Uwev2/src/bot.js

32 lines
980 B
JavaScript
Raw Normal View History

2017-11-07 17:22:41 +00:00
import { cfg, read } from './inc/cfg.js';
2017-11-08 21:29:43 +00:00
import { wrapper, clients } from './inc/wrapper.js';
2017-11-09 11:21:40 +00:00
const safeEval = require('safe-eval');
2017-11-07 17:22:41 +00:00
read().then(() => {
2017-11-08 11:56:04 +00:00
let bot = new wrapper();
2017-11-08 18:43:08 +00:00
bot.on('message', e => {
2017-11-08 21:29:43 +00:00
//if(e.type === "tg")
// clients[0].client.send(`PRIVMSG #kbot-dev ${e.user.nick}: ${e.message}`);
2017-11-09 11:21:40 +00:00
if(e.type === "irc") {
if (e.message.match(/^\.js /)) { // JS-Sandbox
let args = e.message.substring(3);
var context = {
e: e
}
try {
var output = safeEval(args, context);
if (typeof output !== undefined && output !== 'undefined' && output) {
let blah = JSON.stringify(output);
if (blah != "Converting circular structure to JSON")
e.reply(blah.length > 250 ? `holy fuck, Ausgabe wäre viel zu lang! (${blah.length} Zeichen :DDDDDD)` : blah);
}
}
catch (err) {
e.reply(err.message);
}
}
}
2017-11-08 11:56:04 +00:00
});
2017-11-08 21:29:43 +00:00
2017-11-08 18:43:08 +00:00
});