This commit is contained in:
Flummi 2019-08-19 19:53:55 +00:00
parent 6472112aa1
commit fe936b8cd6
5 changed files with 60 additions and 146 deletions

View File

@ -5,15 +5,13 @@ export default async bot => {
name: "chatbot",
call: /^(?![!./[])(.*uw(e|i).*)/i,
set: "uwe",
f: e => {
const chat = e.message
f: async e => {
const res = await cleverbot.ask(e.message
.replace(/uw(e|i)/gi, "")
.split("?")
.join("");
cleverbot.ask(chat)
.then(res => {
e.reply(res.response);
}).catch(console.error);
.join("")
);
e.reply(res.response);
}
}]
};

View File

@ -1,6 +1,3 @@
import sql from "../sql";
import { getLevel } from "../admin";
export default async bot => {
return [{
@ -40,72 +37,5 @@ export default async bot => {
e.reply(`changed nick to ${e.args[0]}`);
}
}
}, {
name: "level",
call: /^\!level .*/i,
level: 0,
active: false,
clients: ["irc"],
f: e => {
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
//const args = e.message.split(' ');
e.message = e.args.join("");
console.log(e.message);
if (Number.isInteger(parseInt(e.args[2]))) {
if (e.user.level.level >= 100) {
const name = e.args[1].replace('@', '');
const level = Math.min(Math.max(0, e.args[2]), 100);
//if (name.toLowerCase() != bot.me.toLowerCase()) {
if (e._user.hasi(name)) {
const user = e._user.geti(name);
if (user.registered) { // check if user is registered
const userlevel = getLevel(e.network, user).level;
if(userlevel > 0) { // check if user is admin
if(level <= 0) {
sql.any("delete from admins where account = lower(?) and network = lower(?)", [user.account, e.network])
.then(rows => {
loadAdmins();
return e.reply(`deleted user ${user.nickname}`);
}).catch(err => console.log("delete", err))
}
else if(level !== userlevel) {
sql.any("update admins set level = ? where account = ? and network = ?", [level, user.account, e.network])
.then(rows => {
loadAdmins();
return e.reply(`changed user [b]${user.nickname}[/b] (${userlevel} -> ${level})`);
}).catch(err => console.log("update", err))
}
else
return e.reply("no changes");
}
else {
sql.any("insert into admins (prefix, account, level, network) values (lower(?), lower(?), ?, lower(?))", [user.prefix, user.account, level, e.network])
.then(rows => {
loadAdmins();
return e.reply(`added new user [b]${user.nickname}[/b] with level ${level}`);
}).catch(err => console.log("add", err))
}
}
else
return e.reply(`user [b]${name}[/b] isn't registered`);
}
else
return e.reply(`user not found`);
}
else
return e.reply("no permission, min level 100 required");
}
else {
let user = (!(user = e.message.match(/^\!level(?: +@(.*))?/i)[1])) ? e.user.nick : user.trim();
if(e._user.hasi(user)) {
const level = getLevel(e.network, e._user.geti(user));
e.reply(`level from ${user}: ${level.level} (${level.verified ? "verified" : "unverified"})`);
}
else
e.reply(`user not found`);
}
}
}
}]
};

View File

@ -6,51 +6,47 @@ export default async bot => {
name: "irpg",
call: /^\.irpg/i,
set: "uwe",
f: e => {
fetch("https://f0ck.me/irpg/db.php")
.then(res => res.text())
.then(res => {
e.args[0] = e.args[0] || e.user.nick;
let players = new Map()
, alias = {};
res
.split("\n").join``
.match(/\<tr\>(.*?)\<\/tr\>/gsi)
.map((l, i) => `<td>${i}</td>${l}`.match(/\<td.*?\>(.*?)\<\/td\>/gsi))
.map(l => l?l.map(m => m
.replace("<td>", "")
.replace("<td nowrap>", "")
.replace("</td>", "")
):false)
.splice(1)
.forEach(p => { // 6 archangel!archangel@pomf.space
const nick = p[6].split("!")[0].toLowerCase();
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",
nick: nick,
itemsum: parseInt(p[31])
});
if(nick !== p[1].toLowerCase())
alias[nick] = p[1].toLowerCase();
});
e.args[0] = (e.args[0].toLowerCase() in alias)?alias[e.args[0].toLowerCase()]:e.args[0];
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}. Itemsum: ${p.itemsum}`);
})
.catch(err => console.log(err));
f: async e => {
const res = await (await fetch("https://f0ck.me/irpg/db.php")).text();
e.args[0] = e.args[0] || e.user.nick;
let players = new Map()
, alias = {};
res
.split("\n").join``
.match(/\<tr\>(.*?)\<\/tr\>/gsi)
.map((l, i) => `<td>${i}</td>${l}`.match(/\<td.*?\>(.*?)\<\/td\>/gsi))
.map(l => l?l.map(m => m
.replace("<td>", "")
.replace("<td nowrap>", "")
.replace("</td>", "")
):false)
.splice(1)
.forEach(p => { // 6 archangel!archangel@pomf.space
const nick = p[6].split("!")[0].toLowerCase();
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",
nick: nick,
itemsum: parseInt(p[31])
});
if(nick !== p[1].toLowerCase())
alias[nick] = p[1].toLowerCase();
});
e.args[0] = (e.args[0].toLowerCase() in alias)?alias[e.args[0].toLowerCase()]:e.args[0];
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}. Itemsum: ${p.itemsum}`);
}
}];
};

View File

@ -18,17 +18,14 @@ export default async bot => {
name: "mcmaniac_add",
call: /Mc.*iaC/,
set: "nxy",
f: e => {
const match = e.message.match(/(Mc\S+iaC?)/)[0];
sql.any(_query_add, [match])
.then()
.catch(err => {});
f: async e => {
await sql.any(_query_add, [e.message.match(/(Mc\S+iaC?)/)[0]]);
}
}, {
name: "mcmaniac_get",
call: /^(\.|\/)mcmaniac/i,
set: "nxy",
f: e => {
f: async e => {
const args = e.message.trim().substring(10);
let order = "id asc"
, offset
@ -52,13 +49,9 @@ export default async bot => {
query = query
.split("{order}").join(order)
.split("{offset}").join(offset);
sql.any(query)
.then(rows => {
e.reply(`[${rows[0].rank}/${rows[0].total}] ${rows[0].item}`);
})
.catch(err => {
console.log(err);
});
const rows = await sql.any(query);
e.reply(`[${rows[0].rank}/${rows[0].total}] ${rows[0].item}`);
}
}];
};

View File

@ -12,22 +12,19 @@ export default async bot => {
text: "Searches for a term on Urbandict and returns first result",
usage: "[b].ud[/b] [i]<term>[/i] [i](<index>)[/i]"
},
f: e => {
f: async e => {
let index = 1;
if(!isNaN(e.args[e.args.length - 1]) && e.args.length > 1)
index = parseInt(e.args.pop());
const term = e.args.join(" ").trim().toLowerCase();
fetch(`${url}?term=${term}`)
.then(res => res.json())
.then(data => {
if(data.result_type === "no_results")
return e.reply("Term not found");
if(!data.list[index-1])
return e.reply("Index not found");
const res = data.list[index-1];
e.reply(`[${index}/${data.list.length}] [b]${res.word}[/b]: ${res.definition.replace(/\r\n/g, "")} - ${res.example.replace(/\r\n/g, "")}`);
}).catch(err => console.log(err));
const data = await (await fetch(`${url}?term=${term}`)).json();
if(data.result_type === "no_results")
return e.reply("Term not found");
if(!data.list[index-1])
return e.reply("Index not found");
const res = data.list[index-1];
e.reply(`[${index}/${data.list.length}] [b]${res.word}[/b]: ${res.definition.replace(/\r\n/g, "")} - ${res.example.replace(/\r\n/g, "")}`);
}
}];
};