class Bot

Public Class Methods

new(token) click to toggle source
# File lib/telegram_imdb_bot/bot.rb, line 7
def initialize(token)
  @token = token
end

Public Instance Methods

get_movie(query) click to toggle source
# File lib/telegram_imdb_bot/bot.rb, line 11
def get_movie(query)
  Imdb::Search.new(query).movies.first
end
print_movie(movie) click to toggle source
start() click to toggle source
# File lib/telegram_imdb_bot/bot.rb, line 27
def start
  Telegram::Bot::Client.run(@token) do |bot|
    bot.listen do |message|
      case message.text
      when /^\/imdb\s+(.*)$/
        bot.api.sendChatAction(chat_id: message.chat.id, action: 'typing')
        movie = get_movie($1)
        if movie
          poster = movie.poster
          if poster
            f = open(poster)
            filename = "#{f.path}.jpg"
            `mv '#{f.path}' '#{filename}'`
            bot.api.sendPhoto(chat_id: message.chat.id, photo: File.new(filename)) if File.exist?(filename)
          end
          bot.api.sendMessage(chat_id: message.chat.id, text: print_movie(movie), disable_web_page_preview: true)
        end
      end
    end
  end
end