nickchange & leveltrigger

This commit is contained in:
Flummi 2017-11-26 00:25:51 +01:00
parent d1c422f767
commit 3dd7affd96

View File

@ -1,5 +1,5 @@
import sql from "../sql.js"; import sql from "../sql.js";
import admins from "../admin.js"; import { getLevel, loadAdmins } from "../admin.js";
module.exports = bot => { module.exports = bot => {
bot._trigger.set("join", { bot._trigger.set("join", {
@ -27,4 +27,100 @@ module.exports = bot => {
e.reply(`parted channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`); e.reply(`parted channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`);
} }
}); });
bot._trigger.set("nick", {
call: /^\!nick .*/i,
level: 100,
active: true,
clients: ["irc"],
f: e => {
let args = e.message.trim().substring(6).split(" ");
e.write(`NICK ${args[0]}`);
e._user.deli(e.self.me.nickname);
e.whois(args[0]);
e.reply(`changed nick to ${args[0]}`);
}
});
bot._trigger.set("level", {
call: /^\!level/i,
level: 0,
active: true,
clients: ["irc"],
f: e => {
const args = e.message.split(' ');
if (Number.isInteger(parseInt(args[2]))) {
if (e.user.level.level >= 100) {
const name = args[1].replace('@', '');
const level = Math.min(Math.max(0, 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.exec("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.exec("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.exec("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(`f0ck you hard`);
//}
}
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`);
}
}
});
}; };