Add a way to register routes that should be run by the bot on update.

This commit is contained in:
Danila Fedorin 2018-01-12 20:28:05 -08:00
parent de9a189d57
commit cb1c4f2e54

View File

@ -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