telegram_meetup_bot 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/config_samples/config.yml +1 -0
- data/lib/telegram_meetup_bot/client.rb +4 -2
- data/lib/telegram_meetup_bot/initializers/config_loader.rb +5 -1
- data/lib/telegram_meetup_bot/message_parser.rb +5 -2
- data/lib/telegram_meetup_bot/version.rb +1 -1
- data/spec/telegram_meetup_bot/message_parser_spec.rb +18 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e496544d412e4ded058528c0ce1c62bb97976f29
|
4
|
+
data.tar.gz: 09d7b861bf4b309629e8ae37784883659366f2bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
data/config_samples/config.yml
CHANGED
@@ -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
|
-
|
14
|
-
|
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
|
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
|
@@ -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.
|
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.
|
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
|
|