telegram_meetup_bot 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51b03a0ff454da1c34c353fc829be95338d0870f
4
- data.tar.gz: e910a57c53883471c023b55bf860d8ee52bbbc3d
3
+ metadata.gz: 2cb81754b8ece1419aa6058ecabd7e8a4462d88a
4
+ data.tar.gz: 24f686b8db1e4768a1361f8ac52551166d44b4fe
5
5
  SHA512:
6
- metadata.gz: 23e565091e85d53839829905fe0f02e73713bf26be623b983b8c9c5beb633245122444ce04dc627e9ec955a441edb36be6b99d804d3f576e1db8ab66ffba351c
7
- data.tar.gz: 5f731f29fa8e8da8fd9c2d35f5e8107eee8f2a6c0e0c0d65de2bb9ec3d45e200bc5616c5c7e7d8c469d27d8494d57683495bfc7f115aed39eafc739455e8032a
6
+ metadata.gz: e93de5d8f13463d74a26c3084af467c9973e168a4616a60e1e9ed49f921efb0e875fe216f0b279192ab9f44a0eb042f1d8497998313f8a821ddcbbd6ed9eb94c
7
+ data.tar.gz: 2d06f6fe0d08cd2ea9b87f7009636ea71bac05d0e83452706507b699c9dd70a14f524df6132c02ee824a612a91e81daa1ccec0099cc6e5bb1b2a4759cf74503b
data/README.md CHANGED
@@ -35,7 +35,11 @@ bot_name: 'meetup_dev_bot'
35
35
  redis_host: 'localhost'
36
36
  redis_port: '6379'
37
37
  redis_key: 'meetup_bot'
38
+ botan_key: ''
38
39
  ```
40
+
41
+ The gem supports [botan.io](http://botan.io/) – free telegram analytics tool. All you have to do is obtain botan_key and specify it in ```config.yml```.
42
+
39
43
  If you use more than one bot per redis server, use different redis_keys for each of them.
40
44
 
41
45
  Also you could change sample responses in ```~/.telegram_meetup_bot/responses.yml```. It uses templates ```%first_name%``` and ```%date%``` to display actual name and date in messages.
@@ -3,3 +3,4 @@ bot_name: 'meetup_dev_bot'
3
3
  redis_host: 'localhost'
4
4
  redis_port: '6379'
5
5
  redis_key: 'meetup_bot'
6
+ botan_key: ''
@@ -1,4 +1,5 @@
1
1
  require 'telegram/bot'
2
+ require 'telegram/bot/botan'
2
3
  require 'redis'
3
4
 
4
5
  require 'telegram_meetup_bot/version'
@@ -11,6 +12,7 @@ require 'telegram_meetup_bot/calendar'
11
12
  require 'telegram_meetup_bot/commands_handler'
12
13
  require 'telegram_meetup_bot/params_parser'
13
14
  require 'telegram_meetup_bot/handler_helper'
15
+ require 'telegram_meetup_bot/botan'
14
16
 
15
17
  module TelegramMeetupBot
16
18
  def self.run(config_path)
@@ -0,0 +1,14 @@
1
+ module TelegramMeetupBot
2
+ class Botan
3
+ attr_reader :bot, :author_id
4
+
5
+ def initialize(args)
6
+ @bot = args.fetch(:bot)
7
+ @author_id = args.fetch(:author_id)
8
+ end
9
+
10
+ def track(command)
11
+ bot.track(command, author_id)
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,7 @@
1
1
  module TelegramMeetupBot
2
2
  class Client
3
+ TIMEOUT = 1
4
+
3
5
  attr_reader :token
4
6
 
5
7
  def initialize(token)
@@ -7,20 +9,37 @@ module TelegramMeetupBot
7
9
  end
8
10
 
9
11
  def run
10
- begin
11
- Telegram::Bot::Client.run(token) do |bot|
12
- bot.listen do |message|
13
- if message.text
14
- messenger = Messenger.new(api: bot.api, chat_id: message.chat.id)
15
- CommandsHandler.new(message: message, messenger: messenger).process
16
- end
17
- end
12
+ Telegram::Bot::Client.run(token) do |bot|
13
+ bot.enable_botan!(botan_key) if botan_key
14
+ bot.listen do |message|
15
+ process_message(bot, message) if message.text
18
16
  end
19
- rescue Telegram::Bot::Exceptions::ResponseError => e
20
- puts e
21
- sleep 1
22
- retry # run again on telegram server error
23
17
  end
18
+ rescue Telegram::Bot::Exceptions::ResponseError => e
19
+ write_log_and_sleep(e)
20
+ retry # run again on telegram server error
21
+ end
22
+
23
+ private
24
+
25
+ def process_message(bot, message)
26
+ messenger = Messenger.new(api: bot.api, chat_id: message.chat.id)
27
+ botan = Botan.new(bot: bot, author_id: message.from.id) if botan_key
28
+
29
+ CommandsHandler.new(
30
+ message: message,
31
+ messenger: messenger,
32
+ botan: botan
33
+ ).process
34
+ end
35
+
36
+ def botan_key
37
+ Initializers::ConfigLoader.botan_key
38
+ end
39
+
40
+ def write_log_and_sleep(error)
41
+ puts "#{Time.now}: #{error}"
42
+ sleep TIMEOUT
24
43
  end
25
44
  end
26
45
  end
@@ -2,7 +2,7 @@ module TelegramMeetupBot
2
2
  class CommandsHandler
3
3
  COMMANDS = %w(date list cancel help cal)
4
4
  BLACK_LIST = %w(me)
5
- attr_reader :command, :params, :helper
5
+ attr_reader :command, :params, :helper, :botan
6
6
 
7
7
  def initialize(args)
8
8
  parser = MessageParser.new(args.fetch(:message))
@@ -13,12 +13,14 @@ module TelegramMeetupBot
13
13
  command: @command,
14
14
  messenger: args.fetch(:messenger)
15
15
  )
16
+ @botan = args[:botan]
16
17
  end
17
18
 
18
19
  def process
19
20
  return if BLACK_LIST.include?(command)
20
21
 
21
22
  call_command(command)
23
+ botan.track(command) if botan
22
24
  helper.send_empty_username_notification unless helper.author_has_username?
23
25
  end
24
26
 
@@ -1,8 +1,10 @@
1
1
  module TelegramMeetupBot
2
2
  module Initializers
3
3
  class ConfigLoader < Base
4
+ EMPTY = ''
4
5
  FILE_NAME = 'config.yml'
5
- AVAILABLE_KEYS = %w(bot_token bot_name redis_key redis_port redis_host)
6
+ AVAILABLE_KEYS = %w(bot_token bot_name redis_key
7
+ redis_port redis_host botan_key)
6
8
 
7
9
  class << self
8
10
  def storage
@@ -17,6 +19,14 @@ module TelegramMeetupBot
17
19
  @configurations['bot_name']
18
20
  end
19
21
 
22
+ def botan_key
23
+ @key ||= if @configurations['botan_key'] == EMPTY
24
+ nil
25
+ else
26
+ @configurations['botan_key']
27
+ end
28
+ end
29
+
20
30
  private
21
31
 
22
32
  def redis_key
@@ -1,3 +1,3 @@
1
1
  module TelegramMeetupBot
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "timecop"
25
25
 
26
26
  spec.add_dependency 'redis'
27
- spec.add_dependency 'telegram-bot-ruby', ">= 0.3.5"
27
+ spec.add_dependency 'telegram-bot-ruby', ">= 0.3.11"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram_meetup_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timur Yanberdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.3.5
103
+ version: 0.3.11
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.3.5
110
+ version: 0.3.11
111
111
  description:
112
112
  email:
113
113
  - yanberdint@gmail.com
@@ -126,6 +126,7 @@ files:
126
126
  - config_samples/config.yml
127
127
  - config_samples/responses.yml
128
128
  - lib/telegram_meetup_bot.rb
129
+ - lib/telegram_meetup_bot/botan.rb
129
130
  - lib/telegram_meetup_bot/calendar.rb
130
131
  - lib/telegram_meetup_bot/client.rb
131
132
  - lib/telegram_meetup_bot/commands_handler.rb