Class: Rubotnik::MessageDispatch

Inherits:
Object
  • Object
show all
Includes:
Commands, Helpers
Defined in:
lib/rubotnik/message_dispatch.rb

Overview

Routing for messages

Constant Summary

Constants included from Helpers

Helpers::GRAPH_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  @message = message
  p @message.class
  p @message
  @user = Rubotnik::UserStore.instance.find_or_create_user(@message.sender['id'])
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/rubotnik/message_dispatch.rb', line 10

def message
  @message
end

#userObject (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