prevent errors during initialization
This commit is contained in:
parent
a225922753
commit
a4e347bcdc
@ -13,6 +13,10 @@ const parseArgs = (msg) => {
|
||||
export default self => {
|
||||
self.bot.on("message", e => {
|
||||
for (var [name, trigger] of self._trigger.entries()) {
|
||||
if (!e.self.me.nickname) {
|
||||
e.reply("nope, still initialising myself :^)");
|
||||
break;
|
||||
}
|
||||
if (!trigger.call.exec(e.message))
|
||||
continue;
|
||||
if (!trigger.clients.includes(e.type))
|
||||
|
@ -4,120 +4,109 @@ import { getLevel, loadAdmins } from "../admin";
|
||||
export default bot => {
|
||||
bot._trigger.set("join", new bot.trigger({
|
||||
call: /^\!join .*/i,
|
||||
active: false,
|
||||
level: 100,
|
||||
clients: ["irc"],
|
||||
f: e => {
|
||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||
chans.map(e.join);
|
||||
e.reply(`joined channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`);
|
||||
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||
chans.map(e.join);
|
||||
e.reply(`joined channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
bot._trigger.set("part", new bot.trigger({
|
||||
call: /^\!part .*/i,
|
||||
active: false,
|
||||
level: 100,
|
||||
clients: ["irc"],
|
||||
f: e => {
|
||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||
chans.map(e.part);
|
||||
e.reply(`parted channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`);
|
||||
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||
chans.map(e.part);
|
||||
e.reply(`parted channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
bot._trigger.set("nick", new bot.trigger({
|
||||
call: /^\!nick .*/i,
|
||||
active: false,
|
||||
level: 100,
|
||||
clients: ["irc"],
|
||||
f: e => {
|
||||
e.write(`NICK ${e.args[0]}`);
|
||||
e._user.deli(e.self.me.nickname);
|
||||
e.whois(e.args[0]);
|
||||
e.reply(`changed nick to ${e.args[0]}`);
|
||||
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||
e.write(`NICK ${e.args[0]}`);
|
||||
e._user.deli(e.self.me.nickname);
|
||||
e.whois(e.args[0]);
|
||||
e.reply(`changed nick to ${e.args[0]}`);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
bot._trigger.set("level", new bot.trigger({
|
||||
call: /^\!level/i,
|
||||
active: false,
|
||||
call: /^\!level .*/i,
|
||||
level: 0,
|
||||
active: false,
|
||||
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(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);
|
||||
})
|
||||
//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 {
|
||||
return e.reply("no changes");
|
||||
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 {
|
||||
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 [b]${name}[/b] isn't registered`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return e.reply(`user not found`);
|
||||
}
|
||||
//}
|
||||
//else {
|
||||
// return e.reply(`f0ck you hard`);
|
||||
//}
|
||||
else
|
||||
return e.reply(`user not found`);
|
||||
}
|
||||
else
|
||||
return e.reply("no permission, min level 100 required");
|
||||
}
|
||||
else {
|
||||
return e.reply("no permission, min level 100 required");
|
||||
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`);
|
||||
}
|
||||
}
|
||||
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`);
|
||||
}
|
||||
|
||||
}
|
||||
}));
|
||||
};
|
Loading…
Reference in New Issue
Block a user