This commit is contained in:
Flummi 2017-11-20 19:43:17 +01:00
parent 0d3d5f7c8a
commit 88039bbe05
5 changed files with 36 additions and 118 deletions

View File

@ -7,10 +7,6 @@ read().then(() => {
let bot = new wrapper();
const self = {
logger: logger,
cfg: cfg,
wrapper: wrapper,
clients: clients,
_trigger: new Map()
};

View File

@ -1,94 +0,0 @@
const safeEval = require('safe-eval');
const util = require('util');
const fs = require('fs');
const ytdl = util.promisify(require('youtube-dl').getInfo);
require('irc-colors').global();
module.exports = (lib) => {
lib.events.on('message', function(msg) {
if( msg.event[1] === 'privmsg' ) { // Triggerauswertung und blah
//lib.rpc.emit('call', 'rizon', 'privmsg', [ '#f0ck', JSON.stringify(msg) ]);
var e = lib.reply(msg);
switch(e.message) {
case "1":
e.reply("normal");
break;
case "2":
e.replyAction("action");
break;
case "3":
e.replyNotice("notice");
break;
case "4":
e.reply("Debugzeugs (lib.interfaces.rpc.sock) in die Konsole pfostiert.");
console.log(lib.interfaces.rpc.sock);
break;
case "6":
e.reply("\x02!kick kbotv3\x02");
break;
case "5":
e.reply("!kick kbotv3");
break;
case "whois":
lib.rpc.emit('call', e.network, 'raw', [ 'whois', e.user.nick ]);
e.reply(`whois an ${e.user.nick} ist raus!`);
break;
default:
if(e.user.nick === "Flummi" || e.user.nick === "jkhsjdhjs" || e.user.nick === "pFT" || e.user.nick === "mrhanky" || e.user.nick === "gz") {
if(e.message.match(/^\.js /)) { // JS-Sandbox
let args = e.message.substring(3);
var context = {
e: e,
msg: msg,
setInterval: setInterval,
clearInterval: clearInterval
}
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);
}
}
else if(e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // parser
let links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
const args = [
//"-j",
//"-q",
"--no-progress",
"--no-warnings",
"--no-check-certificate",
"--max-filesize 500m",
'-o "./tmp/%(title)s.%(ext)s"'
];
Promise.all( links.map( link => checkRepost( link ) ) ) // repostcheck
.then( res => Promise.all( res.map( link => ytdl(link) ) ) ) // get informations
.then( res => {
res.forEach( data => {
e.reply( data.title );
});
});
}
}
break;
}
}
if( msg.event === 'metadata' )
console.log(msg);
});
};
function checkRepost(link) {
return new Promise((resolve, reject) => {
resolve( link );
});
}

View File

@ -1,9 +0,0 @@
module.exports = (lib) => {
lib.events.on('message', function(msg) {
if( msg.event == 'synchronize' ) {
if( msg.keys.length == 0 )
setTimeout(lib.loadIRC, 500);
return;
}
});
};

View File

@ -1,11 +0,0 @@
module.exports = (lib) => {
lib.events.on('message', function(msg) {
if( msg.event[1] === 'whois' || (msg.event[1] === 'unknown' && msg.message.command === 'RPL_WHOISNICKSERVREG') ) {
console.log(msg);
}
if( msg.event[1] === 'who' ) {
console.log(msg.message.who);
}
});
};

36
src/inc/trigger/parser.js Normal file
View File

@ -0,0 +1,36 @@
const util = require('util')
, fs = require('fs')
, ytdl = util.promisify(require('youtube-dl').getInfo);
const args = [
"--no-progress",
"--no-warnings",
"--no-check-certificate",
"--max-filesize 500m",
'-o "./tmp/%(title)s.%(ext)s"'
];
module.exports = bot => {
bot._trigger.set("parser", {
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
level: 0,
active: true,
clients: ["irc"],
f: e => {
const links = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi);
Promise.all(links.map(link => checkRepost(link))) // repostcheck
.then(res => Promise.all(res.map(link => ytdl(link)))) // get informations
.then(res => {
res.forEach(data => {
e.reply(data.title);
});
});
}
});
};
function checkRepost(link) {
return new Promise((resolve, reject) => {
resolve(link);
});
}