From 059b713555061e778831fdaec245faefb852bc3d Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 14 Aug 2016 14:06:18 +0200 Subject: [PATCH] modified: src/main.js --- src/main.js | 58 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/main.js b/src/main.js index 29b273c..6731e71 100644 --- a/src/main.js +++ b/src/main.js @@ -44,34 +44,49 @@ bot.on('motd', (e) => { bot.on('message', (e) => { var orig = e.message; - if(e.channel.getName().toString() == "#f0ck") { // (debug) only in channel #f0ck - if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher - var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links - tmp.forEach((entry,i,a) => { - dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item - if(cb.status === true) { - var tmpuser = getUser(e.user.getNick(), e.network); - setTimeout(()=>{ - sql.query("insert into `f0ck`.`items` values (?,?,?,?,?,?,?)",tmp, "./b/"+path.parse(entry).base,tmpuser['username'],e.channel.getName(),new Date().getTime(),0); - e.reply(cb.msg+" for "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); - }, 1600); - } - else - e.reply(cb.msg); - }); + if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher + var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links + tmp.forEach((entry,i,a) => { + dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item + if(cb.status === true) { + var tmpuser = getUser(e.user.getNick(), e.network); + sql.query("insert into `f0ck`.`items` (`src`,`dest`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?)", [ + entry, + "./b/"+path.parse(entry).base, + tmpuser['nick'], + e.channel.getName(), + e.network, + new Date().getTime(), + 0 + ]).on('end', () => { + e.reply(cb.msg+" for "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); + }).on('error', (msg) => { + e.reply(msg); + }); + } + else + e.reply(cb.msg); + }); + }); + } + else if(orig.match(/^\.user/)) { // (debug) get userinfos + var tmp = getUser(e.user.getNick(), e.network); + setTimeout(()=>{ e.reply(tmp); }, 1500); + } + else if(orig.match(/^\.del/) && e.channel.getName().toString() == "#f0ck") { + sql.query("truncate table `f0ck`.`items`") + .on('end', () => { + e.reply("database truncated"); + }).on('error', (msg) => { + e.reply(msg); }); - } - else if(orig.match(/^\.user/)) { // (debug) get userinfos - var tmp = getUser(e.user.getNick(), e.network); - setTimeout(()=>{ e.reply(tmp); }, 1500); - } } }); var getUser = (u, n) => { bot.whois(u, n, (fn)=>{ }); // send whois var start = Date.now(); - while(Date.now() < start + 2000) {} // block script for catch whois + while(Date.now() < start + 1000) {} // block script for catch whois return bot.getUser(u, n); }; @@ -109,7 +124,6 @@ var dl = (url, dest, cb) => { }; var checkRepost = (url, cbcr) => { - console.log(url); sql.query("select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => { cbcr((rows[0].count == 0)?true:false); });