class BotBrain::Brain
Public Class Methods
new(token, dictionary)
click to toggle source
# File lib/bot_brain.rb, line 12 def initialize(token, dictionary) @token = token @dictionary = dictionary @chats = {} end
Public Instance Methods
answer(raw_message)
click to toggle source
# File lib/bot_brain.rb, line 18 def answer(raw_message) message = BotBrain::Message.new(raw_message) add_to_chat(message) command = @dictionary.get_command(message) text = command.answer(message) api.call('sendMessage', chat_id: message.chat_id, text: text) end
Private Instance Methods
add_to_chat(message)
click to toggle source
# File lib/bot_brain.rb, line 28 def add_to_chat(message) chat = find_or_create_chat(message.chat_id) chat.add(message) end
api()
click to toggle source
# File lib/bot_brain.rb, line 37 def api @api ||= ::Telegram::Bot::Api.new(@token) end
find_or_create_chat(chat_id)
click to toggle source
# File lib/bot_brain.rb, line 33 def find_or_create_chat(chat_id) @chats[chat_id] || @chats[chat_id] = BotBrain::Chat.new(chat_id) end