From 97bf1151200886c86aee5fb2eec911aec471e0ed Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 14 Aug 2016 16:54:37 +0200 Subject: [PATCH] modified: src/main.js --- src/main.js | 58 +++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/main.js b/src/main.js index 67be452..d771822 100644 --- a/src/main.js +++ b/src/main.js @@ -66,7 +66,7 @@ bot.on('message', (e) => { tmpuser['nick'], e.channel.getName(), e.network, - new Date().getTime(), + Math.floor(new Date() / 1000), 0 ]).on('result', (result) => { @@ -108,41 +108,37 @@ var getUser = (u, n) => { }; var dl = (url, dest, cb) => { - var request = (url.match(/^https/)?https:http).get(url, (response) => { - try { // type:1=post,type:2=stfu - console.log(response.headers['content-type']); - if(allowed.indexOf(response.headers['content-type']) != -1) { - if(response.headers['content-length'] <= maxFileSize) { - checkRepost(url, (cbcr) => { - if(cbcr) { - var file = fs.createWriteStream(dest); - response.pipe(file); - file.on('finish', () => { - file.close(); - cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length']}}); - }); - file.on('error', (err) => { - fs.unlink(dest); - file.close(); - cb({'status':false, 'msg':err.message, 'type':1}); - }); - } - else { - cb({'status':false, 'msg':'repost motherf0cker', 'type':1}); - } - }); - } - else { - cb({'status':false, 'msg':'f0ck! your file is too big (~'+formatSize(response.headers['content-length'])+'), max '+formatSize(maxFileSize)+' allowed', 'type':1}); - } + var request = (url.match(/^https/)?https:http).get(url, (response) => { // type:1=post,type:2=stfu + if(allowed.indexOf(response.headers['content-type']) != -1) { + if(response.headers['content-length'] <= maxFileSize) { + checkRepost(url, (cbcr) => { + if(cbcr) { + var file = fs.createWriteStream(dest); + response.pipe(file); + file.on('finish', () => { + file.close(); + cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length']}}); + }); + file.on('error', (err) => { + fs.unlink(dest); + file.close(); + cb({'status':false, 'msg':err.message, 'type':1}); + }); + } + else { + cb({'status':false, 'msg':'repost motherf0cker', 'type':1}); + } + }); } else { - cb({'status':false, 'msg':'f0ck you', 'type':2}); + cb({'status':false, 'msg':'f0ck! your file is too big (~'+formatSize(response.headers['content-length'])+'), max '+formatSize(maxFileSize)+' allowed', 'type':1}); } } - catch(ex) { - e.reply(ex); + else { + cb({'status':false, 'msg':'f0ck you', 'type':2}); } + }).on('error', (msg) => { + cb({'status':false, 'msg':msg, 'type':2}); }); };