From d031a1f7babffc409f249bb510f4ef06397de77b Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sun, 15 Nov 2015 20:02:28 +0100 Subject: [PATCH] =?UTF-8?q?Manga=20Plugin=20auf=20Basis=20des=20Anime=20Pl?= =?UTF-8?q?ugins=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/myanimelist_manga.lua | 127 ++++++++++++++++++++++++++++++++++ plugins/url_title.lua | 1 + 2 files changed, 128 insertions(+) create mode 100644 plugins/myanimelist_manga.lua diff --git a/plugins/myanimelist_manga.lua b/plugins/myanimelist_manga.lua new file mode 100644 index 0000000..6a55235 --- /dev/null +++ b/plugins/myanimelist_manga.lua @@ -0,0 +1,127 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION +-- Modified by Akamaru [https://ponywave.de] + +do + +local xml = require("xml") + +local user = cred_data.mal_username +local password = cred_data.mal_pw + +local BASE_URL = 'http://'..user..':'..password..'@myanimelist.net/api/manga' + +local function delete_tags(str) + str = string.gsub( str, '
', '') + str = string.gsub( str, '%[i%]', '') + str = string.gsub( str, '%[/i%]', '') + return str +end + +local makeOurDate = function(dateString) + local pattern = "(%d+)%-(%d+)%-(%d+)" + local year, month, day = dateString:match(pattern) + return day..'.'..month..'.'..year +end + +local function get_manga_info(manga) + local url = BASE_URL..'/search.xml?q='..manga + local res,code = http.request(url) + if code ~= 200 then return "HTTP-Fehler" end + local result = xml.load(res) + return result +end + +local function send_manga_data(result, receiver) + local title = xml.find(result, 'title')[1] + local id = xml.find(result, 'id')[1] + local mal_url = 'http://myanimelist.net/manga/'..id + + if xml.find(result, 'type')[1] then + typ = ' ('..xml.find(result, 'type')[1]..')' + else + typ = '' + end + + if xml.find(result, 'synonyms')[1] then + syno = '\nAlternativ: '..unescape(delete_tags(string.sub(xml.find(result, 'synonyms')[1], 1, 200))) + else + syno = '' + end + + if xml.find(result, 'chapters')[1] then + chapters = '\nChapters: '..xml.find(result, 'chapters')[1] + else + chapters = '' + end + + if xml.find(result, 'status')[1] then + status = ' ('..xml.find(result, 'status')[1]..')' + else + status = '' + end + + if xml.find(result, 'volumes')[1] then + volumes = '\nVolumes: '..xml.find(result, 'volumes')[1] + else + volumes = '' + end + + if xml.find(result, 'score')[1] ~= "0.00" then + score = '\nScore: '..xml.find(result, 'score')[1] + else + score = '' + end + + if xml.find(result, 'start_date')[1] ~= "0000-00-00" then + startdate = '\nVeröffentlichung: '..makeOurDate(xml.find(result, 'start_date')[1]) + else + startdate = '' + end + + if xml.find(result, 'end_date')[1] ~= "0000-00-00" then + enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) + else + enddate = '' + end + + if xml.find(result, 'synopsis')[1] then + desc = '\n'..unescape(delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' + else + desc = '' + end + + local text = title..typ..syno..chapters..status..volumes..score..startdate..enddate..'\n'..desc..'\n'..mal_url + if xml.find(result, 'image') then + local image_url = xml.find(result, 'image')[1] + local cb_extra = { + receiver=receiver, + url=image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) + else + send_msg(receiver, text, ok_cb, false) + end +end + +local function run(msg, matches) + local manga = URL.escape(matches[1]) + local receiver = get_receiver(msg) + local manga_info = get_manga_info(manga) + if manga_info == "HTTP-Fehler" then + return "manga nicht gefunden!" + else + send_manga_data(manga_info, receiver) + end +end + +return { + description = "Sendet Infos zu einem manga.", + usage = "/manga [manga]: Sendet Infos zum manga", + patterns = {"^/[Mm][Aa][Nn][Gg][Aa] (.+)$", + "^https?://myanimelist.net/manga/[0-9]+/(.*)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/url_title.lua b/plugins/url_title.lua index 13613d0..f74cb77 100644 --- a/plugins/url_title.lua +++ b/plugins/url_title.lua @@ -84,6 +84,7 @@ function run(msg, matches) string.match(msg.text, "twitter.com") or string.match(msg.text, "steamcommunity.com/app/") or string.match(msg.text, "myanimelist.net/anime/") or + string.match(msg.text, "myanimelist.net/manga/") or string.match(msg.text, "deviantart.com") or string.match(msg.text, "urbanup.com/") or string.match(msg.text, "urbandictionary.com/define.php")or