Class: Bot::Handler
- Inherits:
-
Object
- Object
- Bot::Handler
- Defined in:
- lib/bot/handler.rb
Direct Known Subclasses
Constant Summary collapse
- @@responder_chain =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #execute_chain(message, responses, user) ⇒ Object
- #handle(messages) ⇒ Object
- #responder_chain ⇒ Object
Class Method Details
.handle(messages) ⇒ Object
9 10 11 |
# File 'lib/bot/handler.rb', line 9 def self.handle() new.handle() end |
.responder_chain ⇒ Object
35 36 37 |
# File 'lib/bot/handler.rb', line 35 def self.responder_chain @@responder_chain ||= Bot::ResponderChain.new end |
.use(responder) ⇒ Object
5 6 7 |
# File 'lib/bot/handler.rb', line 5 def self.use(responder) responder_chain.add(responder) end |
Instance Method Details
#execute_chain(message, responses, user) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bot/handler.rb', line 17 def execute_chain(, responses, user) context = Bot::Context.new(user, Bot.configuration.redis) analytics = Bot::Analytics.new(user.username, Bot.configuration.mixpanel) responder_chain.responders.each do |responder| responder = responder.new(, user, responses, self, context, analytics) if responder.can_respond_to_type?(['type']) && responder.can_handle? responses << responder.handle break end end responses end |
#handle(messages) ⇒ Object
13 14 15 |
# File 'lib/bot/handler.rb', line 13 def handle() .flat_map { |m| (m) } end |
#responder_chain ⇒ Object
31 32 33 |
# File 'lib/bot/handler.rb', line 31 def responder_chain @@responder_chain ||= Bot::ResponderChain.new end |