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
36 37 38 |
# File 'lib/bot/handler.rb', line 36 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 30 |
# File 'lib/bot/handler.rb', line 17 def execute_chain(, responses, user) analytics = Bot::Analytics.new(user.username, Bot.configuration.mixpanel) user_context = Bot::Context.new(user.id, Bot.configuration.redis) chat_context = Bot::Context.new(["chatId"].to_i, Bot.configuration.redis) responder_chain.responders.each do |responder| responder = responder.new(, user, responses, self, analytics, user_context, chat_context) 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
32 33 34 |
# File 'lib/bot/handler.rb', line 32 def responder_chain @@responder_chain ||= Bot::ResponderChain.new end |