telegram_meetup_bot 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0b6bb180e431520c43ac177e3afbc0b705f16cf
4
- data.tar.gz: eab2300653e6d119aeecb18573e86955153a80b0
3
+ metadata.gz: e496544d412e4ded058528c0ce1c62bb97976f29
4
+ data.tar.gz: 09d7b861bf4b309629e8ae37784883659366f2bb
5
5
  SHA512:
6
- metadata.gz: 453de1b09b75f1350be93ea83b4ffcbc5e0908d372826a489c9268f7e97ae673e7b91830f40f80f17a89067a4126b9a157f3d18f77f7c5c6bf438320688389fc
7
- data.tar.gz: 700aa76255a6106c6473014bdbf7b7dfdbe35c310bfa4758bcf55b7f4a5846bd6a7d7415d3c9bbb86114346c1de4965ea29482d83d62338af54ce216cc40b5fd
6
+ metadata.gz: c6d95c65a742dd485d7e5ab208cad2dd02df26722d001a0f933b06271d948fbc76734b3ad19fdbe8895a31261a8606ca98d68293d39b07895e8bc70c33b2b40d
7
+ data.tar.gz: fcfd3a73e91218d3fb5a74ed5330f623cb667c99ccb5621e02ce4d58d4cae876992bef309ef3b7826109ada4bc4b27d51f3799c253a402771184d93f0d1bc45a
data/README.md CHANGED
@@ -26,9 +26,10 @@ Generate sample configurations:
26
26
 
27
27
  $ telegram_meetup_bot --generate
28
28
 
29
- You should specify your bot_token in ```~/.telegram_meetup_bot/config.yml```.
29
+ You should specify your bot_token and bot_name in ```~/.telegram_meetup_bot/config.yml```.
30
30
  ```
31
31
  bot_token: 'insert your token here'
32
+ bot_name: 'meetup_dev_bot'
32
33
  redis_host: 'localhost'
33
34
  redis_port: '6379'
34
35
  redis_key: 'meetup_bot'
@@ -1,4 +1,5 @@
1
1
  bot_token: 'insert your token here'
2
+ bot_name: 'meetup_dev_bot'
2
3
  redis_host: 'localhost'
3
4
  redis_port: '6379'
4
5
  redis_key: 'meetup_bot'
@@ -10,8 +10,10 @@ module TelegramMeetupBot
10
10
  begin
11
11
  Telegram::Bot::Client.run(token) do |bot|
12
12
  bot.listen do |message|
13
- messenger = Messenger.new(api: bot.api, chat_id: message.chat.id)
14
- CommandsHandler.new(message: message, messenger: messenger).process
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
15
17
  end
16
18
  end
17
19
  rescue Telegram::Bot::Exceptions::ResponseError => e
@@ -4,7 +4,7 @@ module TelegramMeetupBot
4
4
  module Initializers
5
5
  class ConfigLoader < Base
6
6
  FILE_NAME = 'config.yml'
7
- AVAILABLE_KEYS = %w(bot_token redis_key redis_port redis_host)
7
+ AVAILABLE_KEYS = %w(bot_token bot_name redis_key redis_port redis_host)
8
8
 
9
9
  class << self
10
10
  def storage
@@ -15,6 +15,10 @@ module TelegramMeetupBot
15
15
  @configurations['bot_token']
16
16
  end
17
17
 
18
+ def bot_name
19
+ @configurations['bot_name']
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def redis_key
@@ -13,7 +13,10 @@ module TelegramMeetupBot
13
13
  end
14
14
 
15
15
  def command
16
- parse_message { |words| words.first }
16
+ parse_message do |words|
17
+ cmd, bot_name = words.first.split('@')
18
+ cmd if bot_name.nil? || bot_name == Initializers::ConfigLoader.bot_name
19
+ end
17
20
  end
18
21
 
19
22
  def params
@@ -23,7 +26,7 @@ module TelegramMeetupBot
23
26
  private
24
27
 
25
28
  def parse_message(&block)
26
- if message.text[0] == '/' && message.text.length > 1
29
+ if message.text && message.text[0] == '/' && message.text.length > 1
27
30
  yield message.text[1..-1].split(' ')
28
31
  end
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module TelegramMeetupBot
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -28,10 +28,26 @@ RSpec.describe TelegramMeetupBot::MessageParser do
28
28
  end
29
29
 
30
30
  context "when message with params" do
31
- let(:message) { instance_double('message', text: '/date 08.11.1998', from: from) }
31
+ let(:message) { instance_double('message', text: '/date 08.11.07', from: from) }
32
32
 
33
33
  it { expect(subject.command).to eq('date') }
34
- it { expect(subject.params).to eq(['08.11.1998']) }
34
+ it { expect(subject.params).to eq(['08.11.07']) }
35
+ end
36
+
37
+ context "when command contain @ and username equal to bot" do
38
+ before { allow(TelegramMeetupBot::Initializers::ConfigLoader).to receive(:bot_name).and_return('test_bot')}
39
+ let(:message) { instance_double('message', text: '/today_list@test_bot', from: from) }
40
+
41
+ it { expect(subject.command).to eq('today_list') }
42
+ it { expect(subject.params).to eq([]) }
43
+ end
44
+
45
+ context "when command contain @ and username isn't equal to bot" do
46
+ before { allow(TelegramMeetupBot::Initializers::ConfigLoader).to receive(:bot_name).and_return('production_bot')}
47
+ let(:message) { instance_double('message', text: '/today_list@test_bot', from: from) }
48
+
49
+ it { expect(subject.command).to eq(nil) }
50
+ it { expect(subject.params).to eq([]) }
35
51
  end
36
52
  end
37
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telegram_meetup_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timur Yanberdin