diff --git a/src/main.js b/src/main.js index 47086da..5eb6576 100644 --- a/src/main.js +++ b/src/main.js @@ -6,6 +6,10 @@ var mysql = require('mysql'); var bot = require('coffea')(); const path = require('path'); +var allowed = [ + 'image/png', 'video/webm' +]; + cfg.server.forEach((e,i,a) => { bot.add({ "name": e.name, @@ -33,13 +37,20 @@ bot.on('message', (e) => { 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 - e.reply(cb); + if(cb.status === true) { + var tmp = getUser(e.user.getNick(), e.network); + setTimeout(()=>{ + e.reply(cb.msg+" for "+tmp['nick']+" ("+tmp['username']+"@"+tmp['hostname']+")"); + }, 1600); + } + 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); }, 2000); + setTimeout(()=>{ e.reply(tmp); }, 1500); } } }); @@ -56,19 +67,24 @@ var dl = (url, dest, cb) => { var file = fs.createWriteStream(dest); var request = (url.match(/^https/)?https:http).get(url, (response) => { try { - response.pipe(file); - file.on('finish', () => { - file.close(); - cb('downloaded '+dest); - }); - file.on('error', (err) => { - fs.unlink(dest); - file.close(); - cb(err.message); - }); + if(allowed.indexOf(response.headers['content-type']) != -1) { + 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':'f0ck you'}); + } } catch(ex) { e.reply(ex); } }); -} \ No newline at end of file +}; \ No newline at end of file