Class: QbertBot::Robot
- Inherits:
-
Object
- Object
- QbertBot::Robot
- Includes:
- Singleton
- Defined in:
- lib/qbert_bot/robot.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
-
#scheduler ⇒ Object
readonly
Returns the value of attribute scheduler.
-
#slack ⇒ Object
readonly
Returns the value of attribute slack.
Instance Method Summary collapse
- #handle_slack(params) ⇒ Object
- #handle_web(method, request, params, response) ⇒ Object
- #hear(pattern, &block) ⇒ Object
-
#initialize ⇒ Robot
constructor
A new instance of Robot.
- #load_config ⇒ Object
- #run! ⇒ Object
- #say(*args) ⇒ Object
Constructor Details
#initialize ⇒ Robot
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
24 25 26 |
# File 'lib/qbert_bot/robot.rb', line 24 def config @config end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
24 25 26 |
# File 'lib/qbert_bot/robot.rb', line 24 def listeners @listeners end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
24 25 26 |
# File 'lib/qbert_bot/robot.rb', line 24 def plugins @plugins end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
24 25 26 |
# File 'lib/qbert_bot/robot.rb', line 24 def router @router end |
#scheduler ⇒ Object (readonly)
Returns the value of attribute scheduler.
24 25 26 |
# File 'lib/qbert_bot/robot.rb', line 24 def scheduler @scheduler end |
#slack ⇒ Object (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_config ⇒ Object
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 |