cuffeo ausgelagert..

This commit is contained in:
Flummi 2019-08-17 11:54:50 +00:00
parent 05d42650ec
commit c0ef557f72
31 changed files with 22 additions and 1021 deletions

View File

@ -1,11 +1,15 @@
import { logger } from "./inc/log";
import { read, cfg } from "./inc/cfg";
import { wrapper } from "./inc/wrapper";
import { default as config } from "../cfg/config.json";
import triggers from "./inc/trigger";
import events from "./inc/events";
read().then(() => {
import cuffeo from "cuffeo";
(async () => {
await read(); // read and parse config from database
const self = {
_trigger: new Map(),
trigger: function trigger(args) {
@ -14,12 +18,12 @@ 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 wrapper()
bot: new cuffeo(config.clients)
};
triggers.forEach(mod => mod(self));
events.forEach(event => event(self));
}).catch(err => logger.error(`(main) ${err.message}`));
})();

View File

@ -1,94 +0,0 @@
import { logger } from "../inc/log";
import { getLevel } from "../inc/admin";
import { spurdo } from "../inc/spurdo";
import { schmuser } from "../inc/schmuser";
import Discord from "discord.js";
import EventEmitter from "events";
export class discord extends EventEmitter {
constructor(options) {
super();
this.options = options || {};
this.token = options.token || null;
this.set = this.options.set || "all";
this.network = "discord";
this.bot = new Discord.Client();
this.bot.login(this.token);
this.server = {
set: this.set,
channel: new Map(),
user: new Map(),
me: {},
spurdo: false,
schmuser: false
};
this.bot.on("ready", () => {
this.server.me = {
nickname: this.bot.user.username,
username: this.bot.user.username,
account: this.bot.user.id.toString(),
prefix: `${this.bot.user.username}!${this.bot.user.id.toString()}`,
id: this.bot.user.id.toString()
};
});
this.bot.on("message", msg => {
if(msg.author.id !== this.server.me.id)
this.emit("data", ["message", this.reply(msg)]);
});
}
reply(tmp) {
return {
type: "discord",
network: "Discord",
channel: tmp.channel.name,
channelid: tmp.channel.id,
user: {
prefix: `${tmp.author.username}!${tmp.author.id}`,
nick: tmp.author.username,
username: tmp.author.username,
account: tmp.author.id.toString(),
level: getLevel("Discord", {
prefix: `${tmp.author.username}!${tmp.author.id}`,
nick: tmp.author.username,
username: tmp.author.username,
account: tmp.author.id.toString()
})
},
message: tmp.content,
time: ~~(Date.now() / 1000),
self: this.server,
reply: msg => this.send(tmp, this.format(msg)),
replyAction: msg => this.send(tmp, this.format(`*${msg}*`), "normal"),
replyNotice: msg => this.send(tmp, this.format(msg))
};
}
send(r, msg, mode="blah") {
switch(mode) {
case "normal":
r.channel.send(msg);
break;
default:
r.reply(msg);
break;
}
}
sendmsg(mode, recipient, msg) {
this.bot.channels.get(recipient).send(msg);
}
format(msg) {
if(this.server.spurdo)
msg = spurdo(msg);
if(this.server.schmuser)
msg = schmuser(msg);
return msg.toString()
.replace(/\[b\](.*?)\[\/b\]/g, "**$1**") // bold
.replace(/\[i\](.*?)\[\/i\]/g, "*$1*") // italic
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2")
;
}
};

View File

@ -1,177 +0,0 @@
import { logger } from "../inc/log";
import { getLevel } from "../inc/admin";
import modules from "./irc/index";
import net from "net";
import tls from "tls";
import EventEmitter from "events";
const colors = {
red: "04",
blue: "12",
yellow: "08",
green: "03",
brown: "05"
};
const msgmodes = {
normal: "PRIVMSG {recipient} :{msg}",
action: "PRIVMSG {recipient} :\u0001ACTION {msg}\u0001",
notice: "NOTICE {recipient} :{msg}"
};
const replaceColor = (match, color, text) => {
if (colors.hasOwnProperty(color))
return `\x03${colors[color]}${text}\x0F`;
return text;
};
export class irc extends EventEmitter {
constructor(options) {
super();
this.options = options || {};
this.options.channels = this.options.channels || [];
this.options.host = this.options.host || "127.0.0.1";
this.options.port = this.options.port || 6667;
this.options.ssl = this.options.ssl || false;
this.options.selfSigned = this.options.selfSigned || false;
this.options.sasl = this.options.sasl || false;
this.network = this.options.network || "test";
this.nickname = this.options.nickname || "test";
this.username = this.options.username || "test";
this.realname = this.options.realname || "test";
this.channels = this.options.channels || [];
this.set = this.options.set || "all";
this._recachetime = 60 * 30; // 30 minutes
this._cmd = new Map();
modules.forEach(mod => mod(this));
this.server = {
set: this.set,
motd: "",
me: {},
channel: [],
user: new Map()
};
this.socket = (this.options.ssl ? tls : net).connect({
host: this.options.host,
port: this.options.port,
rejectUnauthorized: !this.options.selfSigned
}, () => {
this.send(`NICK ${this.nickname}`);
this.send(`USER ${this.username} 0 * : ${this.realname}`);
if(this.options.sasl)
this.send("CAP LS");
});
this.socket.setEncoding("utf-8");
this.socket.on("data", msg => {
msg.split(/\r?\n|\r/).filter(tmp => tmp.length > 0).forEach(tmp => {
const cmd = this.parse(tmp);
if (this._cmd.has(cmd.command))
this._cmd.get(cmd.command)(cmd);
})
});
}
send(data) {
this.socket.write(`${data}\n`);
logger.debug(`(${this.network}) out: ${data}`);
}
sendmsg(mode, recipient, msg) {
msg = msg.split(/\r?\n/);
if(msg.length > 6)
return false;
msg.forEach(e => {
this.send( msgmodes[mode].replace("{recipient}", recipient).replace("{msg}", e) );
});
}
parse(data, [a, ...b] = data.split(/ +:/), tmp = a.split(" ").concat(b)) {
logger.debug(`(${this.network}) in: ${data}`);
let prefix = data.charAt(0) === ":" ? tmp.shift() : null
, command = tmp.shift()
, params = command.toLowerCase() === "privmsg" ? [ tmp.shift(), tmp.join(" :") ] : tmp;
return {
prefix: prefix,
command: command,
params: params
};
}
reply(tmp) {
return {
type: "irc",
network: this.network,
channel: tmp.params[0],
channelid: tmp.params[0],
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].replace(/\u0002/, ""),
time: ~~(Date.now() / 1000),
raw: tmp,
reply: msg => this.sendmsg("normal", tmp.params[0], this.format(""+msg)),
replyAction: msg => this.sendmsg("action", tmp.params[0], this.format(""+msg)),
replyNotice: msg => this.sendmsg("notice", tmp.params[0], this.format(""+msg)),
self: this.server,
_chan: this.server.channel[tmp.params[0]],
_user: this.server.user,
_cmd: this._cmd,
join: chan => this.join(chan),
part: (chan, msg) => this.part(chan, msg),
whois: user => this.whois(user),
write: msg => this.send(msg),
socket: this.socket
};
}
join(channel) {
this.send(`JOIN ${(typeof channel === "object") ? channel.join(",") : channel}`);
}
part(channel, msg=false) {
this.send(`PART ${(typeof channel === "object") ? channel.join(",") : channel}${msg ? " " + msg : " part"}`);
}
whois(user, force = false) {
user = user.toLowerCase();
let tmpuser = {};
if(this.server.user.has(user) && !force) {
tmpuser = this.server.user.get(user);
if(tmpuser.cached >= ~~(Date.now() / 1000) - this._recachetime)
return;
}
tmpuser = {
nickname: tmpuser.nickname || false,
username: tmpuser.username || false,
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 || [],
cached: ~~(Date.now() / 1000)
};
this.server.user.set(user, tmpuser);
this.send(`WHOIS ${user}`);
}
parsePrefix(prefix) {
prefix = /:?(.*)\!(.*)@(.*)/.exec(prefix);
if(!prefix)
return false; //this.parsePrefix(arguments);
return {
nick: prefix[1],
username: prefix[2],
hostname: prefix[3]
};
}
format(msg) {
return msg
.replace(/\[b\](.*?)\[\/b\]/g, "\x02$1\x02") // bold
.replace(/\[i\](.*?)\[\/i\]/g, "\x1D$1\x1D") // italic
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, replaceColor) // colors
;
}
}

View File

@ -1,21 +0,0 @@
export default client => {
client._cmd.set("CAP", function (msg) { // capkram
switch (msg.params[1]) {
case "LS": // list
this.send(`CAP REQ :${msg.params[2]}`);
break;
case "ACK": // success
this.send("AUTHENTICATE PLAIN");
break;
}
}.bind(client));
client._cmd.set("AUTHENTICATE", function (msg) { // auth
if (msg.params[0].match(/\+/))
this.send(`AUTHENTICATE ${new Buffer(this.username + "\u0000" + this.username + "\u0000" + this.options.password).toString("base64")}`);
}.bind(client));
client._cmd.set("900", function (msg) { // cap end
this.send("CAP END");
}.bind(client));
};

View File

@ -1,19 +0,0 @@
import cap from "./cap";
import invite from "./invite";
import join from "./join";
import motd from "./motd";
import msg from "./msg";
import nick from "./nick";
import part from "./part";
import ping from "./ping";
import pwdreq from "./pwdreq";
import welcome from "./welcome";
import who from "./who";
import whois from "./whois";
export default [
cap, invite, join,
motd, msg, nick,
part, ping, pwdreq,
welcome, who, whois
];

View File

@ -1,13 +0,0 @@
export default client => {
client._cmd.set("INVITE", function (msg) { // invite
const user = this.parsePrefix(msg.prefix);
const channel = msg.params[1];
if(!this.server.channel.includes(channel)) {
this.join(channel);
setTimeout(() => {
this.send(`PRIVMSG ${channel} :Hi. Wurde von ${user.nick} eingeladen.`);
}, 1000);
}
}.bind(client));
};

View File

@ -1,5 +0,0 @@
export default client => {
client._cmd.set("JOIN", function (msg) { // join
this.send(`WHO ${msg.params[0]}`);
}.bind(client));
};

View File

@ -1,14 +0,0 @@
export default client => {
client._cmd.set("372", function (msg) { // motd_entry
this.server.motd += `${msg.params[1]}\n`;
}.bind(client));
client._cmd.set("375", function (msg) { // motd_start
this.server.motd = `${msg.params[1]}\n`;
}.bind(client));
client._cmd.set("376", function (msg) { // motd_end
this.server.motd += `${msg.params[1]}\n`;
this.emit("data", ["motd", this.server.motd]);
}.bind(client));
};

View File

@ -1,14 +0,0 @@
export default client => {
client._cmd.set("PRIVMSG", function (msg) { // privmsg
if(msg.params[1] === "\u0001VERSION\u0001")
return this.emit("data", ["ctcp:version", this.reply(msg)]);
else if(msg.params[1].match(/^\u0001PING .*\u0001/i))
return this.emit("data", ["ctcp:ping", this.reply(msg)]);
else
this.emit("data", ["message", this.reply(msg)]);
}.bind(client));
client._cmd.set("NOTICE", function (msg) { // notice
this.emit("data", ["notice", msg.params[1]]);
}.bind(client));
};

View File

@ -1,8 +0,0 @@
export default client => {
client._cmd.set("NICK", function (msg) { // nickchange
let prefix = this.parsePrefix(msg.prefix);
if (this.server.user.hasi(prefix.nick))
this.server.user.deli(prefix.nick);
this.whois(msg.params[0], true); // force
}.bind(client));
};

View File

@ -1,5 +0,0 @@
export default client => {
client._cmd.set("PART", function (msg) { // part
//delete this.server.user[msg.params[0]];
}.bind(client));
};

View File

@ -1,5 +0,0 @@
export default client => {
client._cmd.set("PING", function (msg) { // ping
this.send(`PONG ${msg.params.join``}`);
}.bind(client));
};

View File

@ -1,6 +0,0 @@
export default client => {
client._cmd.set("464", function (msg) { // motd_entry
if (this.options.password.length > 0 && !this.options.sasl)
this.send(`PASS ${this.options.password}`);
}.bind(client));
};

View File

@ -1,6 +0,0 @@
export default client => {
client._cmd.set("001", function (msg) { // welcome
this.join(this.options.channels);
this.emit("data", ["connected", msg.params[1]]);
}.bind(client));
};

View File

@ -1,27 +0,0 @@
const max = 400;
let whois = [];
export default client => {
client._cmd.set("352", function (msg) { // who_entry
if (!this.server.channel[msg.params[1]])
this.server.channel[msg.params[1]] = new Map();
this.server.channel[msg.params[1]].set(msg.params[5], { // chan
nick: msg.params[5],
username: msg.params[2],
hostname: msg.params[3]
});
whois.push(msg.params[5]);
}.bind(client));
client._cmd.set("315", function (msg) { // who_end
this.whois(whois.reduce((a, b) => {
a += `${b},`;
if(a.length >= max) {
this.whois(a.slice(0, -1));
a = "";
}
return a;
}, "").slice(0, -1));
whois = [];
}.bind(client));
};

View File

@ -1,77 +0,0 @@
export default client => {
client._cmd.set("307", function (msg) { // whois_identified (ircd-hybrid)
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.account = msg.params[1];
tmpuser.registered = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("311", function (msg) { // whois_userdata
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.nickname = msg.params[1];
tmpuser.username = msg.params[2];
tmpuser.hostname = msg.params[3];
tmpuser.realname = msg.params[5];
tmpuser.prefix = `${msg.params[1]}!${msg.params[2]}@${msg.params[3]}`;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("313", function (msg) { // whois_oper
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.oper = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("318", function (msg) { // whois_end
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser = {
nickname: tmpuser.nickname || false,
username: tmpuser.username || false,
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 || [],
cached: ~~(Date.now() / 1000)
};
if(msg.params[0] === msg.params[1])
this.server.me = tmpuser;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("319", function (msg) { // whois_chanlist
let tmpchan = new Map()
, tmpuser = {};
if (this.server.user.hasi(msg.params[1])) {
tmpuser = this.server.user.geti(msg.params[1]);
if (tmpuser.channels)
tmpchan = new Map(tmpuser.channels);
}
let chans = msg.params[2].trim().split(" ");
for (let chan in chans) {
chan = chans[chan].split("#");
tmpchan.set(`#${chan[1]}`, chan[0]);
}
tmpuser.channels = tmpchan;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
client._cmd.set("330", function (msg) { // whois_authed_as (snircd)
let tmpuser = {};
if (this.server.user.hasi(msg.params[1]))
tmpuser = this.server.user.geti(msg.params[1]);
tmpuser.account = msg.params[2];
tmpuser.registered = true;
this.server.user.set(msg.params[1], tmpuser);
}.bind(client));
};

View File

@ -1,153 +0,0 @@
import { logger } from "../inc/log";
import { getLevel } from "../inc/admin";
import { spurdo } from "../inc/spurdo";
import { schmuser } from "../inc/schmuser";
import { schwitzer } from "../inc/schwitzer";
import fetch from "flumm-fetch-cookies";
import EventEmitter from "events";
export class tg extends EventEmitter {
constructor(options) {
super();
this.options = options || {};
this.token = options.token || null;
this.options.pollrate = options.pollrate || 1000;
this.set = this.options.set || "all";
this.network = "Telegram";
this.api = `https://api.telegram.org/bot${this.token}`;
this.lastUpdate = 0;
this.lastMessage = 0;
this.server = {
set: this.set,
channel: new Map(),
user: new Map(),
me: {},
spurdo: false,
schmuser: false,
schwitzer: false
};
this.connect().then(() => {
this.poller = setInterval(() => { this.poll(); }, this.options.pollrate);
});
}
connect() {
return new Promise((resolve, reject) => {
fetch(`${this.api}/getMe`)
.then(res => res.json())
.then(res => {
if(res.ok) {
this.me = res.result;
this.server.me = {
nickname: res.result.first_name,
username: res.result.username,
account: res.result.id.toString(),
prefix: `${res.result.username}!${res.result.id.toString()}`,
id: res.result.id.toString()
};
resolve();
}
else {
logger.error(`(${this.network}) ${res}`);
reject();
}
})
.catch(err => {
logger.error(`(${this.network}) ${err.message}`);
reject();
});
});
}
poll() {
fetch(`${this.api}/getUpdates?offset=${this.lastUpdate}&allowed_updates=message`)
.then(res => res.json())
.then(res => {
if(res.ok && res.result.length > 0) {
res = res.result[res.result.length-1];
this.lastUpdate = res.update_id + 1;
if (res.message.date >= ~~(Date.now() / 1000) - 10 && res.message.message_id !== this.lastMessage) {
this.lastMessage = res.message.message_id;
if(!this.server.user.has(res.message.from.username || res.message.from.first_name)) {
this.server.user.set(res.message.from.username || res.message.from.first_name, {
nick: res.message.from.first_name,
username: res.message.from.username,
account: res.message.from.id.toString(),
prefix: `${res.message.from.username}!${res.message.from.id.toString()}`,
id: res.message.from.id
});
}
this.emit("data", ["message", this.reply(res.message)]);
}
}
})
.catch(err => {
if(err.statusCode !== 409)
logger.error(`(${this.network}) ${err.message}`);
});
}
send(chatid, msg, reply = null) {
if(msg.length === 0 || msg.length > 2048)
return false;
const opts = {
method: "POST",
body: {
chat_id: chatid,
text: msg.split("\n").length > 1 ? `<code>${msg}</code>` : msg,
parse_mode: "HTML"
}
};
if(reply)
opts.body.reply_to_message_id = reply;
fetch(`${this.api}/sendMessage`, opts)
.then(res => {})
.catch(err => {
logger.error(`(${this.network}) ${err.message}`);
});
}
sendmsg(mode, recipient, msg) {
this.send(recipient, msg);
}
reply(tmp) {
return {
type: "tg",
network: "Telegram",
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,
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()
})
},
self: this.server,
message: tmp.text,
time: tmp.date,
raw: tmp,
reply: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id),
replyAction: msg => this.send(tmp.chat.id, this.format(`Uwe ${msg}`), tmp.message_id),
replyNotice: msg => this.send(tmp.chat.id, this.format(msg), tmp.message_id),
_user: this.server.user
};
}
format(msg) {
if(this.server.spurdo)
msg = spurdo(msg);
if(this.server.schmuser)
msg = schmuser(msg);
if(this.server.schwitzer)
msg = schwitzer(msg);
return msg.toString()
.split("<").join("&lt;")
.split(">").join("&gt;")
.replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold
.replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2")
;
}
}

View File

@ -1,25 +1,4 @@
import sql from "./sql";
export let admins = [];
export const loadAdmins = () => {
admins = [];
sql.any(`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");
});
};
loadAdmins();
import { default as config } from "../../cfg/config.json";
export const getLevel = (network, user) => {
let ret = {
@ -30,7 +9,7 @@ export const getLevel = (network, user) => {
return "user has to be an object!";
if (!user.account || !user.prefix)
return ret;
for(let admin of admins) {
for(let admin of config.admins) {
if (admin.account === user.account.toLowerCase() && admin.network === network.toLowerCase()) {
ret = {
level: admin.level,
@ -39,4 +18,4 @@ export const getLevel = (network, user) => {
}
};
return ret;
};
};

View File

@ -1,6 +1,8 @@
import { logger } from "../log";
import { read, cfg } from "../cfg";
import { getLevel } from "../../inc/admin";
const parseArgs = (msg) => {
let args = msg.trim().split(" ");
let cmd = args.shift();
@ -35,7 +37,8 @@ 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 > e.user.level.level) {
if (trigger.level > getLevel(e.network, e.user)) {
e.reply(`no permission, min level ${trigger.level} required`);
break;
}

View File

@ -1,18 +0,0 @@
const replacements = [
["blöd", "plöd"], ["nein", "neim"], ["ein", "1"], ["bitte", "bidde"],
["Bitte", "Bidde"], ["ich", "i"], ["Ich", "i"], ["auch", "au"],
["noch", "no"], ["Hallo", "Halo"], ["hallo", "halo"], ["bin", "bims"],
["Bin", "Bims"], ["ist", "is"], ["Ist", "Is"], ["danke", "dangge"],
["Danke", "Dangge"], ["t", "dd"], ["mm", "m"], ["n", "m"],
["mir", "mi"], ["Mir", "Mi"], ["die", "di"], ["Die", "Di"],
["Immer", "Imer"], ["immer", "imer"], ["Hab", "Han"], ["hab", "han"]
];
export function schmuser(text) {
replacements.forEach(filter => {
let replaceFrom = new RegExp(filter[0], 'gm')
, replaceTo = filter[1];
text = text.replace(replaceFrom, replaceTo);
});
return text;
}

View File

@ -1,4 +0,0 @@
export function schwitzer(text) {
text = text.split(" ");
return text.map(word => word.match(/(i|l)$/gm) ? word : `${word}li`).join(" ")
}

View File

@ -1,32 +0,0 @@
const ebinFaces = [
':D', ':DD', ':DDD', ':-D',
'XD', 'XXD', 'XDD', 'XXDD'
];
const replacements = [
['wh', 'w'], ['th', 'd'], ['af', 'ab'], ['ap', 'ab'],
['ca', 'ga'], ['ck', 'gg'], ['co', 'go'], ['ev', 'eb'],
['ex', 'egz'], ['et', 'ed'], ['iv', 'ib'], ['it', 'id'],
['ke', 'ge'], ['nt', 'nd'], ['op', 'ob'], ['ot', 'od'],
['po', 'bo'], ['pe', 'be'], ['pi', 'bi'], ['up', 'ub'],
['va', 'ba'], ['ck', 'gg'], ['cr', 'gr'], ['kn', 'gn'],
['lt', 'ld'], ['mm', 'm'], ['nt', 'dn'], ['pr', 'br'],
['ts', 'dz'], ['tr', 'dr'], ['bs', 'bz'], ['ds', 'dz'],
['es', 'es'], ['fs', 'fz'], ['gs', 'gz'], [' is', ' iz'],
['ls', 'lz'], ['ms', 'mz'], ['ns', 'nz'], ['rs', 'rz'],
['ss', 'sz'], ['ts', 'tz'], ['us', 'uz'], ['ws', 'wz'],
['ys', 'yz'], ['alk', 'olk'], ['ing', 'ign'], ['ic', 'ig'],
['ng', 'nk'], ['kek', 'geg'], ['epic', 'ebin'], ['some', 'sum'],
['meme', 'maymay']
];
export function spurdo(text) {
text = text.toLowerCase();
replacements.forEach(filter => {
let replaceFrom = new RegExp(filter[0], 'gm')
, replaceTo = filter[1];
text = text.replace(replaceFrom, replaceTo);
});
while (text.match(/\.|,(?=\s|$)/m))
text = text.replace(/\.|,(?=\s|$)/m, ' ' + ebinFaces[~~(Math.random() * ebinFaces.length)]);
return text;
}

View File

@ -1,7 +1,7 @@
import PG from "pg-promise";
import { default as cfg } from "../../cfg/sql.json";
import { default as config } from "../../cfg/config.json";
//const pgp = new PG();
const sql = (new PG())(cfg);
const sql = (new PG())(config.sql);
export default sql;

View File

@ -1,5 +1,5 @@
import sql from "../sql";
import { getLevel, loadAdmins } from "../admin";
import { getLevel } from "../admin";
export default bot => {
bot._trigger.set("join", new bot.trigger({

View File

@ -1,6 +1,5 @@
import { admins, getLevel } from "../admin";
import { getLevel } from "../admin";
import fetch from "flumm-fetch-cookies";
import { wrapper, clients } from "../wrapper";
import vm from "vm";
@ -10,10 +9,7 @@ let context = vm.createContext({
bot: null,
admins: null,
fetch: fetch,
console: console,
wrapper: {
wrapper, clients
}
console: console
});
export default bot => {
bot._trigger.set("sandbox_debug", new bot.trigger({
@ -23,7 +19,6 @@ export default bot => {
f: e => {
const args = e.message.trim().substring(7);
try {
context.admins = admins;
context.e = e;
context.bot = bot;
context.level = getLevel;

View File

@ -16,7 +16,6 @@ import rape from "./rape";
import sandbox from "./sandbox";
import soundcloud from "./soundcloud";
import sysinfo from "./sysinfo";
import timer from "./timer1";
import urban from "./urban";
import nxy from "./useless_nxy";
import uwe from "./useless_uwe";
@ -26,5 +25,5 @@ export default [
cfg, chatbot, coins, cookie, core, debug,
drugs, help, irpg, kernel, lastfm, mcmaniac,
pr0gag, quotes, rape, sandbox, soundcloud,
sysinfo, timer, urban, nxy, uwe, wttr
sysinfo, urban, nxy, uwe, wttr
];

View File

@ -1,66 +0,0 @@
import lt from "long-timeout";
import sql from "../../../inc/sql";
import { clients } from "../../wrapper";
export default new class timer {
constructor() {
this.regex = /(\d+)(mon|[smhdwy])/;
this.calc = {
y: val => val * 365 * 24 * 60 * 60, // years
mon: val => val * 30 * 24 * 60 * 60, // months
w: val => val * 7 * 24 * 60 * 60, // weeks
d: val => val * 24 * 60 * 60, // days
h: val => val * 60 * 60, // hours
m: val => val * 60, // minutes
s: val => val // seconds
};
this._timers = new Set();
setTimeout(() => { this.getTimers(); }, 1000);
}
add(time, fn, begin = ~~(Date.now()/1000)) {
return new Promise((resolve, reject) => {
if(!this.regex.test(time))
return reject();
let seconds = 0;
time.match(/\d+(mon|[smhdwy])/g).forEach(t => {
const [,val,mod] = t.match(/(\d+)(mon|[smhdwy])/);
seconds += parseInt(this.calc[mod](val));
});
if(seconds < 1)
return reject();
const rest = seconds - (~~(Date.now() / 1000) - begin);
if(begin < ~~(Date.now() / 1000))
return reject();
lt.setTimeout(() => {
fn();
}, rest * 1000);
this._timers.add(rest);
resolve(rest);
});
}
getTimers() {
sql.any("select * from nxy_timers")
.then(rows => {
if(rows.length === 0)
return;
rows.forEach(r => {
r.target = JSON.parse(r.target);
clients.forEach(client => {
if(client.type.toLowerCase() === r.target.type.toLowerCase()
&& client.client.network.toLowerCase() === r.target.network.toLowerCase())
{
this.add(r.delay, () => {
client.client.sendmsg("normal", r.target.channel, client.client.format(`[b]${r.target.nick}[/b]: ${r.message} [i](${r.delay})[/i]`));
sql.any("delete from nxy_timers where id = $1", [ r.id ])
.then(() => {
client.client.sendmsg("normal", r.target.channel, client.client.format(`timer ${r.id} gelöscht.`));
console.log(`deleted timer ${r.id}`);
})
.catch(err => console.log(err));
}, r.created).catch(err => {});
}
});
});
}).catch(err => console.log(err));
}
}

View File

@ -1,64 +0,0 @@
//import sql from "../../../inc/sql";
import { clients } from "../../wrapper";
export default new class timer {
constructor() {
this.regex = /(\d+)(mon|[smhdwy])/;
this.calc = {
y: 365 * 24 * 60 * 60, // years
mon: 30 * 24 * 60 * 60, // months
w: 7 * 24 * 60 * 60, // weeks
d: 24 * 60 * 60, // days
h: 60 * 60, // hours
m: 60, // minutes
s: 1 // seconds
};
this._timers = new Map();
setInterval(() => { this.loop(); }, 1000);
//setTimeout(() => { this.getTimers(); }, 1000);
}
add(time, fn, now = ~~(Date.now() / 1000)) {
return new Promise((resolve, reject) => {
try {
if(!this.regex.test(time))
return reject("ungültig lol");
let seconds = 0;
time.match(/\d+(mon|[smhdwy])/g).forEach(t => {
const [,val,mod] = t.match(/(\d+)(mon|[smhdwy])/);
seconds += val * this.calc[mod];
});
if(seconds < 1)
return reject("lel ne");
const until = now + seconds;
const rest = until - now;
if(!this._timers.has(until))
this._timers.set(until, []);
this._timers.get(until).push(fn);
resolve({
now: new Date(now * 1000),
rest: rest,
until: new Date((now + rest) * 1000)
});
} catch(err) {
reject(err);
};
});
}
loop() {
this._timers.forEach((val, key) => {
if(key === ~~(Date.now() / 1000)) {
val.forEach(k => {
k.target = JSON.parse(k.target);
clients.forEach(client => {
if(client.type.toLowerCase() === k.target.type.toLowerCase() && client.client.network.toLowerCase() === k.target.network.toLowerCase()) {
client.client.sendmsg("normal", k.target.channel, client.client.format(`[b]${k.target.nick}[/b]: ${k.message} [i](${k.delay})[/i]`));
}
});
this._timers.delete(key);
});
}
});
}
};

View File

@ -1,41 +0,0 @@
import timer from "./lib/timer";
import sql from "../../inc/sql";
export default bot => {
bot._trigger.set("timer", new bot.trigger({
call: /^(\.|\/)timer .*/i,
set: "nxy",
help: {
text: "(WIP) Sets a timer, delay can be: s, m, h, d, w, mon, y",
usage: "[b].timer[/b] [i]<delay>[/i] [i]<message>[/i]..."
},
active: false,
f: e => {
const t = e.args.shift()
, msg = e.args.join(" ");
if(t === "debug" && e.user.level.level >= 100)
return e.reply( JSON.stringify([...timer._timers]) );
timer.add(t, () => {
e.reply(`[b]${e.user.nick}[/b]: ${msg} [i](${t})[/i]`);
}).then(seconds => {
sql.any(
"insert into nxy_timers (mask, target, message, delay, created) values ($1, $2, $3, $4, $5)",
[
e.user.prefix,
JSON.stringify({
nick: e.user.nick,
type: e.type,
network: e.network,
channel: e.channelid
}),
msg,
t,
~~(Date.now() / 1000)
]
);
}).catch(err => { e.reply("error lol"); });
}
}));
};

View File

@ -1,38 +0,0 @@
import timer from "./lib/timer1";
//import sql from "../../inc/sql";
export default bot => {
bot._trigger.set("timer", new bot.trigger({
call: /^(\.|\/)timer .*/i,
set: "nxy",
level: 100,
help: {
text: "(WIP) Sets a timer, delay can be: s, m, h, d, w, mon, y",
usage: "[b].timer[/b] [i]<delay>[/i] [i]<message>[/i]..."
},
active: true,
f: e => {
const t = e.args.shift()
, msg = e.args.join(" ");
if(t === "debug" && e.user.level.level >= 100)
return e.reply( JSON.stringify([...timer._timers.entries()]) );
timer.add(t, {
prefix: e.user.prefix,
target: JSON.stringify({
nick: e.user.nick,
type: e.type,
network: e.network,
channel: e.channelid
}),
message: msg,
delay: t
}).then(tmp => {
//e.reply(JSON.stringify([...timer._timers.entries()]));
}).catch(err => {
e.reply(err);
});
}
}));
};

View File

@ -1,72 +0,0 @@
import { cfg } from "./cfg";
import { irc as irclib } from "../clients/irc";
import { tg as tglib } from "../clients/tg";
//import { discord as discordlib } from "../clients/discord";
import EventEmitter from "events";
const clients = [];
const wrapper = class wrapper extends EventEmitter {
constructor() {
super();
for (let srv in cfg.client) {
if(cfg.client[srv].val.enabled) {
switch (cfg.client[srv].val.type) {
case "irc":
clients.push({
name: cfg.client[srv].val.network,
type: "irc",
client: new irclib(cfg.client[srv].val)
});
break;
case "tg":
clients.push({
name: "tg",
type: "tg",
client: new tglib(cfg.client[srv].val)
});
break;
/*case "discord":
clients.push({
name: "discord",
type: "discord",
client: new discordlib(cfg.client[srv].val)
});
break;*/
}
}
}
clients.forEach(client => {
client.client.on("data", e => {
this.emit(e[0], e[1]);
});
});
}
};
export { wrapper, clients };
Map.prototype.hasi = function(val) {
try {
for (let [key] of this)
if(key.toLowerCase() === val.toLowerCase())
return true;
return false;
} catch(err) {
console.log("das übliche mit tolowercase()");
return false;
}
};
Map.prototype.geti = function(val) {
for (let [key, value] of this)
if(key.toLowerCase() === val.toLowerCase())
return value;
return false;
};
Map.prototype.deli = function(val) {
for (let [key] of this)
if(key.toLowerCase() === val.toLowerCase())
this.delete(key);
};