import fetch from "../fetch";
export default bot => {
bot._trigger.set("irpg", new bot.trigger({
call: /^\.irpg/i,
set: "uwe",
f: e => {
fetch("https://irpg.zneb.org/db.php")
.then(res => res.text())
.then(res => {
e.args[0] = e.args[0] || e.user.nick;
let players = new Map();
res
.split("\n").join``
.match(/\
(.*?)\<\/tr\>/gsi)
.map((l, i) => `${i} | ${l}`.match(/\(.*?)\<\/td\>/gsi))
.map(l => l?l.map(m => m
.replace("", "")
.replace(" | ", "")
.replace(" | ", "")
):false)
.splice(1)
.forEach(p => players.set(p[1].toLowerCase(), {
rang: parseInt(p[0]),
name: p[1],
level: parseInt(p[2]),
class: p[4],
ttl: p[5],
online: p[7] === "Yes"
}));
let p = players.has(e.args[0].toLowerCase())?players.get(e.args[0].toLowerCase()):false;
let tmp = e.args[0].match(/#\d+/);
if(tmp) {
tmp = parseInt(tmp[0].slice(1)) - 1;
if(tmp >= 0 && tmp <= players.size - 1)
p = [...players.entries()][tmp][1];
}
if(!p)
return e.reply("user / rang doesn't exist. D:");
e.reply(`(${p.rang} / ${players.size}) [b]${p.name}[/b], the [b]${p.class}[/b] is ${p.online?"[color=green]online[/color]":"[color=red]offline[/color]"}: level: ${p.level}, next level in ${p.ttl}.`);
})
.catch(err => console.log(err));
}
}));
};