-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_message.rb
37 lines (33 loc) · 926 Bytes
/
process_message.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Telekrug
module Workers
class ProcessMessage < Base
def perform(message_dump)
message = YAML.load(message_dump)
user =
Telekrug::Models::User.find_or_create(telegram_id: message.from.id)
command_klass(message, user).execute(message, user)
end
private
def command_klass(message, user)
current_command_klass(user) ||
command_klass_by_text(message.text) ||
Telekrug::Commands::Missing
end
def current_command_klass(user)
return unless user.current_command
end
def command_klass_by_text(text)
case text
when '/start'
Telekrug::Commands::Start
when '/stop'
Telekrug::Commands::Stop
when '/cancel'
Telekrug::Commands::Cancel
when %r{^\/subscribe}
Telekrug::Commands::Subscribe
end
end
end
end
end