2016-04-11 06:04:47 +02:00
|
|
|
local imdb = {}
|
|
|
|
|
|
|
|
local HTTP = require('socket.http')
|
|
|
|
local URL = require('socket.url')
|
2016-04-15 21:07:23 +02:00
|
|
|
local JSON = require('dkjson')
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-06-11 14:46:41 +02:00
|
|
|
local bindings = require('otouto.bindings')
|
2016-04-11 06:04:47 +02:00
|
|
|
|
|
|
|
imdb.command = 'imdb <query>'
|
2016-05-27 05:28:44 +02:00
|
|
|
|
|
|
|
function imdb:init(config)
|
|
|
|
imdb.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imdb', true).table
|
2016-06-11 14:46:41 +02:00
|
|
|
imdb.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[imdb* _<Film>_
|
|
|
|
Sucht _Film_ bei IMDB]]
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
function imdb:action(msg, config)
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local input = utilities.input(msg.text)
|
2015-07-03 00:15:52 +02:00
|
|
|
if not input then
|
2015-11-25 03:22:04 +01:00
|
|
|
if msg.reply_to_message and msg.reply_to_message.text then
|
|
|
|
input = msg.reply_to_message.text
|
2015-07-15 08:15:23 +02:00
|
|
|
else
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, imdb.doc, true, msg.message_id, true)
|
2015-11-25 03:22:04 +01:00
|
|
|
return
|
2015-07-15 08:15:23 +02:00
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2015-09-22 01:34:02 +02:00
|
|
|
local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input)
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local jstr, res = HTTP.request(url)
|
|
|
|
if res ~= 200 then
|
2016-05-27 02:26:30 +02:00
|
|
|
utilities.send_reply(self, msg, config.errors.connection)
|
2015-11-25 03:22:04 +01:00
|
|
|
return
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2015-11-25 03:22:04 +01:00
|
|
|
local jdat = JSON.decode(jstr)
|
|
|
|
|
2015-07-03 00:15:52 +02:00
|
|
|
if jdat.Response ~= 'True' then
|
2016-05-27 02:26:30 +02:00
|
|
|
utilities.send_reply(self, msg, config.errors.results)
|
2015-11-25 03:22:04 +01:00
|
|
|
return
|
2015-07-03 00:15:52 +02:00
|
|
|
end
|
|
|
|
|
2016-06-11 14:46:41 +02:00
|
|
|
local output = '*' .. jdat.Title .. ' ('.. jdat.Year ..')* von '..jdat.Director..'\n'
|
|
|
|
output = output .. string.gsub(jdat.imdbRating, '%.', ',') ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
2016-04-28 20:27:22 +02:00
|
|
|
output = output .. '_' .. jdat.Plot .. '_\n'
|
2016-06-11 14:46:41 +02:00
|
|
|
output = output .. '[IMDB-Seite besuchen](http://imdb.com/title/' .. jdat.imdbID .. ')'
|
2015-07-03 00:15:52 +02:00
|
|
|
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
2016-06-11 14:46:41 +02:00
|
|
|
|
|
|
|
if jdat.Poster ~= "N/A" then
|
|
|
|
local file = download_to_file(jdat.Poster)
|
|
|
|
bindings.sendPhoto(self, {chat_id = msg.chat.id}, {photo = file} )
|
|
|
|
end
|
2015-07-03 00:15:52 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return imdb
|