From 88039bbe053cb418a2ce275f901865f7f57c0f56 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 20 Nov 2017 19:43:17 +0100 Subject: [PATCH] . --- src/bot.js | 4 -- src/inc/events/message.js | 94 --------------------------------------- src/inc/events/sync.js | 9 ---- src/inc/events/whois.js | 11 ----- src/inc/trigger/parser.js | 36 +++++++++++++++ 5 files changed, 36 insertions(+), 118 deletions(-) delete mode 100644 src/inc/events/message.js delete mode 100644 src/inc/events/sync.js delete mode 100644 src/inc/events/whois.js create mode 100644 src/inc/trigger/parser.js diff --git a/src/bot.js b/src/bot.js index c67a63e..2f20ef6 100644 --- a/src/bot.js +++ b/src/bot.js @@ -7,10 +7,6 @@ read().then(() => { let bot = new wrapper(); const self = { - logger: logger, - cfg: cfg, - wrapper: wrapper, - clients: clients, _trigger: new Map() }; diff --git a/src/inc/events/message.js b/src/inc/events/message.js deleted file mode 100644 index b43e8a4..0000000 --- a/src/inc/events/message.js +++ /dev/null @@ -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 ); - }); -} \ No newline at end of file diff --git a/src/inc/events/sync.js b/src/inc/events/sync.js deleted file mode 100644 index 5befc02..0000000 --- a/src/inc/events/sync.js +++ /dev/null @@ -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; - } - }); -}; \ No newline at end of file diff --git a/src/inc/events/whois.js b/src/inc/events/whois.js deleted file mode 100644 index c5d4849..0000000 --- a/src/inc/events/whois.js +++ /dev/null @@ -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); - } - }); -}; \ No newline at end of file diff --git a/src/inc/trigger/parser.js b/src/inc/trigger/parser.js new file mode 100644 index 0000000..29efdbf --- /dev/null +++ b/src/inc/trigger/parser.js @@ -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); + }); +} \ No newline at end of file