class Tegawa::Bot

Public Class Methods

new(token, channel_id) click to toggle source
# File lib/tegawa/bot.rb, line 7
def initialize(token, channel_id)
  @token = token
  @channel_id = channel_id
  @queue = Tegawa.queue
  @logger = Tegawa.logger

  @bot = Telegram::Bot::Client.new(@token)
  @logger.info "Ready to forward messages to channel: #{@channel_id}"
end

Public Instance Methods

run() click to toggle source
# File lib/tegawa/bot.rb, line 17
def run
  # FIXME: needs a thread pool to stop flooding
  while (message = @queue.pop)
    @logger.info "Forwarding message to telegram"
    @bot.api.send_message(chat_id: @channel_id, text: message)
  end
end