diff --git a/src/main.js b/src/main.js index d771822..3ef4cf2 100644 --- a/src/main.js +++ b/src/main.js @@ -7,18 +7,6 @@ var bot = require('coffea')(); var uuid = require('uuid'); const path = require('path'); -var allowed = [ - 'image/png', - 'video/webm', - 'image/gif', - 'image/jpeg', - 'video/mp4', - 'audio/mpeg3', - 'audio/x-mpeg-3', - 'audio/mpeg' -]; -var maxFileSize = 10485760; // 10 mb - var sql; var haDC = () => { sql = mysql.createConnection(cfg.mysql); @@ -56,29 +44,27 @@ bot.on('message', (e) => { 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) => { - var tmpdest = uuid.v1().split('-')[0]+path.parse(entry).ext; + var tmpdest = uuid.v1().split('-')[0]; dl(entry, "./b/"+tmpdest, (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/"+tmpdest, + "./b/"+tmpdest+"."+cb.infos.ext, tmpuser['nick'], e.channel.getName(), e.network, Math.floor(new Date() / 1000), 0 ]).on('result', (result) => { - e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); }).on('error', (msg) => { e.reply(msg); }); } - else { + else if(cb.type == 1) e.reply(cb.msg); - } }); }); } @@ -86,7 +72,7 @@ bot.on('message', (e) => { var tmp = getUser(e.user.getNick(), e.network); setTimeout(()=>{ e.reply(tmp); }, 1500); } - else if(orig.match(/^\.del/) && e.channel.getName().toString() == "#f0ck") { + else if(orig.match(/^\.del/) && e.channel.getName() == "#f0ck") { sql.query("truncate table `f0ck`.`items`") .on('end', () => { e.reply("database truncated"); @@ -94,10 +80,6 @@ bot.on('message', (e) => { e.reply(msg); }); } - else if(orig.match(/^\.uuid/)) { - var tmp = uuid.v1().split('-')[0]; - e.reply(tmp); - } }); var getUser = (u, n) => { @@ -109,15 +91,16 @@ var getUser = (u, n) => { var dl = (url, dest, cb) => { 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) { + if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) { + console.log(cfg.allowedMimes[response.headers['content-type']]); + if(response.headers['content-length'] <= cfg.maxFileSize) { checkRepost(url, (cbcr) => { if(cbcr) { - var file = fs.createWriteStream(dest); + var file = fs.createWriteStream(dest+"."+cfg.allowedMimes[response.headers['content-type']]); 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']}}); + cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length'], 'ext':cfg.allowedMimes[response.headers['content-type']]}}); }); file.on('error', (err) => { fs.unlink(dest); @@ -125,18 +108,15 @@ var dl = (url, dest, cb) => { cb({'status':false, 'msg':err.message, 'type':1}); }); } - else { + 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}); - } + else + cb({'status':false, 'msg':'f0ck! your file is too big (~'+formatSize(response.headers['content-length'])+'), max '+formatSize(cfg.maxFileSize)+' allowed', 'type':1}); } - else { + else cb({'status':false, 'msg':'f0ck you', 'type':2}); - } }).on('error', (msg) => { cb({'status':false, 'msg':msg, 'type':2}); });