prevent errors during initialization
This commit is contained in:
parent
a225922753
commit
a4e347bcdc
@ -13,6 +13,10 @@ const parseArgs = (msg) => {
|
|||||||
export default self => {
|
export default self => {
|
||||||
self.bot.on("message", e => {
|
self.bot.on("message", e => {
|
||||||
for (var [name, trigger] of self._trigger.entries()) {
|
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))
|
if (!trigger.call.exec(e.message))
|
||||||
continue;
|
continue;
|
||||||
if (!trigger.clients.includes(e.type))
|
if (!trigger.clients.includes(e.type))
|
||||||
|
@ -4,120 +4,109 @@ import { getLevel, loadAdmins } from "../admin";
|
|||||||
export default bot => {
|
export default bot => {
|
||||||
bot._trigger.set("join", new bot.trigger({
|
bot._trigger.set("join", new bot.trigger({
|
||||||
call: /^\!join .*/i,
|
call: /^\!join .*/i,
|
||||||
active: false,
|
|
||||||
level: 100,
|
level: 100,
|
||||||
clients: ["irc"],
|
clients: ["irc"],
|
||||||
f: e => {
|
f: e => {
|
||||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||||
chans.map(e.join);
|
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||||
e.reply(`joined channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`);
|
chans.map(e.join);
|
||||||
|
e.reply(`joined channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
bot._trigger.set("part", new bot.trigger({
|
bot._trigger.set("part", new bot.trigger({
|
||||||
call: /^\!part .*/i,
|
call: /^\!part .*/i,
|
||||||
active: false,
|
|
||||||
level: 100,
|
level: 100,
|
||||||
clients: ["irc"],
|
clients: ["irc"],
|
||||||
f: e => {
|
f: e => {
|
||||||
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||||
chans.map(e.part);
|
const chans = e.args.filter(chan => chan.charAt(0) === "#");
|
||||||
e.reply(`parted channel${chans.length > 1 ? "s" : null}: ${chans.join(", ")}`);
|
chans.map(e.part);
|
||||||
|
e.reply(`parted channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
bot._trigger.set("nick", new bot.trigger({
|
bot._trigger.set("nick", new bot.trigger({
|
||||||
call: /^\!nick .*/i,
|
call: /^\!nick .*/i,
|
||||||
active: false,
|
|
||||||
level: 100,
|
level: 100,
|
||||||
clients: ["irc"],
|
clients: ["irc"],
|
||||||
f: e => {
|
f: e => {
|
||||||
e.write(`NICK ${e.args[0]}`);
|
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||||
e._user.deli(e.self.me.nickname);
|
e.write(`NICK ${e.args[0]}`);
|
||||||
e.whois(e.args[0]);
|
e._user.deli(e.self.me.nickname);
|
||||||
e.reply(`changed nick to ${e.args[0]}`);
|
e.whois(e.args[0]);
|
||||||
|
e.reply(`changed nick to ${e.args[0]}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
bot._trigger.set("level", new bot.trigger({
|
bot._trigger.set("level", new bot.trigger({
|
||||||
call: /^\!level/i,
|
call: /^\!level .*/i,
|
||||||
active: false,
|
|
||||||
level: 0,
|
level: 0,
|
||||||
|
active: false,
|
||||||
clients: ["irc"],
|
clients: ["irc"],
|
||||||
f: e => {
|
f: e => {
|
||||||
const args = e.message.split(' ');
|
if(e.self.me.nickname.toLowerCase() === e.args.shift().toLowerCase()) {
|
||||||
if (Number.isInteger(parseInt(args[2]))) {
|
//const args = e.message.split(' ');
|
||||||
if (e.user.level.level >= 100) {
|
e.message = e.args.join("");
|
||||||
const name = args[1].replace('@', '');
|
console.log(e.message);
|
||||||
const level = Math.min(Math.max(0, args[2]), 100);
|
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 (name.toLowerCase() != bot.me.toLowerCase()) {
|
||||||
if (e._user.hasi(name)) {
|
if (e._user.hasi(name)) {
|
||||||
const user = e._user.geti(name);
|
const user = e._user.geti(name);
|
||||||
if (user.registered) { // check if user is registered
|
if (user.registered) { // check if user is registered
|
||||||
const userlevel = getLevel(e.network, user).level;
|
const userlevel = getLevel(e.network, user).level;
|
||||||
if(userlevel > 0) { // check if user is admin
|
if(userlevel > 0) { // check if user is admin
|
||||||
if(level <= 0) {
|
if(level <= 0) {
|
||||||
sql.any("delete from admins where account = lower(?) and network = lower(?)", [user.account, e.network])
|
sql.any("delete from admins where account = lower(?) and network = lower(?)", [user.account, e.network])
|
||||||
.then(rows => {
|
.then(rows => {
|
||||||
loadAdmins();
|
loadAdmins();
|
||||||
return e.reply(`deleted user ${user.nickname}`);
|
return e.reply(`deleted user ${user.nickname}`);
|
||||||
})
|
}).catch(err => console.log("delete", err))
|
||||||
.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 => {
|
||||||
else if(level !== userlevel) {
|
loadAdmins();
|
||||||
sql.any("update admins set level = ? where account = ? and network = ?", [level, user.account, e.network])
|
return e.reply(`changed user [b]${user.nickname}[/b] (${userlevel} -> ${level})`);
|
||||||
.then(rows => {
|
}).catch(err => console.log("update", err))
|
||||||
loadAdmins();
|
}
|
||||||
return e.reply(`changed user [b]${user.nickname}[/b] (${userlevel} -> ${level})`);
|
else
|
||||||
})
|
return e.reply("no changes");
|
||||||
.catch(err => {
|
|
||||||
console.log("update", err);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
else
|
||||||
sql.any("insert into admins (prefix, account, level, network) values (lower(?), lower(?), ?, lower(?))", [user.prefix, user.account, level, e.network])
|
return e.reply(`user [b]${name}[/b] isn't registered`);
|
||||||
.then(rows => {
|
|
||||||
loadAdmins();
|
|
||||||
return e.reply(`added new user [b]${user.nickname}[/b] with level ${level}`);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.log("add", err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
return e.reply(`user [b]${name}[/b] isn't registered`);
|
return e.reply(`user not found`);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else {
|
return e.reply("no permission, min level 100 required");
|
||||||
return e.reply(`user not found`);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
//else {
|
|
||||||
// return e.reply(`f0ck you hard`);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
else {
|
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