2016-11-29 18:28:21 +01:00
|
|
|
|
local mal = {}
|
|
|
|
|
|
|
|
|
|
local xml = require("xml")
|
|
|
|
|
|
|
|
|
|
mal.command = 'anime <Anime>, /manga <Manga>'
|
|
|
|
|
|
|
|
|
|
function mal:init(config)
|
|
|
|
|
if not cred_data.mal_username then
|
|
|
|
|
print('Fehlender Key: mal_username.')
|
|
|
|
|
print('myanimelist.lua wird nicht aktiviert.')
|
|
|
|
|
return
|
|
|
|
|
elseif not cred_data.mal_pw then
|
|
|
|
|
print('Fehlender Key: mal_pw.')
|
|
|
|
|
print('myanimelist.lua wird nicht aktiviert.')
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
mal.triggers = {
|
|
|
|
|
"^/(anime) (.+)$",
|
|
|
|
|
"^/(mal) (.+)$",
|
|
|
|
|
"^/(manga) (.+)$"
|
|
|
|
|
}
|
|
|
|
|
mal.doc = [[*
|
|
|
|
|
]]..config.cmd_pat..[[anime*_ <Anime>_: Sendet Infos zum Anime
|
|
|
|
|
*]]..config.cmd_pat..[[manga*_ <Manga>_: Sendet Infos zum Manga
|
|
|
|
|
]]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local user = cred_data.mal_username
|
|
|
|
|
local password = cred_data.mal_pw
|
|
|
|
|
|
|
|
|
|
local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api'
|
|
|
|
|
|
|
|
|
|
function mal:delete_tags(str)
|
|
|
|
|
str = string.gsub( str, '<br />', '')
|
|
|
|
|
str = string.gsub( str, '%[i%]', '')
|
|
|
|
|
str = string.gsub( str, '%[/i%]', '')
|
|
|
|
|
str = string.gsub( str, '—', ' — ')
|
|
|
|
|
return str
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local makeOurDate = function(dateString)
|
|
|
|
|
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
|
|
|
|
local year, month, day = dateString:match(pattern)
|
|
|
|
|
if month == "00" then
|
|
|
|
|
return year
|
|
|
|
|
elseif day == "00" then
|
|
|
|
|
return month..'.'..year
|
|
|
|
|
else
|
|
|
|
|
return day..'.'..month..'.'..year
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mal:get_mal_info(query, typ)
|
|
|
|
|
if typ == 'anime' then
|
|
|
|
|
url = BASE_URL..'/anime/search.xml?q='..query
|
|
|
|
|
elseif typ == 'manga' then
|
|
|
|
|
url = BASE_URL..'/manga/search.xml?q='..query
|
|
|
|
|
end
|
|
|
|
|
local res,code = https.request(url)
|
|
|
|
|
if code ~= 200 then return "HTTP-Fehler" end
|
|
|
|
|
local result = xml.load(res)
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mal:send_anime_data(result, receiver)
|
2017-10-31 22:55:52 +01:00
|
|
|
|
local title = '<b>'..xml.find(result, 'title')[1]..'</b>'
|
2016-11-29 18:28:21 +01:00
|
|
|
|
local id = xml.find(result, 'id')[1]
|
|
|
|
|
local mal_url = 'https://myanimelist.net/anime/'..id
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'type')[1] then
|
|
|
|
|
typ = ' ('..xml.find(result, 'type')[1]..')'
|
|
|
|
|
else
|
|
|
|
|
typ = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'english')[1] then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
eng = '\n<b>Englisch:</b> '..xml.find(result, 'english')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
eng = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'synonyms')[1] then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
syno = '\n<b>Alternativ:</b> '..xml.find(result, 'synonyms')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
syno = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'episodes')[1] then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
episodes = '\n<b>Episoden:</b> '..xml.find(result, 'episodes')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
episodes = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|
2017-10-31 22:55:52 +01:00
|
|
|
|
score = '\n<b>Score:</b> '..string.gsub(xml.find(result, 'score')[1], "%.", ",")
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
score = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
startdate = '\n<b>Ausstrahlung:</b> '..makeOurDate(xml.find(result, 'start_date')[1])
|
2016-11-29 18:28:21 +01:00
|
|
|
|
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
|
2017-10-31 22:55:52 +01:00
|
|
|
|
desc = '\n<i>'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'...</i>'
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
desc = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'image') then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
image_url = xml.find(result, 'image')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
2017-10-31 22:55:52 +01:00
|
|
|
|
image_url = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local text = title..typ..eng..syno..episodes..status..score..startdate..enddate..'\n'..desc..'<a href="'..image_url..'"> </a>\n<a href="'..mal_url..'">Auf MyAnimeList ansehen</a>'
|
|
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
|
2016-11-29 18:28:21 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mal:send_manga_data(result)
|
|
|
|
|
local title = xml.find(result, 'title')[1]
|
|
|
|
|
local id = xml.find(result, 'id')[1]
|
|
|
|
|
local mal_url = 'https://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
|
|
|
|
|
alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1]))
|
|
|
|
|
else
|
|
|
|
|
alt_name = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'chapters')[1] then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
chapters = '\n<b>Kapitel:</b> '..xml.find(result, 'chapters')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
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
|
2017-10-31 22:55:52 +01:00
|
|
|
|
volumes = '\n<b>Bände:</b> '..xml.find(result, 'volumes')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
volumes = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'score')[1] ~= "0.00" then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
score = '\n<b>Score:</b> '..xml.find(result, 'score')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
score = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
startdate = '\n<b>Veröffentlichungszeitraum:</b> '..makeOurDate(xml.find(result, 'start_date')[1])
|
2016-11-29 18:28:21 +01:00
|
|
|
|
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
|
2017-10-31 22:55:52 +01:00
|
|
|
|
desc = '\n<i>'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200)))..'...</i>'
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
|
|
|
|
desc = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if xml.find(result, 'image') then
|
2017-10-31 22:55:52 +01:00
|
|
|
|
image_url = xml.find(result, 'image')[1]
|
2016-11-29 18:28:21 +01:00
|
|
|
|
else
|
2017-10-31 22:55:52 +01:00
|
|
|
|
image_url = ''
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local text = title..alt_name..typ..chapters..status..volumes..score..startdate..enddate..desc..'<a href="'..image_url..'"> </a>\n<a href="'..mal_url..'">Auf MyAnimeList ansehen</a>'
|
|
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
|
2016-11-29 18:28:21 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function mal:action(msg, config, matches)
|
|
|
|
|
local query = URL.escape(matches[2])
|
|
|
|
|
if matches[1] == 'anime' or matches[1] == 'mal' then
|
|
|
|
|
local anime_info = mal:get_mal_info(query, 'anime')
|
|
|
|
|
if anime_info == "HTTP-Fehler" then
|
|
|
|
|
utilities.send_reply(msg, 'Anime nicht gefunden!')
|
|
|
|
|
return
|
|
|
|
|
else
|
2017-10-31 22:55:52 +01:00
|
|
|
|
local text = mal:send_anime_data(anime_info)
|
|
|
|
|
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
2016-11-29 18:28:21 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
elseif matches[1] == 'manga' then
|
|
|
|
|
local manga_info = mal:get_mal_info(query, 'manga')
|
|
|
|
|
if manga_info == "HTTP-Fehler" then
|
|
|
|
|
utilities.send_reply(msg, 'Manga nicht gefunden!')
|
|
|
|
|
return
|
|
|
|
|
else
|
2017-10-31 22:55:52 +01:00
|
|
|
|
local text = mal:send_manga_data(manga_info)
|
|
|
|
|
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
|
2016-11-29 18:28:21 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return mal
|