From e341a2d52fa8d5e68687d05add9e879c5ef3dd0c Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 14 Aug 2016 04:06:01 +0200 Subject: [PATCH] modified: src/main.js --- src/main.js | 55 ++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/src/main.js b/src/main.js index 7c82b80..29b273c 100644 --- a/src/main.js +++ b/src/main.js @@ -50,10 +50,10 @@ bot.on('message', (e) => { tmp.forEach((entry,i,a) => { dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item if(cb.status === true) { - var tmp = getUser(e.user.getNick(), e.network); + var tmpuser = getUser(e.user.getNick(), e.network); setTimeout(()=>{ - sql.query("insert into `f0ck`.`items` values (?,?,?,?,?,?,?)",url, "./b/"+path.parse(entry).base,tmp['username'],e.channel.getName(),new Date().getTime(),0); - e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")"); + 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 @@ -80,21 +80,23 @@ var dl = (url, dest, cb) => { var request = (url.match(/^https/)?https:http).get(url, (response) => { try { if(allowed.indexOf(response.headers['content-type']) != -1) { - if(checkRepost(url)) { - response.pipe(file); - file.on('finish', () => { - file.close(); - cb({'status':true, 'msg':'downloaded '+dest}); - }); - file.on('error', (err) => { - fs.unlink(dest); - file.close(); - cb({'status':false, 'msg':err.message}); - }); - } - else { - cb({'status':false, 'msg':'repost motherf0cker'}); - } + checkRepost(url, (cbcr) => { + if(cbcr) { + response.pipe(file); + file.on('finish', () => { + file.close(); + cb({'status':true, 'msg':'downloaded '+dest}); + }); + file.on('error', (err) => { + fs.unlink(dest); + file.close(); + cb({'status':false, 'msg':err.message}); + }); + } + else { + cb({'status':false, 'msg':'repost motherf0cker'}); + } + }); } else { cb({'status':false, 'msg':'f0ck you'}); @@ -106,16 +108,9 @@ var dl = (url, dest, cb) => { }); }; -var checkRepost = (url) => { - var result = false; - sql.query( - "select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => { - result = (rows[0].count == 0)?true:false; - console.log("1: "+result); - } - ); - var start = Date.now(); - while(Date.now() < start + 1000) {} - console.log("2: "+result); - return result; +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); + }); }; \ No newline at end of file