import sql from "../sql"; import { getLevel, loadAdmins } from "../admin"; export default bot => { bot._trigger.set("join", new bot.trigger({ call: /^\!join .*/i, 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(", ")}`); } })); bot._trigger.set("part", new bot.trigger({ call: /^\!part .*/i, 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(", ")}`); } })); bot._trigger.set("nick", new bot.trigger({ call: /^\!nick .*/i, 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]}`); } })); bot._trigger.set("level", new bot.trigger({ call: /^\!level/i, level: 0, 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.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(`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`); } } })); };