lib/te_bot/court.rb in te_bot-0.1.0 vs lib/te_bot/court.rb in te_bot-0.2.0

- old
+ new

@@ -18,18 +18,10 @@ def default_action(&block) @default_action ||= block end - def reply(conn, message) - send_message(conn.data&.chat_id, message) - end - - def send_message(chat_id, message) - wire.send_message(chat_id, message) - end - def command(text, &block) @commands ||= {} @commands[text] = block end @@ -72,33 +64,34 @@ end def handle_request(body) message = ::TeBot::Message.new(body) + command, params = message.data&.content&.parse + conn = ::TeBot::Cable.new(self.class.wire, message, params || {}) + message.command do - command, params = message.data.content.parse handler = self.class.commands[command] - if handler.respond_to?(:call) - handler.call(message, params) + handler.call(conn) elsif self.class.default_command.respond_to?(:call) - self.class.default_command.call(message, params) + self.class.default_command.call(conn) end end ::TeBot::Message::GENERAL_MESSAGE_TYPES.each do |f| message.public_send(f) do handler = self.class.public_send(f) next unless handler.respond_to?(:call) - handler.call(message) + handler.call(conn) end end if message.handler.respond_to?(:call) message.call elsif self.class.default_action.respond_to?(:call) - self.class.default_action.call(message) + self.class.default_action.call(conn) end end end end