Class: Bot
- Inherits:
-
Object
- Object
- Bot
- Defined in:
- lib/telegram_imdb_bot/bot.rb
Instance Method Summary collapse
- #get_movie(query) ⇒ Object
-
#initialize(token) ⇒ Bot
constructor
A new instance of Bot.
- #print_movie(movie) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(token) ⇒ Bot
Returns a new instance of Bot.
7 8 9 |
# File 'lib/telegram_imdb_bot/bot.rb', line 7 def initialize(token) @token = token end |
Instance Method Details
#get_movie(query) ⇒ Object
11 12 13 |
# File 'lib/telegram_imdb_bot/bot.rb', line 11 def get_movie(query) Imdb::Search.new(query).movies.first end |
#print_movie(movie) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/telegram_imdb_bot/bot.rb', line 15 def print_movie(movie) s = [] s << "Title: #{movie.title}" s << "Director: #{movie.director.first}" s << "Cast: #{movie.cast_members[0..2].join(', ')}" s << "Rating: #{movie.}" s << '' s << movie.plot s << movie.url s.join("\n") end |
#start ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/telegram_imdb_bot/bot.rb', line 27 def start Telegram::Bot::Client.run(@token) do |bot| bot.listen do || case .text when /^\/imdb\s+(.*)$/ bot.api.sendChatAction(chat_id: .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: .chat.id, photo: File.new(filename)) if File.exist?(filename) end bot.api.sendMessage(chat_id: .chat.id, text: print_movie(movie), disable_web_page_preview: true) end end end end end |