2015-11-12 17:42:03 +01:00
|
|
|
-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
|
|
|
|
-- DO NOT USE WITHOUT PERMISSION
|
|
|
|
|
|
|
|
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/anime'
|
|
|
|
|
|
|
|
local function delete_tags(str)
|
|
|
|
str = string.gsub( str, '<br />', '')
|
|
|
|
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_anime_info(anime)
|
|
|
|
local url = BASE_URL..'/search.xml?q='..anime
|
|
|
|
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_anime_data(result, receiver)
|
|
|
|
local title = xml.find(result, 'title')[1]
|
|
|
|
local id = xml.find(result, 'id')[1]
|
|
|
|
local mal_url = 'http://myanimelist.net/anime/'..id
|
2015-04-29 21:57:38 +02:00
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
if xml.find(result, 'synopsis')[1] then
|
|
|
|
desc = '\n'..delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200)) .. '...'
|
|
|
|
else
|
|
|
|
desc = ''
|
2015-04-29 21:57:38 +02:00
|
|
|
end
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
if xml.find(result, 'episodes')[1] then
|
|
|
|
episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1]
|
|
|
|
else
|
|
|
|
episodes = ''
|
2015-04-29 21:57:38 +02:00
|
|
|
end
|
2015-11-12 17:42:03 +01:00
|
|
|
|
|
|
|
if xml.find(result, 'status')[1] then
|
|
|
|
status = ' ('..xml.find(result, 'status')[1]..')'
|
|
|
|
else
|
|
|
|
status = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[if xml.find(result, 'score')[1] ~= "0.00" then
|
|
|
|
score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", "%,")
|
|
|
|
else
|
|
|
|
score = ''
|
|
|
|
end]]
|
|
|
|
|
|
|
|
if xml.find(result, 'type')[1] then
|
|
|
|
typ = '\nTyp: '..xml.find(result, 'type')[1]
|
|
|
|
else
|
|
|
|
typ = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
|
|
|
|
startdate = '\nStart: '..makeOurDate(xml.find(result, 'start_date')[1])
|
|
|
|
else
|
|
|
|
startdate = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
if xml.find(result, 'end_date')[1] ~= "0000-00-00" then
|
|
|
|
enddate = '\nEnde: '..makeOurDate(xml.find(result, 'end_date')[1])
|
|
|
|
else
|
|
|
|
enddate = ''
|
|
|
|
end
|
|
|
|
|
|
|
|
--local text = title..desc..episodes..status..score..typ..startdate..enddate..'\n— '..mal_url
|
|
|
|
local text = title..desc..episodes..status..typ..startdate..enddate..'\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
|
2015-04-29 21:57:38 +02:00
|
|
|
end
|
|
|
|
|
2015-11-12 17:42:03 +01:00
|
|
|
local function run(msg, matches)
|
|
|
|
local anime = URL.escape(matches[1])
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
local anime_info = get_anime_info(anime)
|
|
|
|
if anime_info == "HTTP-Fehler" then
|
|
|
|
return "Anime nicht gefunden!"
|
|
|
|
else
|
|
|
|
send_anime_data(anime_info, receiver)
|
|
|
|
end
|
2015-04-29 21:57:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2015-11-12 17:42:03 +01:00
|
|
|
description = "Sendet Infos zu einem Anime.",
|
|
|
|
usage = "/anime [Anime]: Sendet Infos zum Anime",
|
|
|
|
patterns = {"^/anime (.+)$",
|
|
|
|
"^/mal (.*)$",
|
|
|
|
"^/myanimelist (.*)$)",
|
|
|
|
"^https?://myanimelist.net/anime/[0-9]+/(.*)$"
|
|
|
|
},
|
|
|
|
run = run
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|