Class: QbertBot::Robot

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/qbert_bot/robot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRobot

Returns a new instance of Robot.



26
27
28
29
# File 'lib/qbert_bot/robot.rb', line 26

def initialize
  @plugins = []
  @listeners = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def config
  @config
end

#listenersObject (readonly)

Returns the value of attribute listeners.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def listeners
  @listeners
end

#pluginsObject (readonly)

Returns the value of attribute plugins.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def plugins
  @plugins
end

#routerObject (readonly)

Returns the value of attribute router.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def router
  @router
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def scheduler
  @scheduler
end

#slackObject (readonly)

Returns the value of attribute slack.



24
25
26
# File 'lib/qbert_bot/robot.rb', line 24

def slack
  @slack
end

Instance Method Details

#handle_slack(params) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/qbert_bot/robot.rb', line 53

def handle_slack(params)
  msg = Message.new(self, params)
  match = find_listener(msg)
  msg.matches = match.matches
  match.proc.call(msg)
  ''
end

#handle_web(method, request, params, response) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/qbert_bot/robot.rb', line 45

def handle_web(method, request, params, response)
  if method == :post && request.path_info == @router.endpoint
    return handle_slack(params)
  end

  @router.exec_route(method, request, params, response)
end

#hear(pattern, &block) ⇒ Object



41
42
43
# File 'lib/qbert_bot/robot.rb', line 41

def hear(pattern, &block)
  @listeners << Listener.new(pattern, block)
end

#load_configObject



31
32
33
# File 'lib/qbert_bot/robot.rb', line 31

def load_config
  @config = YAML.load_file('qbert.yml')
end

#run!Object



35
36
37
38
39
# File 'lib/qbert_bot/robot.rb', line 35

def run!
  prepare_workers
  load_plugins
  start_workers
end

#say(*args) ⇒ Object



61
62
63
# File 'lib/qbert_bot/robot.rb', line 61

def say(*args)
  @slack.say(*args)
end