44 lines
1.5 KiB
Lua
44 lines
1.5 KiB
Lua
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)
|
|
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&diagnostics=true&callback='
|
|
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
|
|
|
|
local name = data.user_name
|
|
local watching = data.user_watching
|
|
local pause = data.user_onhold
|
|
local dropped = data.user_dropped
|
|
local complete = data.user_completed
|
|
local planed = data.user_plantowatch
|
|
local mal_url = 'http://myanimelist.net/profile/'..data.user_name
|
|
local text = '<b>'..name..'</b> schaut derzeit <b>'..watching..' Animes</b>, hat <b>'..pause..' pausiert</b>, <b>'..dropped..' abgebrochen</b> und <b>'..complete..' beendet</b>. <b>'..planed..'</b> stehen auf der Watchlist.\n<a href="'..mal_url..'">Profil aufrufen</a>'
|
|
|
|
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
|
|
utilities.send_reply(msg, config.errors.results)
|
|
return
|
|
end
|
|
utilities.send_reply(msg, text, 'HTML')
|
|
end
|
|
|
|
return mal_user |