Class: Lita::External::Robot
- Inherits:
-
Robot
- Object
- Robot
- Lita::External::Robot
- Defined in:
- lib/lita/external/robot.rb
Defined Under Namespace
Classes: Ballot
Instance Method Summary collapse
- #process_outbound_command(payload) ⇒ Object
- #receive(message) ⇒ Object
- #run ⇒ Object
- #shut_down ⇒ Object
- #watch_outbound_queue ⇒ Object
Instance Method Details
#process_outbound_command(payload) ⇒ Object
55 56 57 58 59 |
# File 'lib/lita/external/robot.rb', line 55 def process_outbound_command(payload) command, args = Marshal.load(payload) Lita.logger.debug("Triggering #{command}") adapter.public_send(command, *args) end |
#receive(message) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lita/external/robot.rb', line 12 def receive() ballot = Ballot.new trigger(:master_receive, ballot: ballot) if ballot.veto Lita.logger.debug("Ignoring vetoed message") else Lita.logger.debug("Put inbound message from #{.user.mention_name} into the queue") Lita.redis.rpush('messages:inbound', External.()) end end |
#run ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/lita/external/robot.rb', line 23 def run @stopping = false trigger(:master_loaded) watch_outbound_queue super end |
#shut_down ⇒ Object
32 33 34 35 |
# File 'lib/lita/external/robot.rb', line 32 def shut_down @stopping = true super end |
#watch_outbound_queue ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lita/external/robot.rb', line 37 def watch_outbound_queue Thread.start do Lita.logger.info("Watching outbound queue") until @stopping begin if command = External.blocking_redis.blpop('messages:outbound', timeout: 1) process_outbound_command(command.last) end rescue => error Lita.logger.error("Outbound message failed: #{error.class}: #{error.}") if Lita.config.robot.error_handler Lita.config.robot.error_handler.call(error) end end end end end |