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 class << self def handle(provider, entry) Sinbotra::Config.logger.debug("ENTRY DEBUG:\n" + entry.inspect) if ENV["DEBUG"] if ENV["SINBOTRA_SYNCHRONOUS"] new.perform(provider, entry) else perform_async(provider, entry) end end def add_handler(provider, handler) @handlers ||= {} @handlers[provider.to_sym] = handler end def receive(provider, msg) handler = @handlers[provider.to_sym] Sinbotra::Config.logger.debug("MESSAGE DEBUG:\n" + msg.inspect) if ENV["DEBUG"] 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, msgs) msgs.each do |msg| Sinbotra::Bot.receive(provider, msg) end end end end