From 3dd7affd96744d15033bf94c2d1ea0ad75fc460f Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 26 Nov 2017 00:25:51 +0100 Subject: [PATCH] nickchange & leveltrigger --- src/inc/trigger/core.js | 98 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/src/inc/trigger/core.js b/src/inc/trigger/core.js index 9373066..5a2322f 100644 --- a/src/inc/trigger/core.js +++ b/src/inc/trigger/core.js @@ -1,5 +1,5 @@ import sql from "../sql.js"; -import admins from "../admin.js"; +import { getLevel, loadAdmins } from "../admin.js"; module.exports = bot => { bot._trigger.set("join", { @@ -27,4 +27,100 @@ module.exports = bot => { 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`); + } + + } + }); }; \ No newline at end of file