From c2a5380507533f8eef419a2ebf5d710be76ef935 Mon Sep 17 00:00:00 2001 From: Claudio Filho Date: Fri, 13 Feb 2015 13:45:27 -0200 Subject: [PATCH] Add imdb plugin --- plugins/imdb.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugins/imdb.lua diff --git a/plugins/imdb.lua b/plugins/imdb.lua new file mode 100644 index 0000000..5f6c92b --- /dev/null +++ b/plugins/imdb.lua @@ -0,0 +1,33 @@ + +function imdb(movie) + local http = require("socket.http") + http.TIMEOUT = 5 + + movie = movie:gsub(' ', '+') + url = "http://www.imdbapi.com/?t=" .. movie + response, code, headers = http.request(url) + + if code ~= 200 then + return "Error: " .. code + end + + if #response > 0 then + r = json:decode(response) + r['Url'] = "http://imdb.com/title/" .. r.imdbID + t = "" + for k, v in pairs(r) do t = t .. k .. ": " .. v .. ", " end + return t:sub(1, -3) + end + return nil +end + +function run(msg, matches) + return imdb(matches[1]) +end + +return { + description = "Imdb plugin for telegram", + usage = "!imdb [movie]", + patterns = {"^!imdb (.+)"}, + run = run +}