class StallmanBot::Bot
Public Class Methods
new(config)
click to toggle source
# File lib/stallman_bot/bot.rb, line 8 def initialize(config) @config = config @token = @config[:token] @debug = @config[:debug] Locale.load_i18n(@config[:locale]) @listener = Listener.new end
Public Instance Methods
run()
click to toggle source
# File lib/stallman_bot/bot.rb, line 16 def run puts "Stallman_bot running... (DEBUG: #{@debug})" if @debug local_handler elsif @token.empty? puts "Invalid/empty token: #{@token}" exit else bot_handler end end
Private Instance Methods
bot_handler()
click to toggle source
# File lib/stallman_bot/bot.rb, line 28 def bot_handler Telegram::Bot::Client.run(@token) do |bot| bot.listen do |message| begin @listener.respond(message.text, bot, message.chat.id) rescue Telegram::Bot::Exceptions::ResponseError => e puts e end end end end
local_handler()
click to toggle source
# File lib/stallman_bot/bot.rb, line 40 def local_handler loop do begin message = gets.chomp rescue Interrupt exit end @listener.respond(message) end end