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:
parent
d2c8ca346f
commit
54ea970a3e
|
@ -1,11 +1,12 @@
|
||||||
import sql from "./sql";
|
import sql from "./sql";
|
||||||
|
|
||||||
export let admins = [];
|
export let admins = [];
|
||||||
export const loadAdmins = () => {
|
|
||||||
|
export const loadAdmins = async () => {
|
||||||
|
const db = await sql;
|
||||||
admins = [];
|
admins = [];
|
||||||
sql.exec(`select * from admins`)
|
db.query(`select * from user`)
|
||||||
.then(rows => {
|
.then(rows => rows.forEach(row => {
|
||||||
rows.forEach(row => {
|
|
||||||
admins.push({
|
admins.push({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
prefix: row.prefix,
|
prefix: row.prefix,
|
||||||
|
@ -13,13 +14,15 @@ export const loadAdmins = () => {
|
||||||
network: row.network,
|
network: row.network,
|
||||||
level: row.level
|
level: row.level
|
||||||
});
|
});
|
||||||
});
|
}))
|
||||||
})
|
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log("keine Admins vorhanden");
|
console.log("keine Admins vorhanden", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
loadAdmins();
|
|
||||||
|
(async () => {
|
||||||
|
await loadAdmins();
|
||||||
|
})();
|
||||||
|
|
||||||
export const getLevel = (network, user) => {
|
export const getLevel = (network, user) => {
|
||||||
let ret = {
|
let ret = {
|
||||||
|
|
|
@ -9,7 +9,7 @@ let cfg = {
|
||||||
let admins = [];
|
let admins = [];
|
||||||
|
|
||||||
const read = () => new Promise((resolve, reject) => {
|
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) {
|
for (let row in rows) {
|
||||||
cfg[rows[row].class][rows[row].key] = {
|
cfg[rows[row].class][rows[row].key] = {
|
||||||
val: ((type, value) => {
|
val: ((type, value) => {
|
||||||
|
@ -37,7 +37,7 @@ const read = () => new Promise((resolve, reject) => {
|
||||||
|
|
||||||
export const loadAdmins = () => new Promise((resolve, reject) => {
|
export const loadAdmins = () => new Promise((resolve, reject) => {
|
||||||
admins = [];
|
admins = [];
|
||||||
sql.exec(`select * from admins`)
|
sql.query(`select * from admins`)
|
||||||
.then(rows => {
|
.then(rows => {
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
admins.push({
|
admins.push({
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { logger } from "../log";
|
|
||||||
|
|
||||||
const versions = [
|
const versions = [
|
||||||
"AmIRC.1 (8 Bit) for Commodore Amiga 500",
|
"AmIRC.1 (8 Bit) for Commodore Amiga 500",
|
||||||
"HexChat 0.72 [x86] / Windows 95c [500MHz]"
|
"HexChat 0.72 [x86] / Windows 95c [500MHz]"
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { logger } from "../log";
|
import { getLevel } from "../admin";
|
||||||
import { cfg } from "../cfg";
|
|
||||||
|
|
||||||
const parseArgs = msg => {
|
const parseArgs = msg => {
|
||||||
let args = msg.trim().split(" ");
|
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")
|
if ((e.self.set !== "all" && e.self.set !== trigger.set) && trigger.set !== "all")
|
||||||
continue;
|
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`);
|
e.reply(`no permission, min level ${trigger.level} required`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +39,6 @@ export default self => {
|
||||||
e = Object.assign(e, parseArgs(e.message));
|
e = Object.assign(e, parseArgs(e.message));
|
||||||
trigger.f(e);
|
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}`);
|
||||||
});
|
});
|
||||||
};
|
};
|
|
@ -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 };
|
|
|
@ -1,5 +1,4 @@
|
||||||
import mysql from "nodejs-mysql2";
|
import mariadb from "mariadb";
|
||||||
import { default as cfg } from "../../cfg/sql.json";
|
import cfg from "../../config.json";
|
||||||
|
|
||||||
const sql = mysql.default.getInstance(cfg);
|
export default mariadb.createPool(cfg.sql).getConnection();
|
||||||
export default sql;
|
|
||||||
|
|
|
@ -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 };
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { logger } from "./inc/log";
|
import cfg from "../config.json";
|
||||||
import { read, cfg, admins } from "./inc/cfg";
|
import sql from "./inc/sql";
|
||||||
import { cuffeo } from "cuffeo";
|
import { cuffeo } from "cuffeo";
|
||||||
|
|
||||||
import triggers from "./inc/trigger";
|
import triggers from "./inc/trigger";
|
||||||
import events from "./inc/events";
|
import events from "./inc/events";
|
||||||
|
|
||||||
read().then(() => {
|
(async () => {
|
||||||
|
// Chatbots
|
||||||
const self = {
|
const self = {
|
||||||
_trigger: new Map(),
|
_trigger: new Map(),
|
||||||
trigger: function trigger(args) {
|
trigger: function trigger(args) {
|
||||||
|
@ -14,11 +15,13 @@ read().then(() => {
|
||||||
this.level = args.level || 0;
|
this.level = args.level || 0;
|
||||||
this.active = args.hasOwnProperty("active") ? args.active : true;
|
this.active = args.hasOwnProperty("active") ? args.active : true;
|
||||||
this.set = args.set || "all"; // uwe, nxy, f0ck, all
|
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;
|
this.f = args.f;
|
||||||
},
|
},
|
||||||
bot: new cuffeo(cfg.client, admins)
|
bot: new cuffeo(cfg.clients)
|
||||||
};
|
};
|
||||||
triggers.forEach(mod => mod(self));
|
triggers.forEach(mod => mod(self));
|
||||||
events.forEach(event => event(self));
|
events.forEach(event => event(self));
|
||||||
}).catch(err => logger.error(`(main) ${err.message}`));
|
|
||||||
|
//
|
||||||
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user