From cb1c4f2e5498b4b8fbd4f4a188b15bc4a0ab77e1 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 12 Jan 2018 20:28:05 -0800 Subject: [PATCH] Add a way to register routes that should be run by the bot on update. --- src/telepathy/bot.cr | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/telepathy/bot.cr b/src/telepathy/bot.cr index cf1fa67..f066be0 100644 --- a/src/telepathy/bot.cr +++ b/src/telepathy/bot.cr @@ -8,6 +8,8 @@ module Telepathy @this_user = get_me @last_update_id = uninitialized Int64? @last_update_id = nil + @command_hooks = {} of String => Update, Array(String) -> String + @message_hooks = [] of Update -> String end def get_me @@ -26,5 +28,13 @@ module Telepathy updates.last?.try { |update| @last_update_id = update.update_id + 1 } return updates end + + def command(command_name, &block: Update, Array(String) -> String) + @command_hooks[command_name] = block + end + + def message(&block: Update -> String) + @message_hooks.push(block) + end end end