rewrite trigger system

This commit is contained in:
Flummi 2019-08-19 01:28:01 +00:00
parent 22d79eed18
commit 3a751f2e52
30 changed files with 536 additions and 570 deletions

View File

@ -1,12 +1,12 @@
import logger from "./inc/log"; import logger from "./inc/log";
import _fs from "fs";
import { read, cfg } from "./inc/cfg"; import { read, cfg } from "./inc/cfg";
import { default as config } from "../cfg/config.json"; import { default as config } from "../cfg/config.json";
import triggers from "./inc/trigger";
import events from "./inc/events";
import cuffeo from "cuffeo"; import cuffeo from "cuffeo";
const fs = _fs.promises;
const timeout = 1000;
(async () => { (async () => {
await read(); // read and parse config from database await read(); // read and parse config from database
@ -24,6 +24,35 @@ import cuffeo from "cuffeo";
bot: new cuffeo(config.clients) bot: new cuffeo(config.clients)
}; };
triggers.forEach(mod => mod(self)); console.time("loading");
events.forEach(event => event(self)); const modules = {
events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")),
trigger: (await fs.readdir("./src/inc/trigger")).filter(f => f.endsWith(".mjs"))
};
console.timeLog("loading", "directories");
const blah = (await Promise.all(Object.entries(modules).map(async ([dir, mods]) => ({
[dir]: (await Promise.all(mods.map(async mod => {
const res = await Promise.race([
(await import(`./inc/${dir}/${mod}`)).default(self),
new Promise((_, rej) => setTimeout(() => rej(false), timeout))
]);
console.timeLog("loading", `${dir}/${mod}`);
return res;
}))).flat(2)
})))).reduce((a, b) => ({...a, ...b}));
blah.events.forEach(event => {
console.timeLog("loading", `registering event > ${event.name}`);
self.bot.on(event.listener, event.f);
});
blah.trigger.forEach(trigger => {
console.timeLog("loading", `registering trigger > ${trigger.name}`);
self._trigger.set(trigger.name, new self.trigger(trigger));
});
console.timeEnd("loading");
})(); })();

View File

@ -1,16 +1,21 @@
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]"
]; ];
export default self => { export default async bot => {
self.bot.on("ctcp:version", e => {
e.write(`notice ${e.user.nick} :\u0001VERSION ${versions[~~(Math.random() * versions.length)]}\u0001`);
});
self.bot.on("ctcp:ping", e => { return [{
e.write(`notice ${e.user.nick} :${e.message}`); name: "version",
}); listener: "ctcp:version",
f: e => {
e.write(`notice ${e.user.nick} :\u0001VERSION ${versions[~~(Math.random() * versions.length)]}\u0001`);
}
}, {
name: "ping",
listner: "ctcp:ping",
f: e => {
e.write(`notice ${e.user.nick} :${e.message}`);
}
}];
}; };

View File

@ -1,5 +1,5 @@
import logger from "../log"; import logger from "../log";
import { read, cfg } from "../cfg"; import { cfg } from "../cfg";
import { getLevel } from "../../inc/admin"; import { getLevel } from "../../inc/admin";
@ -12,40 +12,34 @@ const parseArgs = (msg) => {
}; };
}; };
export default self => { export default async bot => {
self.bot.on("message", e => {
for (var [name, trigger] of self._trigger.entries()) {
//if (!e.self.me.nickname) {
// e.reply("nope, still initialising myself :^)");
// break;
//}
if (!trigger.call.exec(e.message))
continue;
if (!trigger.clients.includes(e.type))
continue;
let active = false; return [{
if (e.type === "irc" && cfg.trigger[e.network + e.channel]) { name: "message",
if (cfg.trigger[e.network + e.channel][trigger.name]) listener: "message",
active = true; f: e => {
} const trigger = [...bot._trigger.entries()].filter(t =>
else t[1].call.exec(e.message) &&
active = trigger.active; t[1].clients.includes(e.type) &&
if (!active) t[1].active &&
continue; !(t[1].level > getLevel(e.network, e.user)) &&
!((e.self.set !== "all" && e.self.set !== t[1].set) && t[1].set !== "all")
);
if ((e.self.set !== "all" && e.self.set !== trigger.set) && trigger.set !== "all") trigger.forEach(async t => {
continue; try {
e = { ...e, ...parseArgs(e.message) };
await t[1].f(e);
console.log(`triggered > ${t[0]}`);
}
catch(error) {
e.reply("An error occured.");
logger.error(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${typeof error === "string" ? error : JSON.stringify(error)}`);
}
});
//if (trigger.level > e.user.level.level) { logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
if (trigger.level > getLevel(e.network, e.user)) {
e.reply(`no permission, min level ${trigger.level} required`);
break;
}
e = Object.assign(e, parseArgs(e.message));
trigger.f(e);
} }
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`); }];
});
}; };

View File

@ -0,0 +1,16 @@
import logger from "../log";
const versions = [
"AmIRC.1 (8 Bit) for Commodore Amiga 500",
"HexChat 0.72 [x86] / Windows 95c [500MHz]"
];
export default self => {
self.bot.on("ctcp:version", e => {
e.write(`notice ${e.user.nick} :\u0001VERSION ${versions[~~(Math.random() * versions.length)]}\u0001`);
});
self.bot.on("ctcp:ping", e => {
e.write(`notice ${e.user.nick} :${e.message}`);
});
};

View File

@ -0,0 +1,51 @@
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();
return {
cmd: cmd.replace(/^(\.|\/|\!)/, ""),
args: args
};
};
export default self => {
self.bot.on("message", e => {
for (var [name, trigger] of self._trigger.entries()) {
//if (!e.self.me.nickname) {
// e.reply("nope, still initialising myself :^)");
// break;
//}
if (!trigger.call.exec(e.message))
continue;
if (!trigger.clients.includes(e.type))
continue;
let active = false;
if (e.type === "irc" && cfg.trigger[e.network + e.channel]) {
if (cfg.trigger[e.network + e.channel][trigger.name])
active = true;
}
else
active = trigger.active;
if (!active)
continue;
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;
}
e = Object.assign(e, parseArgs(e.message));
trigger.f(e);
}
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
});
};

View File

@ -7,12 +7,14 @@ const _opts = {
}; };
const _debug = false; const _debug = false;
export default bot => { export default async bot => {
bot._trigger.set("cfg", new bot.trigger({
return [{
name: "cfg",
call: /^\!cfg/i, call: /^\!cfg/i,
active: false, active: false,
level: 100, level: 100,
clients: ["irc", "discord"], clients: ["irc"],
f: e => { f: e => {
let args = e.message.substring(5); let args = e.message.substring(5);
let opts = {}; let opts = {};
@ -91,5 +93,5 @@ export default bot => {
} }
} }
})); }];
}; };

View File

@ -1,7 +1,8 @@
import cleverbot from "./lib/cleverbot"; export default async bot => {
const cleverbot = (await import("./lib/cleverbot")).default;
export default bot => { return [{
bot._trigger.set("chatbot", new bot.trigger({ name: "chatbot",
call: /^(?![!./[])(.*uw(e|i).*)/i, call: /^(?![!./[])(.*uw(e|i).*)/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -12,10 +13,7 @@ export default bot => {
cleverbot.ask(chat) cleverbot.ask(chat)
.then(res => { .then(res => {
e.reply(res.response); e.reply(res.response);
}) }).catch(console.error);
.catch(err => {
console.log(err);
});
} }
})); }]
}; };

View File

@ -16,9 +16,29 @@ const markets = {
xmr: "bitfinex", xmr: "bitfinex",
xrp: "poloniex" xrp: "poloniex"
}; };
const cryptowat_summary = (crypto, market, currency) => new Promise((resolve, reject) => {
if (!Object.keys(currencies).includes(currency) || crypto === currency)
reject(`Can't convert or invalid currency: ${currency}`);
fetch([{ market: market, crypto: crypto, currency: currency }].map(api_url).join``)
.then(res => res.json())
.then(res => {
if (res.length === 0)
reject("No data received");
const data = {
last: [{ val: res.result.price.last }].map(currencies[currency]).join``,
high: [{ val: res.result.price.high }].map(currencies[currency]).join``,
low: [{ val: res.result.price.low }].map(currencies[currency]).join``,
change: (res.result.price.change.percentage * 100).toFixed(2),
volume: res.result.volume
};
resolve(`Current: [b]${data.last}[/b] - High: [b]${data.high}[/b] - Low: [b]${data.low}[/b] - Change: [b]${data.change}[/b]% - Volume: [b]${data.volume}[/b]`);
}).catch(err => reject("lol cryptowatch ist down"));
});
export default bot => { export default async bot => {
bot._trigger.set("coins", new bot.trigger({
return [{
name: "coins",
call: /^(\.|\/)(btc|eth|xmr|xrp)/i, call: /^(\.|\/)(btc|eth|xmr|xrp)/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -31,26 +51,5 @@ export default bot => {
reject => e.reply(reject) reject => e.reply(reject)
); );
} }
})); }];
};
const cryptowat_summary = (crypto, market, currency) => {
return new Promise((resolve, reject) => {
if (!Object.keys(currencies).includes(currency) || crypto === currency)
reject(`Can't convert or invalid currency: ${currency}`);
fetch([{ market: market, crypto: crypto, currency: currency }].map(api_url).join``)
.then(res => res.json())
.then(res => {
if (res.length === 0)
reject("No data received");
const data = {
last: [{ val: res.result.price.last }].map(currencies[currency]).join``,
high: [{ val: res.result.price.high }].map(currencies[currency]).join``,
low: [{ val: res.result.price.low }].map(currencies[currency]).join``,
change: (res.result.price.change.percentage * 100).toFixed(2),
volume: res.result.volume
};
resolve(`Current: [b]${data.last}[/b] - High: [b]${data.high}[/b] - Low: [b]${data.low}[/b] - Change: [b]${data.change}[/b]% - Volume: [b]${data.volume}[/b]`);
}).catch(err => reject("lol cryptowatch ist down"));
});
}; };

View File

@ -8,15 +8,16 @@ const data = {
cookie_beverages: [], cookie_beverages: [],
}; };
Object.keys(data).forEach(cur => { export default async bot => {
sql.any("select data from useless where trigger = $1 limit 1", [cur]) Object.keys(data).forEach(cur => {
.then(rows => { sql.any("select data from useless where trigger = $1 limit 1", [cur])
data[cur] = JSON.parse(rows[0].data); .then(rows => {
}); data[cur] = JSON.parse(rows[0].data);
}); });
});
export default bot => { return [{
bot._trigger.set("cookie", new bot.trigger({ name: "cookie",
call: /^(\.|\/)cookie/i, call: /^(\.|\/)cookie/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -28,5 +29,5 @@ export default bot => {
e.reply(`Here, I'll ${sayMethod} you a ${sayFlavor} ${saySize} ${sayCookie} cookie with a side of ${sayBev}.`); e.reply(`Here, I'll ${sayMethod} you a ${sayFlavor} ${saySize} ${sayCookie} cookie with a side of ${sayBev}.`);
} }
})); }];
}; };

View File

@ -1,8 +1,10 @@
import sql from "../sql"; import sql from "../sql";
import { getLevel } from "../admin"; import { getLevel } from "../admin";
export default bot => { export default async bot => {
bot._trigger.set("join", new bot.trigger({
return [{
name: "join",
call: /^\!join .*/i, call: /^\!join .*/i,
level: 100, level: 100,
clients: ["irc"], clients: ["irc"],
@ -13,9 +15,8 @@ export default bot => {
e.reply(`joined channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`); e.reply(`joined channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
} }
} }
})); }, {
name: "part",
bot._trigger.set("part", new bot.trigger({
call: /^\!part .*/i, call: /^\!part .*/i,
level: 100, level: 100,
clients: ["irc"], clients: ["irc"],
@ -26,9 +27,8 @@ export default bot => {
e.reply(`parted channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`); e.reply(`parted channel${chans.length > 1 ? "s" : ""}: ${chans.join(", ")}`);
} }
} }
})); }, {
name: "nick",
bot._trigger.set("nick", new bot.trigger({
call: /^\!nick .*/i, call: /^\!nick .*/i,
level: 100, level: 100,
clients: ["irc"], clients: ["irc"],
@ -40,9 +40,8 @@ export default bot => {
e.reply(`changed nick to ${e.args[0]}`); e.reply(`changed nick to ${e.args[0]}`);
} }
} }
})); }, {
name: "level",
bot._trigger.set("level", new bot.trigger({
call: /^\!level .*/i, call: /^\!level .*/i,
level: 0, level: 0,
active: false, active: false,
@ -108,5 +107,5 @@ export default bot => {
} }
} }
} }
})); }]
}; };

View File

@ -11,10 +11,13 @@ let context = vm.createContext({
fetch: fetch, fetch: fetch,
console: console console: console
}); });
export default bot => {
bot._trigger.set("sandbox_debug", new bot.trigger({ export default async bot => {
return [{
name: "sandbox_debug",
call: /^\!debug (.*)/i, call: /^\!debug (.*)/i,
active: false, active: true,
level: 100, level: 100,
f: e => { f: e => {
const args = e.message.trim().substring(7); const args = e.message.trim().substring(7);
@ -35,5 +38,5 @@ export default bot => {
e.reply(err.message); e.reply(err.message);
} }
} }
})); }];
}; };

View File

@ -5,15 +5,16 @@ const data = {
dope_strains: {} dope_strains: {}
}; };
Object.keys(data).forEach(cur => { export default async bot => {
sql.any("select data from useless where trigger = $1 limit 1", [cur]) Object.keys(data).forEach(cur => {
.then(rows => { sql.any("select data from useless where trigger = $1 limit 1", [cur])
data[cur] = JSON.parse(rows[0].data); .then(rows => {
}); data[cur] = JSON.parse(rows[0].data);
}); });
});
export default bot => { return [{
bot._trigger.set("dope", new bot.trigger({ name: "dope",
call: /^(\.|\/)dope/i, call: /^(\.|\/)dope/i,
set: "nxy", set: "nxy",
help: { help: {
@ -29,9 +30,8 @@ export default bot => {
, strain = data.dope_strains[strain_type][~~(Math.random() * data.dope_strains[strain_type].length)]; , strain = data.dope_strains[strain_type][~~(Math.random() * data.dope_strains[strain_type].length)];
e.replyAction(`${action[0]} a ${consume_type} of the finest ${strain_type} "${strain}" ${action[1]} [b]${e.args[0] || e.user.nick}[/b]`); e.replyAction(`${action[0]} a ${consume_type} of the finest ${strain_type} "${strain}" ${action[1]} [b]${e.args[0] || e.user.nick}[/b]`);
} }
})); }, {
name: "meth",
bot._trigger.set("meth", new bot.trigger({
call: /^(\.|\/)meth/i, call: /^(\.|\/)meth/i,
set: "nxy", set: "nxy",
help: { help: {
@ -41,5 +41,5 @@ export default bot => {
f: e => { f: e => {
e.replyAction(`legt [b]${e.args[0] || e.user.nick}[/b] eine dicke Line Meth \\________`); e.replyAction(`legt [b]${e.args[0] || e.user.nick}[/b] eine dicke Line Meth \\________`);
} }
})); }];
}; };

View File

@ -1,6 +1,9 @@
export default bot => { export default async bot => {
bot._trigger.set("help", new bot.trigger({
return [{
name: "help",
call: /^(\.|\/)help/i, call: /^(\.|\/)help/i,
active: false,
f: e => { f: e => {
if(e.args[0] && [...bot._trigger.keys()].includes(e.args[0])) { if(e.args[0] && [...bot._trigger.keys()].includes(e.args[0])) {
const help = bot._trigger.get(e.args[0]).help; const help = bot._trigger.get(e.args[0]).help;
@ -15,5 +18,5 @@ export default bot => {
e.reply(`(WIP) available commands: ${triggers.map(blah => `[b]${blah}[/b]`).join(", ")}`); e.reply(`(WIP) available commands: ${triggers.map(blah => `[b]${blah}[/b]`).join(", ")}`);
} }
} }
})); }];
}; };

View File

@ -1,29 +0,0 @@
import cfg from "./cfg";
import chatbot from "./chatbot";
import coins from "./coins";
import cookie from "./cookie";
import core from "./core";
import debug from "./debug";
import drugs from "./drugs";
import help from "./help";
import irpg from "./irpg";
import kernel from "./kernel";
import lastfm from "./lastfm";
import mcmaniac from "./mcmaniac";
import pr0gag from "./pr0gag";
import quotes from "./quotes";
import rape from "./rape";
import sandbox from "./sandbox";
import soundcloud from "./soundcloud";
import sysinfo from "./sysinfo";
import urban from "./urban";
import nxy from "./useless_nxy";
import uwe from "./useless_uwe";
import wttr from "./wttr";
export default [
cfg, chatbot, coins, cookie, core, debug,
drugs, help, irpg, kernel, lastfm, mcmaniac,
pr0gag, quotes, rape, sandbox, soundcloud,
sysinfo, urban, nxy, uwe, wttr
];

View File

@ -1,11 +1,12 @@
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch-cookies";
export default bot => { export default async bot => {
bot._trigger.set("irpg", new bot.trigger({
return [{
name: "irpg",
call: /^\.irpg/i, call: /^\.irpg/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
//process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
fetch("https://f0ck.me/irpg/db.php") fetch("https://f0ck.me/irpg/db.php")
.then(res => res.text()) .then(res => res.text())
.then(res => { .then(res => {
@ -51,5 +52,5 @@ export default bot => {
}) })
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
})); }];
}; };

View File

@ -2,8 +2,10 @@ import fetch from "flumm-fetch-cookies";
const feed = "https://www.kernel.org/releases.json"; const feed = "https://www.kernel.org/releases.json";
export default bot => { export default async bot => {
bot._trigger.set("kernel", new bot.trigger({
return [{
name: "kernel",
call: /^(\.|\/)kernel/i, call: /^(\.|\/)kernel/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -14,5 +16,5 @@ export default bot => {
e.reply(releases.map(entry => `[b]${entry.version}[/b] (${entry.moniker}${entry.iseol ? `, [i]EOL[/i]` : ""})`).join(", ")); e.reply(releases.map(entry => `[b]${entry.version}[/b] (${entry.moniker}${entry.iseol ? `, [i]EOL[/i]` : ""})`).join(", "));
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }];
} };

View File

@ -1,35 +1,43 @@
import { cfg } from "../../inc/cfg"; import { cfg } from "../../inc/cfg";
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch-cookies";
export default bot => { const api = `http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&limit=1&api_key=${cfg.main.lastfm.val.key}&format=json&user=`;
bot._trigger.set("lastfm", new bot.trigger({
export default async bot => {
return [{
name: "lastfm",
call: /^(\.|\/)np/i, call: /^(\.|\/)np/i,
set: "uwe", set: "uwe",
/*help: { /*help: {
text: "", text: "",
usage: "[b].np[/b] [i]<user>[/i]" usage: "[b].np[/b] [i]<user>[/i]"
},*/ },*/
f: e => { f: async e => {
const api = `http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&limit=1&api_key=${cfg.main.lastfm.val.key}&format=json&user=`;
const nick = e.args[0] || e.user.nick; const nick = e.args[0] || e.user.nick;
fetch(`${api}${nick}`)
.then(res => res.json()) let res = await (await fetch(`${api}${nick}`)).json();
.then(res => { if(res.error) return {
if(res.error) err: true,
return e.reply("User not found"); msg: "User not found"
res = res.recenttracks; };
const track = res.track[0];
const info = { res = res.recenttracks;
user: res["@attr"].user, const track = res.track[0];
track: `${track.artist["#text"]} - ${track.name}`, const info = {
playing: track["@attr"] ? true : false user: res["@attr"].user,
}; track: `${track.artist["#text"]} - ${track.name}`,
playing: track["@attr"] ? true : false
if(info.playing) };
e.reply( `[b]${info.user}[/b] is listening to [b]${info.track}[/b]` );
else return {
e.reply( `[b]${info.user}[/b] is not listening to anything. They last listened to [b]${info.track}[/b]` ); err: false,
}).catch(err => console.log(err)); mode: "normal",
msg: info.playing ?
`[b]${info.user}[/b] is listening to [b]${info.track}[/b]` :
`[b]${info.user}[/b] is not listening to anything. They last listened to [b]${info.track}[/b]`
};
} }
})); }];
}; };

View File

@ -1,11 +1,11 @@
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch-cookies";
import { cfg } from "../../../inc/cfg"; import { cfg } from "../../../inc/cfg";
class cleverbot { export default new class cleverbot {
constructor() { constructor() {
this.api = "https://cleverbot.io/1.0"; this.api = "https://cleverbot.io/1.0";
this.nick = ""; this.nick = "";
setTimeout(() => this.init(), 5000); this.init();
} }
init() { init() {
@ -41,5 +41,3 @@ class cleverbot {
}); });
} }
}; };
export default new cleverbot();

View File

@ -12,8 +12,10 @@ let _query_add = `
insert into mcmaniacs (item) values ($1) on conflict do nothing insert into mcmaniacs (item) values ($1) on conflict do nothing
`; `;
export default bot => { export default async bot => {
bot._trigger.set("mcmaniac_add", new bot.trigger({
return [{
name: "mcmaniac_add",
call: /Mc.*iaC/, call: /Mc.*iaC/,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -22,9 +24,8 @@ export default bot => {
.then() .then()
.catch(err => {}); .catch(err => {});
} }
})); }, {
name: "mcmaniac_get",
bot._trigger.set("mcmaniac_get", new bot.trigger({
call: /^(\.|\/)mcmaniac/i, call: /^(\.|\/)mcmaniac/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -59,5 +60,5 @@ export default bot => {
console.log(err); console.log(err);
}); });
} }
})); }];
}; };

View File

@ -33,70 +33,67 @@ const regex = {
return res.json(); return res.json();
}).then(console.log);*/ }).then(console.log);*/
export default bot => { export default async bot => {
bot._trigger.set("pr0gag", new bot.trigger({ await fetch("https://google.de");
return [{
name: "pr0gag",
call: /pr0gramm\.com\/.+\/.+/i, call: /pr0gramm\.com\/.+\/.+/i,
set: "uwe", set: "uwe",
f: async e => { f: async e => {
let reply; let matches, id, link, list;
try { if(matches = e.message.match(regex.direct)) {
let matches, id; const path = matches[1] === "full" && matches[3] === "png"
if(matches = e.message.match(regex.direct)) {
const path = matches[1] === "full" && matches[3] === "png"
? matches[2].slice(0, -3) + "jpg" ? matches[2].slice(0, -3) + "jpg"
: matches[2]; : matches[2];
const response = await (await fetch(apis.reverse + path)).json(); const response = await (await fetch(apis.reverse + path)).json();
if(response.error || !response.items.length) if(response.error || !response.items.length)
throw "reverse lookup error"; throw "reverse lookup error";
id = response.items[0].id; list = response.item[0];
} id = list.id;
else if(matches = e.message.match(regex.normal)) link = "https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id;
id = matches[1];
else
return;
let [list, info] = await Promise.all([
fetch(apis.list + id),
fetch(apis.item + id)
].map(async request => (await request).json()));
list = list.items.filter(item => item.id == id)[0]; // ja, == ist hier ein muss!
if(!list || !info || !Array.isArray(info.tags) || !Array.isArray(info.comments))
throw "item lookup error";
const toptags = info.tags
.sort((a, b) => b.confidence - a.confidence)
.slice(0, 3)
.map(tag => tag.tag)
.join(", ");
const voteRatio = list.up / (list.up + list.down);
const voteRatioColors = [
"red",
"brown",
"orange",
"yellow",
"green",
"lightgreen",
];
const voteRatioColor = voteRatioColors[~~Math.min(voteRatio * voteRatioColors.length, voteRatioColors.length - 1)];
reply = [
"https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id,
`${list.up - list.down} (${color.green(list.up)} / ${color.red(list.down)} = ${color[voteRatioColor]((voteRatio * 100).toFixed(1))}${color.magenta("%")})`,
"user: " + list.user,
"comments: " + info.comments.length,
`toptags: ${toptags} (${flags[list.flags]})`
].join(" - ");
} }
catch(error) { else if(matches = e.message.match(regex.normal)) {
reply = typeof error === "string" ? error : JSON.stringify(error); id = matches[1];
} link = matches[0];
finally { list = (await (await fetch(apis.list + id)).json())
reply && e.reply(reply); .items
.filter(item => item.id == id)[0];
} }
else
return;
let info = await (await fetch(apis.item + id)).json();
if(!info || !Array.isArray(info.tags) || !Array.isArray(info.comments))
throw "item lookup error";
const toptags = info.tags
.sort((a, b) => b.confidence - a.confidence)
.slice(0, 3)
.map(tag => tag.tag)
.join(", ");
const voteRatio = list.up / (list.up + list.down);
const voteRatioColors = [
"red",
"brown",
"orange",
"yellow",
"green",
"lightgreen",
];
const voteRatioColor = voteRatioColors[~~Math.min(voteRatio * voteRatioColors.length, voteRatioColors.length - 1)];
e.reply([
"https://pr0gramm.com/" + (list.promoted ? "top" : "new") + "/" + id,
`${list.up - list.down} (${color.green(list.up)} / ${color.red(list.down)} = ${color[voteRatioColor]((voteRatio * 100).toFixed(1))}${color.magenta("%")})`,
"user: " + list.user,
"comments: " + info.comments.length,
`toptags: ${toptags} (${flags[list.flags]})`
].join(" - "));
} }
})); }];
}; };

View File

@ -23,8 +23,10 @@ insert into nxy_quotes
($1, $2, $3, $4); ($1, $2, $3, $4);
`; `;
export default bot => { export default async bot => {
bot._trigger.set("qrnd", new bot.trigger({
return [{
name: "qrnd",
call: /^(\.|\/)q(rnd)?$/i, call: /^(\.|\/)q(rnd)?$/i,
set: "all", set: "all",
f: e => { f: e => {
@ -35,8 +37,8 @@ export default bot => {
e.reply(`<[b]${quote.nick}[/b]> [i]${quote.item}[/i]`); e.reply(`<[b]${quote.nick}[/b]> [i]${quote.item}[/i]`);
}).catch(console.error); }).catch(console.error);
} }
})); }, {
bot._trigger.set("quotes", new bot.trigger({ name: "quotes",
call: /^(\.|\/)q .*/i, call: /^(\.|\/)q .*/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -118,5 +120,5 @@ export default bot => {
break; break;
} }
} }
})); }];
}; };

View File

@ -1,7 +1,9 @@
import sql from "../sql"; import sql from "../sql";
export default bot => { export default async bot => {
bot._trigger.set("rape", new bot.trigger({
return [{
name: "rape",
call: /^(\.|\/)rape/i, call: /^(\.|\/)rape/i,
set: "nxy", set: "nxy",
help: { help: {
@ -28,9 +30,8 @@ export default bot => {
}); });
} }
} }
})); }, {
name: "owe",
bot._trigger.set("owe", new bot.trigger({
call: /^(\.|\/)owe/i, call: /^(\.|\/)owe/i,
set: "nxy", set: "nxy",
help: { help: {
@ -53,5 +54,5 @@ export default bot => {
return e.reply("user not found"); return e.reply("user not found");
}); });
} }
})); }];
}; };

View File

@ -6,14 +6,14 @@ import fetch from "flumm-fetch-cookies";
import stringify from "stringify-object"; import stringify from "stringify-object";
let _contexts = new Map(); let _contexts = new Map();
setTimeout(() => {
export default async bot => {
sql.any("select prefix, sandbox from nxy_users where sandbox != 'NULL'") sql.any("select prefix, sandbox from nxy_users where sandbox != 'NULL'")
.then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`))) .then(rows => rows.forEach(row => eval(`_contexts.set(row.prefix, ${JSON.parse(row.sandbox)});`)))
.catch(err => console.log("nichts vorhanden lol", err)); .catch(err => console.log("nichts vorhanden lol", err));
}, 5000);
export default bot => { return [{
bot._trigger.set("sandbox_js", new bot.trigger({ name: "sandbox_js",
call: /^(\.|\/)js (.*)/i, call: /^(\.|\/)js (.*)/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -50,9 +50,8 @@ export default bot => {
e.reply(e.user.nick + ": " + err.message.length > maxoutput ? `holy fuck, Error wäre viel zu lang! (${err.message.length} Zeichen :DDDDDD)` : JSON.stringify(err.message)); e.reply(e.user.nick + ": " + err.message.length > maxoutput ? `holy fuck, Error wäre viel zu lang! (${err.message.length} Zeichen :DDDDDD)` : JSON.stringify(err.message));
} }
} }
})); }, {
name: "sandbox",
bot._trigger.set("sandbox", new bot.trigger({
call: /^\!(hs|py|cpp|bf|php|lua|bash) .*/i, call: /^\!(hs|py|cpp|bf|php|lua|bash) .*/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -65,9 +64,8 @@ export default bot => {
reject => e.reply(reject.replace("\n", " ")) reject => e.reply(reject.replace("\n", " "))
); );
} }
})); }, {
name: "sandbox_rs",
bot._trigger.set("sandbox_rs", new bot.trigger({
call: /^\!rs (.*)/i, call: /^\!rs (.*)/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -90,9 +88,8 @@ export default bot => {
e.reply(e.user.nick + ": " + body.success ? (body.stdout.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${body.stdout.length} Zeichen :DDDDDD)` : body.stdout) : "error!"); e.reply(e.user.nick + ": " + body.success ? (body.stdout.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${body.stdout.length} Zeichen :DDDDDD)` : body.stdout) : "error!");
}).catch(err => e.reply(err)); }).catch(err => e.reply(err));
} }
})); }, {
name: "bfgen",
bot._trigger.set("bfgen", new bot.trigger({
call: /^\!bfgen .*/i, call: /^\!bfgen .*/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -100,5 +97,5 @@ export default bot => {
let output = bfgen(args); let output = bfgen(args);
e.reply(e.user.nick + ": " + output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output); e.reply(e.user.nick + ": " + output.length > maxoutput ? `holy fuck, Ausgabe wäre viel zu lang! (${output.length} Zeichen :DDDDDD)` : output);
} }
})); }];
}; };

View File

@ -1,8 +1,10 @@
import fetch from "flumm-fetch-cookies"; import fetch from "flumm-fetch-cookies";
import { cfg } from "../../inc/cfg"; import { cfg } from "../../inc/cfg";
export default bot => { export default async bot => {
bot._trigger.set("scrnd", new bot.trigger({
return [{
name: "scrnd",
call: /^(\.|\/)scrnd/i, call: /^(\.|\/)scrnd/i,
set: "uwe", set: "uwe",
help: { help: {
@ -17,5 +19,5 @@ export default bot => {
e.reply(`${track.permalink_url}\n[b]${track.title}[/b] - length [b]${track.duration}[/b] - [b]${track.user.username}[/b] on [b]${track.created_at}[/b]`); e.reply(`${track.permalink_url}\n[b]${track.title}[/b] - length [b]${track.duration}[/b] - [b]${track.user.username}[/b] on [b]${track.created_at}[/b]`);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }];
}; };

View File

@ -1,7 +1,9 @@
import cp from "child_process"; import cp from "child_process";
export default bot => { export default async bot => {
bot._trigger.set("sysinfo", new bot.trigger({
return [{
name: "sysinfo",
call: /^(\.|\/)sysinfo/i, call: /^(\.|\/)sysinfo/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -9,5 +11,5 @@ export default bot => {
e.reply(stdout); e.reply(stdout);
}); });
} }
})); }];
}; };

View File

@ -2,8 +2,10 @@ import fetch from "flumm-fetch-cookies";
const url = "https://api.urbandictionary.com/v0/define" const url = "https://api.urbandictionary.com/v0/define"
export default bot => { export default async bot => {
bot._trigger.set("urbandict", new bot.trigger({
return [{
name: "urbandict",
call: /^(\.|\/)ud .*/i, call: /^(\.|\/)ud .*/i,
set: "nxy", set: "nxy",
help: { help: {
@ -27,5 +29,5 @@ export default bot => {
e.reply(`[${index}/${data.list.length}] [b]${res.word}[/b]: ${res.definition.replace(/\r\n/g, "")} - ${res.example.replace(/\r\n/g, "")}`); e.reply(`[${index}/${data.list.length}] [b]${res.word}[/b]: ${res.definition.replace(/\r\n/g, "")} - ${res.example.replace(/\r\n/g, "")}`);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }];
}; };

View File

@ -10,18 +10,14 @@ const data = {
slap: [] slap: []
}; };
Object.keys(data).forEach(cur => { export default async bot => {
sql.any("select data from useless where trigger = $1 limit 1", [cur])
.then(rows => {
data[cur] = JSON.parse(rows[0].data);
})
.catch(err => {
console.log(err);
});
});
export default bot => { Object.keys(data).forEach(cur => sql.any("select data from useless where trigger = $1 limit 1", [cur])
bot._trigger.set("kiss", new bot.trigger({ .then(rows => data[cur] = JSON.parse(rows[0].data))
.catch(console.error));
return [{
name: "kiss",
call: /^(\.|\/)kiss/i, call: /^(\.|\/)kiss/i,
set: "nxy", set: "nxy",
help: { help: {
@ -31,9 +27,8 @@ export default bot => {
f: e => { f: e => {
e.reply(`(づ。◕‿‿◕。)づ" [color=red]。。・゜゜・。。・゜❤[/color] [b]${e.args[0] || e.user.nick}[/b] [color=red]❤[/color]`); e.reply(`(づ。◕‿‿◕。)づ" [color=red]。。・゜゜・。。・゜❤[/color] [b]${e.args[0] || e.user.nick}[/b] [color=red]❤[/color]`);
} }
})); }, {
name: "hug",
bot._trigger.set("hug", new bot.trigger({
call: /^(\.|\/)hug/i, call: /^(\.|\/)hug/i,
set: "nxy", set: "nxy",
help: { help: {
@ -43,9 +38,8 @@ export default bot => {
f: e => { f: e => {
e.reply(`[color=red]♥♡❤♡♥[/color] [b]${e.args[0] || e.user.nick}[/b] [color=red]♥♡❤♡♥[/color]`); e.reply(`[color=red]♥♡❤♡♥[/color] [b]${e.args[0] || e.user.nick}[/b] [color=red]♥♡❤♡♥[/color]`);
} }
})); }, {
name: "kill",
bot._trigger.set("kill", new bot.trigger({
call: /^(\.|\/)kill/i, call: /^(\.|\/)kill/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -62,9 +56,8 @@ export default bot => {
.replace("{bomb}", data.kill_parts.bomb[~~(Math.random() * data.kill_parts.bomb.length)]) .replace("{bomb}", data.kill_parts.bomb[~~(Math.random() * data.kill_parts.bomb.length)])
); );
} }
})); }, {
name: "yiff",
bot._trigger.set("yiff", new bot.trigger({
call: /^(\.|\/)yiff/i, call: /^(\.|\/)yiff/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -75,58 +68,51 @@ export default bot => {
.split("{channel}").join(`${e.channel}`) .split("{channel}").join(`${e.channel}`)
); );
} }
})); }, {
name: "bier",
bot._trigger.set("bier", new bot.trigger({
call: /^(\.|\/)bier/i, call: /^(\.|\/)bier/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.replyAction(`schenkt ein kühles Blondes an [b]${e.args[0] || e.user.nick}[/b] aus.`); e.replyAction(`schenkt ein kühles Blondes an [b]${e.args[0] || e.user.nick}[/b] aus.`);
} }
})); }, {
name: "fucken",
bot._trigger.set("fucken", new bot.trigger({
call: /^(\.|\/)fucken/i, call: /^(\.|\/)fucken/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
const user = e.args[0] || e.user.nick; const user = e.args[0] || e.user.nick;
e.replyAction(`fuckt [b]${user}[/b] und tötet [b]${user}[/b] anschließend.`); e.replyAction(`fuckt [b]${user}[/b] und tötet [b]${user}[/b] anschließend.`);
} }
})); }, {
name: "hack",
bot._trigger.set("hack", new bot.trigger({
call: /^(\.|\/)hack/i, call: /^(\.|\/)hack/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply(`hacking ${e.args[0] || e.user.nick}...`); e.reply(`hacking ${e.args[0] || e.user.nick}...`);
} }
})); }, {
name: "spit",
bot._trigger.set("spit", new bot.trigger({
call: /^(\.|\/)spit/i, call: /^(\.|\/)spit/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.replyAction(`spits on [b]${e.args[0] || e.user.nick}[/b] like a dirty whore.`); e.replyAction(`spits on [b]${e.args[0] || e.user.nick}[/b] like a dirty whore.`);
} }
})); }, {
name: "assume",
bot._trigger.set("assume", new bot.trigger({
call: /^(\.|\/)assume/i, call: /^(\.|\/)assume/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply(`Assuming [b]${e.args[0] || e.user.nick}'s[/b] gender... it's a ${data.genders[~~(Math.random() * data.genders.length)]}.`); e.reply(`Assuming [b]${e.args[0] || e.user.nick}'s[/b] gender... it's a ${data.genders[~~(Math.random() * data.genders.length)]}.`);
} }
})); }, {
name: "jn",
bot._trigger.set("jn", new bot.trigger({
call: /^(\.|\/)jn/i, call: /^(\.|\/)jn/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply(`${e.user.nick}: [b]${~~(Math.random() * 2) ? "Ja" : "Nein"}[/b]`); e.reply(`${e.user.nick}: [b]${~~(Math.random() * 2) ? "Ja" : "Nein"}[/b]`);
} }
})); }, {
name: "chosse",
bot._trigger.set("choose", new bot.trigger({
call: /^(\.|\/)choose .*/i, call: /^(\.|\/)choose .*/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -135,34 +121,30 @@ export default bot => {
return e.reply(`${e.user.nick}: Ob du behindert bist?`); return e.reply(`${e.user.nick}: Ob du behindert bist?`);
e.reply(`${e.user.nick}: ${args[~~(Math.random() * args.length)].trim()}`); e.reply(`${e.user.nick}: ${args[~~(Math.random() * args.length)].trim()}`);
} }
})); }, {
name: "huehuehue",
bot._trigger.set("huehuehue", new bot.trigger({
call: /^huehuehue$/i, call: /^huehuehue$/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply("huehuehue"); e.reply("huehuehue");
} }
})); }, {
name: "woah",
bot._trigger.set("woah", new bot.trigger({
call: /woah/i, call: /woah/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
if (~~(Math.random() * 4)) if (~~(Math.random() * 4))
e.reply(data.woahs[~~(Math.random() * data.woahs.length)]); e.reply(data.woahs[~~(Math.random() * data.woahs.length)]);
} }
})); }, {
name: "REEE",
bot._trigger.set("REEE", new bot.trigger({
call: /reee+$/i, call: /reee+$/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply("R".padEnd(~~(Math.random() * 20 + 10), "E")); e.reply("R".padEnd(~~(Math.random() * 20 + 10), "E"));
} }
})); }, {
name: "meme",
bot._trigger.set("meme", new bot.trigger({
call: /^(\.|\/)meme .*/i, call: /^(\.|\/)meme .*/i,
set: "nxy", set: "nxy",
active: false, active: false,
@ -172,9 +154,8 @@ export default bot => {
return e.reply("[WIP] too few arguments: .meme [meme] / [line 1] / [line 2]"); return e.reply("[WIP] too few arguments: .meme [meme] / [line 1] / [line 2]");
} }
})); }, {
name: "slap",
bot._trigger.set("slap", new bot.trigger({
call: /^(\.|\/)slap/i, call: /^(\.|\/)slap/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -182,18 +163,16 @@ export default bot => {
.replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`) .replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`)
); );
} }
})); }, {
name: "fw",
bot._trigger.set("fw", new bot.trigger({
call: /^(\.|\/)fw .*/i, call: /^(\.|\/)fw .*/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
const args = e.message.substring(4).trim(); const args = e.message.substring(4).trim();
e.reply([...args.toUpperCase()].map(c => c === ' ' ? ' ' : String.fromCharCode(65248 + c.charCodeAt(0))).join``); e.reply([...args.toUpperCase()].map(c => c === ' ' ? ' ' : String.fromCharCode(65248 + c.charCodeAt(0))).join``);
} }
})); }, {
name: "waifu_husbando",
bot._trigger.set("waifu_husbando", new bot.trigger({
call: /^(\.|\/)(waifu|husbando)/i, call: /^(\.|\/)(waifu|husbando)/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -224,17 +203,15 @@ export default bot => {
.catch(err => console.log(err)); .catch(err => console.log(err));
} }
} }
})); }, {
name: "asshole",
bot._trigger.set("asshole", new bot.trigger({
call: /^(\.|\/)asshole/i, call: /^(\.|\/)asshole/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.reply(`Jamba Arschlochscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% ein Arschloch.`); e.reply(`Jamba Arschlochscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% ein Arschloch.`);
} }
})); }, {
name: "isup",
bot._trigger.set("isup", new bot.trigger({
call: /^(\.|\/)isup .*/i, call: /^(\.|\/)isup .*/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
@ -247,13 +224,12 @@ export default bot => {
e.reply(`[b]${addr}[/b] seems to be [b]down[/b].`); e.reply(`[b]${addr}[/b] seems to be [b]down[/b].`);
}); });
} }
})); }, {
name: "einschlaefern",
bot._trigger.set("einschlaefern", new bot.trigger({
call: /^(\.|\/)einschläfern/i, call: /^(\.|\/)einschläfern/i,
set: "nxy", set: "nxy",
f: e => { f: e => {
e.replyAction(`schläfert [b]${e.args[0] || e.user.nick}[/b] mit einer Spritze Ketamin ein.`); e.replyAction(`schläfert [b]${e.args[0] || e.user.nick}[/b] mit einer Spritze Ketamin ein.`);
} }
})); }];
}; };

View File

@ -12,334 +12,250 @@ const data = {
quotes_boll: [] quotes_boll: []
}; };
Object.keys(data).forEach(cur => { export default async bot => {
sql.any("select data from useless where trigger = $1 limit 1", [cur])
.then(rows => {
data[cur] = JSON.parse(rows[0].data);
});
});
export default bot => { Object.keys(data).forEach(cur => sql.any("select data from useless where trigger = $1 limit 1", [cur])
bot._trigger.set("abschieben", new bot.trigger({ .then(rows => data[cur] = JSON.parse(rows[0].data))
.catch(console.error));
return [{
name: "abschieben",
call: /^(\.|\/)abschieben/i, call: /^(\.|\/)abschieben/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`schiebt [b]${e.args[0] || e.user.nick}[/b] ${data.abschieben[~~(Math.random() * data.abschieben.length)]} ab.`); e.replyAction(`schiebt [b]${e.args[0] || e.user.nick}[/b] ${data.abschieben[~~(Math.random() * data.abschieben.length)]} ab.`);
} }
})); }, {
name: "butterkäse",
bot._trigger.set("butterkaese", new bot.trigger({
call: /^(\.|\/)butterkäse/i, call: /^(\.|\/)butterkäse/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`drischt mit einem großen Stück Butterkäse auf [b]${e.args[0] || e.user.nick}[/b] ein.`); e.replyAction(`drischt mit einem großen Stück Butterkäse auf [b]${e.args[0] || e.user.nick}[/b] ein.`);
} }
})); }, {
name: "notschlachten",
bot._trigger.set("notschlachten", new bot.trigger({
call: /^(\.|\/)notschlachten/i, call: /^(\.|\/)notschlachten/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`notschlachtet [b]${e.args[0] || e.user.nick}[/b] und entsorgt die Leiche im Biomüll`); e.replyAction(`notschlachtet [b]${e.args[0] || e.user.nick}[/b] und entsorgt die Leiche im Biomüll`);
} }
})); }, {
name: "lachs",
bot._trigger.set("lachs", new bot.trigger({
call: /^(\.|\/)lachs/i, call: /^(\.|\/)lachs/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("öhöhöhöhöhöhö"); e.reply("öhöhöhöhöhöhö");
} }
})); }, {
name: "kaffee",
bot._trigger.set("kaffee", new bot.trigger({
call: /^(\.|\/)kaffee/i, call: /^(\.|\/)kaffee/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(data.kaffee[~~(Math.random() * data.kaffee.length)] e.replyAction(data.kaffee[~~(Math.random() * data.kaffee.length)].replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`));
.replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`)
);
} }
})); }, {
name: "milch",
bot._trigger.set("milch", new bot.trigger({
call: /^(\.|\/)milch/i, call: /^(\.|\/)milch/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(data.milch[~~(Math.random() * data.milch.length)] e.replyAction(data.milch[~~(Math.random() * data.milch.length)].replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`));
.replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`)
);
} }
})); }, {
name: "milchkaffee",
bot._trigger.set("milchkaffee", new bot.trigger({
call: /^(\.|\/)milchkaffee/i, call: /^(\.|\/)milchkaffee/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`serviert [b]${e.args[0] || e.user.nick}[/b] einen heißen halbschwarzen Kaffee mit 99% Kondensmilchanteil.`); e.replyAction(`serviert [b]${e.args[0] || e.user.nick}[/b] einen heißen halbschwarzen Kaffee mit 99% Kondensmilchanteil.`);
} }
})); }, {
name: "tee",
bot._trigger.set("oh", new bot.trigger({
call: /^doch$/i,
set: "uwe",
f: e => {
if(e.user.nick === "nxy")
e.reply("oh!");
}
}));
bot._trigger.set("tee", new bot.trigger({
call: /^(\.|\/)tee/i, call: /^(\.|\/)tee/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(data.tee[~~(Math.random() * data.tee.length)] e.replyAction(data.tee[~~(Math.random() * data.tee.length)].replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`));
.replace("{user}", `[b]${e.args[0] || e.user.nick}[/b]`)
);
} }
})); }, {
name: "uwe_quotes",
bot._trigger.set("uwe_quotes", new bot.trigger({
call: /^(\.|\/)(boll|firecooler|kinski|stoll)$/i, call: /^(\.|\/)(boll|firecooler|kinski|stoll)$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(data[`quotes_${e.cmd}`][~~(Math.random() * data[`quotes_${e.cmd}`].length)]); e.reply(data[`quotes_${e.cmd}`][~~(Math.random() * data[`quotes_${e.cmd}`].length)]);
} }
})); }, {
name:"wusel",
bot._trigger.set("wusel", new bot.trigger({
call: /^(\.|\/)wusel/i, call: /^(\.|\/)wusel/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`wuselt [b]${e.args[0] || e.user.nick}[/b] über den Haufen.`); e.replyAction(`wuselt [b]${e.args[0] || e.user.nick}[/b] über den Haufen.`);
} }
})); }, {
name: "mett",
bot._trigger.set("mett", new bot.trigger({
call: /^(\.|\/)mett/i, call: /^(\.|\/)mett/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(`Jamba Mettscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% Mett.`); e.reply(`Jamba Mettscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% Mett.`);
} }
})); }, {
name: "unfaehig",
bot._trigger.set("unfaehig", new bot.trigger({
call: /^(\.|\/)unfähig/i, call: /^(\.|\/)unfähig/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(`Jamba Fähigkeitenscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% unfähig.`); e.reply(`Jamba Fähigkeitenscanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% unfähig.`);
} }
})); }, {
name: "rotenburg",
bot._trigger.set("rotenburg", new bot.trigger({
call: /^(\.|\/)rotenburg/i, call: /^(\.|\/)rotenburg/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`verarbeitet [b]${e.args[0] || e.user.nick}[/b] zu Hackfleisch.`); e.replyAction(`verarbeitet [b]${e.args[0] || e.user.nick}[/b] zu Hackfleisch.`);
} }
})); }, {
name: "pee",
bot._trigger.set("pee", new bot.trigger({
call: /^(\.|\/)pee/i, call: /^(\.|\/)pee/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`pisst in [b]${e.args[0] || e.user.nick}[/b]s Gesicht.`); e.replyAction(`pisst in [b]${e.args[0] || e.user.nick}[/b]s Gesicht.`);
} }
})); }, {
name: "ike",
bot._trigger.set("ike", new bot.trigger({
call: /^ike/i, call: /^ike/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("ike ike!"); e.reply("ike ike!");
} }
})); }, {
name: "rip",
bot._trigger.set("rip", new bot.trigger({
call: /^rip/i, call: /^rip/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("Rust in Pitabrot"); e.reply("Rust in Pitabrot");
} }
})); }, {
name: "haram",
bot._trigger.set("haram", new bot.trigger({
call: /^(\.|\/)haram/i, call: /^(\.|\/)haram/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(`[b]${e.args[0] || e.user.nick}[/b] ist ${(~~(Math.random() * 2) ? "haram" : "nicht haram")}.`); e.reply(`[b]${e.args[0] || e.user.nick}[/b] ist ${(~~(Math.random() * 2) ? "haram" : "nicht haram")}.`);
} }
})); }, {
name: "sacklutscher",
bot._trigger.set("sacklutscher", new bot.trigger({
call: /^(\.|\/)lutschsack/i, call: /^(\.|\/)lutschsack/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(`[b]${e.user.nick}[/b] legt Rosen aus und lutscht den Sack von [b]${e.args[0] || e.user.nick}[/b]`); e.reply(`[b]${e.user.nick}[/b] legt Rosen aus und lutscht den Sack von [b]${e.args[0] || e.user.nick}[/b]`);
} }
})); }, {
name: "kawaii",
bot._trigger.set("kawaii", new bot.trigger({
call: /kawaii/i, call: /kawaii/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("⌒(oo) so much kawaii"); e.reply("⌒(oo) so much kawaii");
} }
})); }, {
name: "hurrdurr",
bot._trigger.set("hurrdurr", new bot.trigger({
call: /^hurr$/i, call: /^hurr$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("durr"); e.reply("durr");
} }
})); }, {
name: "herpderp",
bot._trigger.set("fraguwe", new bot.trigger({ call: /^herp$/i,
call: /^uwe.*\?$/i,
set: "uwe", set: "uwe",
active: false,
f: e => { f: e => {
e.reply("fuck you"); e.reply("derp");
} }
})); }, {
name: "wasser",
bot._trigger.set("wasser", new bot.trigger({
call: /^(\.|\/)wasser/i, call: /^(\.|\/)wasser/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`kippt [b]${e.args[0] || e.user.nick}[/b] einen Eimer Wasser über den Kopf.`); e.replyAction(`kippt [b]${e.args[0] || e.user.nick}[/b] einen Eimer Wasser über den Kopf.`);
} }
})); }, {
name: "normie",
bot._trigger.set("normie", new bot.trigger({
call: /^(\.|\/)normie/i, call: /^(\.|\/)normie/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply(`Jamba Normiescanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% ein Normie.`); e.reply(`Jamba Normiescanner: [b]${e.args[0] || e.user.nick}[/b] ist zu ${~~(Math.random() * 100 + 1)}% ein Normie.`);
} }
})); }, {
name: "hyper",
bot._trigger.set("hyper", new bot.trigger({
call: /^(\.|\/)hyper$/i, call: /^(\.|\/)hyper$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("[b]GET HYPER![/b]"); e.reply("[b]GET HYPER![/b]");
} }
})); }, {
name: "bark",
bot._trigger.set("bark", new bot.trigger({
call: /^(\.|\/)bark$/i, call: /^(\.|\/)bark$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("BARK BARK BARK"); e.reply("BARK BARK BARK");
} }
})); }, {
name: "meditieren",
bot._trigger.set("meditieren", new bot.trigger({
call: /^(\.|\/)meditieren/i, call: /^(\.|\/)meditieren/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`meditiert zusammen mit [b]${e.args[0] || e.user.nick}[/b] Metta.`); e.replyAction(`meditiert zusammen mit [b]${e.args[0] || e.user.nick}[/b] Metta.`);
} }
})); }, {
name: "duden",
bot._trigger.set("duden", new bot.trigger({
call: /^(\.|\/)duden/i, call: /^(\.|\/)duden/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`drischt mit einem großen Duden auf [b]${e.args[0] || e.user.nick}[/b] ein.`); e.replyAction(`drischt mit einem großen Duden auf [b]${e.args[0] || e.user.nick}[/b] ein.`);
} }
})); }, {
name: "kscht",
bot._trigger.set("kscht", new bot.trigger({
call: /^(\.|\/)kscht/i, call: /^(\.|\/)kscht/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`jagt [b]${e.args[0] || e.user.nick}[/b] durch den Raum.`); e.replyAction(`jagt [b]${e.args[0] || e.user.nick}[/b] durch den Raum.`);
} }
})); }, {
name: "bullenpisse",
bot._trigger.set("bullenpisse", new bot.trigger({
call: /^(\.|\/)bullenpisse/i, call: /^(\.|\/)bullenpisse/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`zapft ein Fläschchen feinsten Bullenurin, verarbeitet diesen zu Red-Bull und serviert ihn [b]${e.args[0] || e.user.nick}[/b] in Form einer Pfanddose.`); e.replyAction(`zapft ein Fläschchen feinsten Bullenurin, verarbeitet diesen zu Red-Bull und serviert ihn [b]${e.args[0] || e.user.nick}[/b] in Form einer Pfanddose.`);
} }
})); }, {
name: "lungenkrebs",
bot._trigger.set("lungenkrebs", new bot.trigger({
call: /^(\.|\/)lungenkrebs/i, call: /^(\.|\/)lungenkrebs/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`dreht [b]${e.args[0] || e.user.nick}[/b] einen prall gefüllten Sargnagel mit feinstem Schwarzer Krauser.`); e.replyAction(`dreht [b]${e.args[0] || e.user.nick}[/b] einen prall gefüllten Sargnagel mit feinstem Schwarzer Krauser.`);
} }
})); }, {
name: "blah",
bot._trigger.set("blah", new bot.trigger({
call: /^[A-ZÄÖÜẞ](?: [A-ZÄÖÜẞ]){1,5}$/, call: /^[A-ZÄÖÜẞ](?: [A-ZÄÖÜẞ]){1,5}$/,
set: "uwe", set: "uwe",
clients: ["irc"], clients: ["irc"],
f: e => { f: e => {
let args = e.message.trim(); let args = e.message.trim();
if (args.toUpperCase() === args) if (args.toUpperCase() === args) e.reply(args.substring(2).split(" ").join("\n"));
args.substring(2).split(" ").forEach(e.reply);
} }
})); }, {
name: "rose",
bot._trigger.set("rose", new bot.trigger({
call: /^(\.|\/)rose/i, call: /^(\.|\/)rose/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`schenkt [b]${e.args[0] || e.user.nick}[/b] eine [color=red]~~{~[@}[/color]`); e.replyAction(`schenkt [b]${e.args[0] || e.user.nick}[/b] eine [color=red]~~{~[@}[/color]`);
} }
})); }, {
name: "wienerle",
bot._trigger.set("wienerle", new bot.trigger({
call: /^(\.|\/)wienerle/i, call: /^(\.|\/)wienerle/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`serviert [b]${e.args[0] || e.user.nick}[/b] ein kaltes Wienerle mit etwas Wurstwasser.`); e.replyAction(`serviert [b]${e.args[0] || e.user.nick}[/b] ein kaltes Wienerle mit etwas Wurstwasser.`);
} }
})); }, {
name: "joke",
bot._trigger.set("witz", new bot.trigger({
call: /^(\.|\/)witz$/i,
set: "uwe",
f: e => {
fetch("http://www.funny4you.at/webmasterprogramm/zufallswitz.php?id=312")
.then(res => res.text())
.then(res => {
res = res
.split("<br />").join("")
.split("<div class=\"funny4you\">").join("")
.split("&amp;").join("&")
.split("&auml;").join("ä")
.split("&ouml;").join("ö")
.split("&uuml;").join("ü")
.split("&Auml;").join("Ä")
.split("&Ouml;").join("Ö")
.split("&Uuml;").join("Ü")
.split("&szlig;").join("ß")
.split("&quot;").join("\"")
.replace(/\<span.*/i, "");
if(e.network !== "Telegram") {
res
.match(/.{1,450}/g)
.map(e.reply);
}
else
e.reply(res);
}).catch(err => console.log(err));
}
}));
bot._trigger.set("joke", new bot.trigger({
call: /^(\.|\/)joke$/i, call: /^(\.|\/)joke$/i,
set: "uwe", set: "uwe",
f: e => { f: e => { ///
fetch("https://icanhazdadjoke.com/slack") fetch("https://icanhazdadjoke.com/slack")
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
@ -353,9 +269,8 @@ export default bot => {
e.reply(res); e.reply(res);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }, { ///
name: "version",
bot._trigger.set("test", new bot.trigger({
call: /^\.version/i, call: /^\.version/i,
set: "uwe", set: "uwe",
clients: ["irc"], clients: ["irc"],
@ -374,17 +289,15 @@ export default bot => {
}); });
e.write(`privmsg ${e.args[0] || e.user.nick} :\u0001VERSION\u0001`); e.write(`privmsg ${e.args[0] || e.user.nick} :\u0001VERSION\u0001`);
} }
})); }, {
name: "mock",
bot._trigger.set("mock", new bot.trigger({
call: /^\.mock .*/i, call: /^\.mock .*/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply([...e.args.join(" ")].map(l => (l === " ") ? " " : (Math.round(Math.random()) === 0) ? l.toUpperCase() : l.toLowerCase()).join``); e.reply([...e.args.join(" ")].map(l => (l === " ") ? " " : (Math.round(Math.random()) === 0) ? l.toUpperCase() : l.toLowerCase()).join``);
} }
})); }, { ///
name: "sync",
bot._trigger.set("sync", new bot.trigger({
call: /^\.sync.*/i, call: /^\.sync.*/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
@ -398,62 +311,55 @@ export default bot => {
e.reply(`${data.name} @ https://sync.f0ck.space/r/${data.name} : ${data.user} Users, now playing: ${decodeURIComponent(data.title)}`); e.reply(`${data.name} @ https://sync.f0ck.space/r/${data.name} : ${data.user} Users, now playing: ${decodeURIComponent(data.title)}`);
}).catch(err => e.reply("Channel nicht gefunden D:")); }).catch(err => e.reply("Channel nicht gefunden D:"));
} }
})); }, {
name: "blech",
bot._trigger.set("blech", new bot.trigger({
call: /^(\.|\/)blech/i, call: /^(\.|\/)blech/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`bereitet [b]${e.args[0] || e.user.nick}[/b] ein Blech Schore zu. Viel Vergnügen du Siffscheiße.`); e.replyAction(`bereitet [b]${e.args[0] || e.user.nick}[/b] ein Blech Schore zu. Viel Vergnügen du Siffscheiße.`);
} }
})); }, {
name: "joghurt",
bot._trigger.set("joghurt", new bot.trigger({
call: /^(\.|\/)joghurt/i, call: /^(\.|\/)joghurt/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`spritzt [b]${e.args[0] || e.user.nick}[/b] 500ml Joghurt in den Arsch.`); e.replyAction(`spritzt [b]${e.args[0] || e.user.nick}[/b] 500ml Joghurt in den Arsch.`);
} }
})); }, {
name: "kelly",
bot._trigger.set("kelly", new bot.trigger({
call: /^(\.|\/)kelly/i, call: /^(\.|\/)kelly/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`dreht [b]${e.args[0] || e.user.nick}[/b]'s dreckige Kelly Family Musik leiser und spuckt [b]${e.args[0] || e.user.nick}[/b] ins Gesicht.`); e.replyAction(`dreht [b]${e.args[0] || e.user.nick}[/b]'s dreckige Kelly Family Musik leiser und spuckt [b]${e.args[0] || e.user.nick}[/b] ins Gesicht.`);
} }
})); }, {
name: "pflaumen",
bot._trigger.set("pflaumen", new bot.trigger({
call: /^(\.|\/)pflaumen/i, call: /^(\.|\/)pflaumen/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`sieht, wie [b]${e.args[0] || e.user.nick}[/b] Pflaumen aus dem Arsch fallen.`); e.replyAction(`sieht, wie [b]${e.args[0] || e.user.nick}[/b] Pflaumen aus dem Arsch fallen.`);
} }
})); }, {
name: "quark",
bot._trigger.set("quark", new bot.trigger({
call: /^(\.|\/)quark/i, call: /^(\.|\/)quark/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.replyAction(`schiebt [b]${e.args[0] || e.user.nick}[/b] 500g dickflüssigen Quark in den soften Arsch.`); e.replyAction(`schiebt [b]${e.args[0] || e.user.nick}[/b] 500g dickflüssigen Quark in den soften Arsch.`);
} }
})); }, {
name: "shrug",
bot._trigger.set("shrug", new bot.trigger({
call: /^so what$/i, call: /^so what$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("¯\\_(ツ)_/¯"); e.reply("¯\\_(ツ)_/¯");
} }
})); }, {
name: "wiedergeburt",
bot._trigger.set("wiedergeburt", new bot.trigger({ call: /^(\.|\/)wiedergeburt$/i,
call: /^(\.|\/)wiedergeburtt$/i,
set: "uwe", set: "uwe",
f: e => { f: e => {
e.reply("spielt Wiedergeburt aus, legt nxy vom Friedhof in die Monsterzone und beendet seinen Zug."); e.reply("spielt Wiedergeburt aus, legt nxy vom Friedhof in die Monsterzone und beendet seinen Zug.");
} }
})); }];
}; };

View File

@ -2,8 +2,10 @@ import fetch from "flumm-fetch-cookies";
import { cfg } from "../../inc/cfg"; import { cfg } from "../../inc/cfg";
import { conds } from "./lib/wttr"; import { conds } from "./lib/wttr";
export default bot => { export default async bot => {
bot._trigger.set("wttr", new bot.trigger({
return [{
name: "wttr",
call: /^\.wttr .*/i, call: /^\.wttr .*/i,
set: "uwe", set: "uwe",
help: { help: {
@ -62,9 +64,8 @@ export default bot => {
[body[0], body[2], body[3], body[4], body[5], body[6]].map(e.reply); [body[0], body[2], body[3], body[4], body[5], body[6]].map(e.reply);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }, {
name: "wttrnew",
bot._trigger.set("wttrnew", new bot.trigger({
call: /^(\.|\/)w .*/i, call: /^(\.|\/)w .*/i,
set: "all", set: "all",
help: { help: {
@ -109,10 +110,9 @@ export default bot => {
e.reply(`Wetterbericht für: ${res.name}, ${res.sys.country}\n${[...Array(5)].map((_, i) => `${icon[i].padEnd(15)} ${data[i]}`).join("\n")}`); e.reply(`Wetterbericht für: ${res.name}, ${res.sys.country}\n${[...Array(5)].map((_, i) => `${icon[i].padEnd(15)} ${data[i]}`).join("\n")}`);
}).catch(err => console.log(err)); }).catch(err => console.log(err));
} }
})); }, {
name: "weather",
bot._trigger.set("weather", new bot.trigger({
call: /^(\.|\/)weather .*/i, call: /^(\.|\/)weather .*/i,
set: "all", set: "all",
help: { help: {
@ -146,5 +146,5 @@ export default bot => {
} }
}).catch(err => e.reply(err)); }).catch(err => e.reply(err));
} }
})); }];
}; };