2016-08-22 22:57:17 +02:00
|
|
|
local mal_user = {}
|
|
|
|
|
|
|
|
function mal_user:init(config)
|
|
|
|
mal_user.triggers = {
|
|
|
|
"^/malu (.+)$",
|
|
|
|
"myanimelist.net/profile/(.*)$"
|
|
|
|
}
|
|
|
|
mal_user.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[malu* _<User>_: Sendet Infos über einen MyAnimeList-User
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
mal_user.command = 'malu <User>'
|
|
|
|
|
|
|
|
function mal_user:get_infos(user)
|
2016-11-13 22:40:24 +01:00
|
|
|
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fmyanimelist.net%2Fmalappinfo.php%3Fu%3D'..user..'%22&format=json'
|
2016-08-22 22:57:17 +02:00
|
|
|
local res, code = https.request(url)
|
|
|
|
if code ~= 200 then return nil end
|
|
|
|
local data = json.decode(res).query.results.myanimelist.myinfo
|
|
|
|
if not data then return nil end
|
|
|
|
|
2016-11-13 22:40:24 +01:00
|
|
|
local name = '<b>'..data.user_name..'</b>'
|
|
|
|
local id = ' <i>(ID '..data.user_id..')</i>'
|
|
|
|
if data.user_watching == '1' then
|
|
|
|
watching = '<b>'..data.user_watching..' Anime</b>'
|
|
|
|
else
|
|
|
|
watching = '<b>'..data.user_watching..' Animes</b>'
|
|
|
|
end
|
|
|
|
local pause = '<b>'..data.user_onhold..' pausiert</b>'
|
|
|
|
local dropped = '<b>'..data.user_dropped..' abgebrochen</b>'
|
2017-02-15 16:49:23 +01:00
|
|
|
local complete = '<b>'..data.user_completed..' beendet</b>'
|
2016-11-13 22:40:24 +01:00
|
|
|
if data.user_plantowatch == '1' then
|
|
|
|
planed = '<b>'..data.user_plantowatch..'</b> steht'
|
|
|
|
else
|
|
|
|
planed = '<b>'..data.user_plantowatch..'</b> stehen'
|
|
|
|
end
|
|
|
|
local mal_url = '<a href="http://myanimelist.net/profile/'..data.user_name..'">Profil aufrufen</a>'
|
|
|
|
|
|
|
|
local text = name..id..' schaut derzeit '..watching..', hat '..pause..', '..dropped..' und '..complete..'. '..planed..' auf der Watchlist.\n'..mal_url
|
2016-08-22 22:57:17 +02:00
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
function mal_user:action(msg, config, matches)
|
|
|
|
local user = matches[1]
|
|
|
|
local text = mal_user:get_infos(user)
|
|
|
|
if not text then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, config.errors.results)
|
2016-08-22 22:57:17 +02:00
|
|
|
return
|
|
|
|
end
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, text, 'HTML')
|
2016-08-22 22:57:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return mal_user
|