Levelsystem
This commit is contained in:
parent
f8d42a3f01
commit
29d20790fc
@ -35,6 +35,10 @@ read().then(() => {
|
||||
if (!active)
|
||||
continue;
|
||||
|
||||
if (trigger.level > e.user.level.level) {
|
||||
e.reply(`no permission, min level ${trigger.level} required`);
|
||||
break;
|
||||
}
|
||||
trigger.f(e);
|
||||
}
|
||||
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
|
||||
|
40
src/inc/admin.js
Normal file
40
src/inc/admin.js
Normal file
@ -0,0 +1,40 @@
|
||||
import sql from "./sql.js";
|
||||
|
||||
export let admins = [];
|
||||
export const loadAdmins = (() => {
|
||||
sql.exec("select * from `admins`")
|
||||
.then(rows => {
|
||||
rows.forEach(row => {
|
||||
admins.push({
|
||||
id: row.id,
|
||||
prefix: row.prefix,
|
||||
account: row.account,
|
||||
network: row.network,
|
||||
level: row.level
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("keine Admins vorhanden");
|
||||
});
|
||||
})();
|
||||
|
||||
export const getLevel = (network, user) => {
|
||||
let ret = {
|
||||
level: 0,
|
||||
verified: false
|
||||
};
|
||||
if (typeof user !== "object")
|
||||
return "user has to be an object!";
|
||||
if (!user.account || !user.prefix)
|
||||
return ret;
|
||||
for(let admin of admins) {
|
||||
if (admin.account === user.account.toLowerCase() && admin.network === network.toLowerCase()) {
|
||||
ret = {
|
||||
level: admin.level,
|
||||
verified: user.prefix.toLowerCase() === admin.prefix
|
||||
};
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
};
|
@ -1,4 +1,6 @@
|
||||
import { logger } from "../log.js";
|
||||
import { getLevel } from "../admin.js";
|
||||
|
||||
const net = require("net")
|
||||
, tls = require("tls")
|
||||
, EventEmitter = require("events").EventEmitter
|
||||
@ -75,7 +77,14 @@ export class irc {
|
||||
type: "irc",
|
||||
network: this.network,
|
||||
channel: tmp.params[0],
|
||||
user: this.parsePrefix(tmp.prefix),
|
||||
user: Object.assign(this.parsePrefix(tmp.prefix), {
|
||||
account: this.server.user.geti(this.parsePrefix(tmp.prefix).nick).account,
|
||||
prefix: tmp.prefix.charAt(0) === ":" ? tmp.prefix.substring(1) : tmp.prefix,
|
||||
level: getLevel(this.network, Object.assign(this.parsePrefix(tmp.prefix), {
|
||||
account: this.server.user.geti(this.parsePrefix(tmp.prefix).nick).account,
|
||||
prefix: tmp.prefix.charAt(0) === ":" ? tmp.prefix.substring(1) : tmp.prefix
|
||||
}))
|
||||
}),
|
||||
message: tmp.params[1],
|
||||
time: ~~(Date.now() / 1000),
|
||||
raw: tmp,
|
||||
@ -115,6 +124,7 @@ export class irc {
|
||||
hostname: tmpuser.hostname || false,
|
||||
realname: tmpuser.realname || false,
|
||||
account: tmpuser.account || false,
|
||||
prefix: tmpuser.prefix || false,
|
||||
registered: tmpuser.registered || false,
|
||||
oper: tmpuser.oper || false,
|
||||
channels: tmpuser.channels || [],
|
||||
|
@ -16,6 +16,7 @@ module.exports = client => {
|
||||
tmpuser.username = msg.params[2];
|
||||
tmpuser.hostname = msg.params[3];
|
||||
tmpuser.realname = msg.params[5];
|
||||
tmpuser.prefix = `${msg.params[2]}!${msg.params[5]}@${msg.params[3]}`;
|
||||
this.server.user.set(msg.params[1], tmpuser);
|
||||
}.bind(client));
|
||||
|
||||
@ -37,6 +38,7 @@ module.exports = client => {
|
||||
hostname: tmpuser.hostname || false,
|
||||
realname: tmpuser.realname || false,
|
||||
account: tmpuser.account || false,
|
||||
prefix: tmpuser.prefix || false,
|
||||
registered: tmpuser.registered || false,
|
||||
oper: tmpuser.oper || false,
|
||||
channels: tmpuser.channels || [],
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { logger } from "../log.js";
|
||||
import { getLevel } from "../admin.js";
|
||||
|
||||
const tgapi = require("node-telegram-bot-api")
|
||||
, EventEmitter = require("events").EventEmitter
|
||||
, util = require("util");
|
||||
@ -21,6 +23,8 @@ export class tg {
|
||||
this.server.user.set(msg.from.username || msg.from.first_name, {
|
||||
nick: msg.from.first_name,
|
||||
username: msg.from.username,
|
||||
account: msg.from.id.toString(),
|
||||
prefix: `${msg.from.username}!${msg.from.id.toString()}`,
|
||||
id: msg.from.id
|
||||
});
|
||||
|
||||
@ -38,9 +42,16 @@ export class tg {
|
||||
channel: tmp.chat.title,
|
||||
channelid: tmp.chat.id,
|
||||
user: {
|
||||
prefix: `${tmp.from.username}!${tmp.from.id}`,
|
||||
nick: tmp.from.first_name,
|
||||
username: tmp.from.username,
|
||||
hostname: tmp.from.id
|
||||
account: tmp.from.id.toString(),
|
||||
level: getLevel("Telegram", {
|
||||
prefix: `${tmp.from.username}!${tmp.from.id}`,
|
||||
nick: tmp.from.first_name,
|
||||
username: tmp.from.username,
|
||||
account: tmp.from.id.toString()
|
||||
})
|
||||
},
|
||||
message: tmp.text,
|
||||
time: tmp.date,
|
||||
|
@ -1,36 +1,38 @@
|
||||
import { admins, getLevel } from "../admin.js";
|
||||
|
||||
const vm = require("vm");
|
||||
|
||||
let maxoutput = 500;
|
||||
let context = vm.createContext({
|
||||
e: null,
|
||||
bot: null
|
||||
bot: null,
|
||||
admins: null,
|
||||
});
|
||||
module.exports = bot => {
|
||||
bot._trigger.set("sandbox_debug", {
|
||||
call: /^\!debug (.*)/i,
|
||||
level: 0,
|
||||
level: 100,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
const args = e.message.trim().substring(7);
|
||||
if ((e.user.nick === "Flummi" && e.network === "n0xy")
|
||||
|| (e.user.nick === "belst" && e.network === "n0xy")
|
||||
|| (e.user.nick === "jkhsjdhjs" && e.network === "n0xy")
|
||||
) {
|
||||
try {
|
||||
let output = vm.runInContext(args, context);
|
||||
if (typeof output !== undefined && output) {
|
||||
output = JSON.stringify(output);
|
||||
if (output.length > maxoutput)
|
||||
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
|
||||
else
|
||||
e.reply(output);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
e.reply(err.message);
|
||||
try {
|
||||
context.admins = admins;
|
||||
context.e = e;
|
||||
context.bot = bot;
|
||||
context.level = getLevel;
|
||||
let output = vm.runInContext(args, vm.createContext(context));
|
||||
if (typeof output !== undefined && output) {
|
||||
output = JSON.stringify(output);
|
||||
if (output.length > maxoutput)
|
||||
return e.reply(`holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)`);
|
||||
else
|
||||
e.reply(output);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
e.reply(err.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
@ -55,7 +55,7 @@ module.exports = bot => {
|
||||
|
||||
bot._trigger.set("sandbox", {
|
||||
call: /^\!(hs|py|cpp|bf|php|lua|bash) .*/i,
|
||||
level: 100,
|
||||
level: 0,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
@ -72,7 +72,7 @@ module.exports = bot => {
|
||||
|
||||
bot._trigger.set("sandbox_rs", {
|
||||
call: /^\!rs (.*)/i,
|
||||
level: 100,
|
||||
level: 0,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
@ -102,7 +102,7 @@ module.exports = bot => {
|
||||
|
||||
bot._trigger.set("bfgen", {
|
||||
call: /^\!bfgen .*/i,
|
||||
level: 100,
|
||||
level: 0,
|
||||
active: true,
|
||||
clients: ["irc", "tg"],
|
||||
f: e => {
|
||||
|
Loading…
Reference in New Issue
Block a user