This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/plugins/imdb.lua
topkecleon 42cda22ab6 much improved personality.lua interactions
partial localization support
2015-07-11 04:31:29 -04:00

41 lines
943 B
Lua

local PLUGIN = {}
PLUGIN.doc = [[
/imdb <movie | TV series>
This function retrieves the IMDb info for a given film or television series, including the year, genre, imdb rating, runtime, and a summation of the plot.
]]
PLUGIN.triggers = {
'^/imdb'
}
function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
end
local url = 'http://www.imdbapi.com/?t=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
local jdat = JSON.decode(jstr)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
end
if jdat.Response ~= 'True' then
return send_msg(msg, jdat.Error)
end
local message = jdat.Title ..' ('.. jdat.Year ..')\n'
message = message .. jdat.imdbRating ..' | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
message = message .. jdat.Plot .. '\n'
message = message .. 'http://imdb.com/title/' .. jdat.imdbID
send_msg(msg, message)
end
return PLUGIN