2016-04-10 21:04:47 -07:00
|
|
|
local imdb = {}
|
|
|
|
|
|
|
|
local HTTP = require('socket.http')
|
|
|
|
local URL = require('socket.url')
|
2016-04-15 19:07:23 +00:00
|
|
|
local JSON = require('dkjson')
|
2016-06-07 00:31:34 -04:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-06-11 14:46:41 +02:00
|
|
|
local bindings = require('otouto.bindings')
|
2016-04-10 21:04:47 -07:00
|
|
|
|
|
|
|
imdb.command = 'imdb <query>'
|
2016-05-26 20:28:44 -07: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-10 21:04:47 -07:00
|
|
|
end
|
2015-07-02 18:15:52 -04:00
|
|
|
|
2016-05-26 17:26:30 -07:00
|
|
|
function imdb:action(msg, config)
|
2015-07-02 18:15:52 -04:00
|
|
|
|
2016-04-08 14:12:02 -07:00
|
|
|
local input = utilities.input(msg.text)
|
2015-07-02 18:15:52 -04:00
|
|
|
if not input then
|
2015-11-24 21:22:04 -05:00
|
|
|
if msg.reply_to_message and msg.reply_to_message.text then
|
|
|
|
input = msg.reply_to_message.text
|
2015-07-15 02:15:23 -04:00
|
|
|
else
|
2016-05-29 13:08:39 -04:00
|
|
|
utilities.send_message(self, msg.chat.id, imdb.doc, true, msg.message_id, true)
|
2015-11-24 21:22:04 -05:00
|
|
|
return
|
2015-07-15 02:15:23 -04:00
|
|
|
end
|
2015-07-02 18:15:52 -04:00
|
|
|
end
|
|
|
|
|
2015-09-21 19:34:02 -04:00
|
|
|
local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input)
|
2015-07-02 18:15:52 -04:00
|
|
|
|
2015-11-24 21:22:04 -05:00
|
|
|
local jstr, res = HTTP.request(url)
|
|
|
|
if res ~= 200 then
|
2016-05-26 17:26:30 -07:00
|
|
|
utilities.send_reply(self, msg, config.errors.connection)
|
2015-11-24 21:22:04 -05:00
|
|
|
return
|
2015-07-02 18:15:52 -04:00
|
|
|
end
|
|
|
|
|
2015-11-24 21:22:04 -05:00
|
|
|
local jdat = JSON.decode(jstr)
|
|
|
|
|
2015-07-02 18:15:52 -04:00
|
|
|
if jdat.Response ~= 'True' then
|
2016-05-26 17:26:30 -07:00
|
|
|
utilities.send_reply(self, msg, config.errors.results)
|
2015-11-24 21:22:04 -05:00
|
|
|
return
|
2015-07-02 18:15:52 -04: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 14:27:22 -04: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-02 18:15:52 -04:00
|
|
|
|
2016-05-29 13:08:39 -04: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)
|
2016-06-12 20:53:20 +02:00
|
|
|
utilities.send_photo(self, msg.chat.id, file)
|
2016-06-11 14:46:41 +02:00
|
|
|
end
|
2015-07-02 18:15:52 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-10 21:04:47 -07:00
|
|
|
return imdb
|