lib/sinbotra/bot.rb in sinbotra-0.1.6 vs lib/sinbotra/bot.rb in sinbotra-0.2.0
- old
+ new
@@ -1,9 +1,10 @@
-require "sinbotra/bot/conversation"
-require "sinbotra/bot/conversation_repo"
+require "sinbotra/bot/redis_store"
require "sinbotra/bot/user"
+require "sinbotra/bot/user_store"
require "sinbotra/bot/user_repo"
+require "sinbotra/bot/conversation"
require "sucker_punch"
module Sinbotra
class Bot
@@ -23,23 +24,24 @@
end
def receive(provider, msg)
handler = @handlers[provider.to_sym]
Sinbotra::Config.logger.debug("MESSAGE DEBUG:\n" + msg.inspect) if ENV["DEBUG"]
- handler.handle_message(msg)
+ user = Sinbotra::User.from_message(msg)
+ bot = handler.new(user)
+ bot.handle_message(msg)
end
def handle_action(action_name, provider, handler, opts={})
handler.handle_action(action_name, opts)
end
end
include SuckerPunch::Job
- def perform(provider, msg)
- # THis needs to be done elsewhere
- msg["entry"].first["messaging"].each do |m|
- Sinbotra::Bot.receive(provider, m)
+ def perform(provider, msgs)
+ msgs.each do |msg|
+ Sinbotra::Bot.receive(provider, msg)
end
end
end
end