From 811834a5449a9f6576a72d1d2cad6b6d518f19b7 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Wed, 29 Apr 2015 21:57:38 +0200 Subject: [PATCH] added myanimelist plugin --- plugins/myanimelist.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/myanimelist.lua diff --git a/plugins/myanimelist.lua b/plugins/myanimelist.lua new file mode 100644 index 0000000..d86c53b --- /dev/null +++ b/plugins/myanimelist.lua @@ -0,0 +1,38 @@ +function getAnime(query) + local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=active&hl=de&q=myanimelist" + local parameters = "+".. (URL.escape(query) or "") + + -- Do the request + local res, code = https.request(api..parameters) + if code ~=200 then return nil end + local data = json:decode(res) + + local results={} + for key,result in ipairs(data.responseData.results) do + table.insert(results, { + result.titleNoFormatting, + result.unescapedUrl or result.url + }) + end + return results +end + +function stringlinks(results) + local stringresults="" + for key,val in ipairs(results) do + stringresults=stringresults..val[1].." - "..val[2].."\n" + end + return stringresults +end + +function run(msg, matches) + local results = getAnime(matches[1]) + return stringlinks(results) +end + +return { + description = "", + usage = {"/myanimelist [Anime]","/mal [Anime]"}, + patterns = {"^/myanimelist (.*)$","^/mal (.*)$"}, + run = run + } \ No newline at end of file