modified: src/inc/admin.mjs

modified:   src/inc/cfg.mjs
	modified:   src/inc/events/ctcp.mjs
	modified:   src/inc/events/message.mjs
	deleted:    src/inc/log.mjs
	modified:   src/inc/sql.mjs
	deleted:    src/inc/trigger/inc/parser.mjs
	modified:   src/index.mjs
This commit is contained in:
Flummi 2019-04-25 01:20:20 +00:00
parent d2c8ca346f
commit 54ea970a3e
8 changed files with 34 additions and 66 deletions

View File

@ -1,11 +1,12 @@
import sql from "./sql";
export let admins = [];
export const loadAdmins = () => {
export const loadAdmins = async () => {
const db = await sql;
admins = [];
sql.exec(`select * from admins`)
.then(rows => {
rows.forEach(row => {
db.query(`select * from user`)
.then(rows => rows.forEach(row => {
admins.push({
id: row.id,
prefix: row.prefix,
@ -13,13 +14,15 @@ export const loadAdmins = () => {
network: row.network,
level: row.level
});
});
})
}))
.catch(err => {
console.log("keine Admins vorhanden");
console.log("keine Admins vorhanden", err);
});
};
loadAdmins();
(async () => {
await loadAdmins();
})();
export const getLevel = (network, user) => {
let ret = {

View File

@ -9,7 +9,7 @@ let cfg = {
let admins = [];
const read = () => new Promise((resolve, reject) => {
sql.exec("select * from cfg").then(rows => {
sql.query("select * from cfg").then(rows => {
for (let row in rows) {
cfg[rows[row].class][rows[row].key] = {
val: ((type, value) => {
@ -37,7 +37,7 @@ const read = () => new Promise((resolve, reject) => {
export const loadAdmins = () => new Promise((resolve, reject) => {
admins = [];
sql.exec(`select * from admins`)
sql.query(`select * from admins`)
.then(rows => {
rows.forEach(row => {
admins.push({

View File

@ -1,5 +1,3 @@
import { logger } from "../log";
const versions = [
"AmIRC.1 (8 Bit) for Commodore Amiga 500",
"HexChat 0.72 [x86] / Windows 95c [500MHz]"

View File

@ -1,5 +1,4 @@
import { logger } from "../log";
import { cfg } from "../cfg";
import { getLevel } from "../admin";
const parseArgs = msg => {
let args = msg.trim().split(" ");
@ -32,7 +31,7 @@ export default self => {
if ((e.self.set !== "all" && e.self.set !== trigger.set) && trigger.set !== "all")
continue;
if (trigger.level > e.user.level.level) {
if (trigger.level > getLevel(e.network, e.user)) {
e.reply(`no permission, min level ${trigger.level} required`);
break;
}
@ -40,6 +39,6 @@ export default self => {
e = Object.assign(e, parseArgs(e.message));
trigger.f(e);
}
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
console.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
});
};

View File

@ -1,26 +0,0 @@
import winston from "winston";
const logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
name: "debug-file",
filename: `./logs/${~~(Date.now() / 1000)}_debug.log`,
level: "debug"
}),
new (winston.transports.File)({
name: "info-file",
filename: `./logs/${~~(Date.now() / 1000)}_info.log`,
level: "info"
}),
new (winston.transports.File)({
name: "error-file",
filename: `./logs/${~~(Date.now() / 1000)}_error.log`,
level: "error"
}),
new (winston.transports.Console)({
level: "info"
})
]
});
export { logger };

View File

@ -1,5 +1,4 @@
import mysql from "nodejs-mysql2";
import { default as cfg } from "../../cfg/sql.json";
import mariadb from "mariadb";
import cfg from "../../config.json";
const sql = mysql.default.getInstance(cfg);
export default sql;
export default mariadb.createPool(cfg.sql).getConnection();

View File

@ -1,8 +0,0 @@
const formatSize = (size, i = ~~(Math.log(size) / Math.log(1024))) => (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
const getUUID = () => Math.random().toString(36).slice(-10) + (new Date()).getTime().toString(36).slice(-3);
const calcSpeed = (bytes, seconds) => `${Math.round((bytes * 8 / seconds / 1000000) * 10000) / 10000} Mbit/s`;
export { calcSpeed, formatSize, getUUID };

View File

@ -1,11 +1,12 @@
import { logger } from "./inc/log";
import { read, cfg, admins } from "./inc/cfg";
import cfg from "../config.json";
import sql from "./inc/sql";
import { cuffeo } from "cuffeo";
import triggers from "./inc/trigger";
import events from "./inc/events";
read().then(() => {
(async () => {
// Chatbots
const self = {
_trigger: new Map(),
trigger: function trigger(args) {
@ -14,11 +15,13 @@ read().then(() => {
this.level = args.level || 0;
this.active = args.hasOwnProperty("active") ? args.active : true;
this.set = args.set || "all"; // uwe, nxy, f0ck, all
this.clients = args.clients || ["irc", "tg", "discord"];
this.clients = args.clients || ["irc", "tg"];
this.f = args.f;
},
bot: new cuffeo(cfg.client, admins)
bot: new cuffeo(cfg.clients)
};
triggers.forEach(mod => mod(self));
events.forEach(event => event(self));
}).catch(err => logger.error(`(main) ${err.message}`));
//
})();