Class: Rubotnik::MessageDispatch
- Inherits:
-
Object
- Object
- Rubotnik::MessageDispatch
- Defined in:
- lib/rubotnik/message_dispatch.rb
Overview
Routing for messages
Constant Summary
Constants included from Helpers
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(message) ⇒ MessageDispatch
constructor
A new instance of MessageDispatch.
- #route(&block) ⇒ Object
Methods included from Helpers
call_graph_api, get_user_info, message_contains_location?, next_command, say, send_message, show, stop_thread, text_message?
Constructor Details
#initialize(message) ⇒ MessageDispatch
Returns a new instance of MessageDispatch.
12 13 14 15 16 17 |
# File 'lib/rubotnik/message_dispatch.rb', line 12 def initialize() @message = p @message.class p @message @user = Rubotnik::UserStore.instance.find_or_create_user(@message.sender['id']) end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/rubotnik/message_dispatch.rb', line 10 def @message end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/rubotnik/message_dispatch.rb', line 10 def user @user end |
Instance Method Details
#route(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubotnik/message_dispatch.rb', line 19 def route(&block) if @user.current_command command = @user.current_command execute(command) Rubotnik.logger.info "Command #{command} is executed for user #{@user.id}" else bind_commands(&block) end rescue StandardError => error raise unless ENV["DEBUG"] == "true" stop_thread say "There was an error: #{error}" end |