This commit is contained in:
Flummi 2016-09-09 07:51:10 +00:00
parent ab4d1355c8
commit a37ad20d08
2 changed files with 64 additions and 76 deletions

View File

@ -79,52 +79,6 @@ Lib.prototype.getCheckSum = (file, cbcs) => {
cbcs(sha256sum.digest('hex'));
});
};
Lib.prototype.dl = (url, dest, cb) => {
(url.match(/^https/)?https:http).get(url, (response) => { // type:1=post,type:2=stfu
console.log(response.headers['content-type']);
if(cfg.allowedMimes.hasOwnProperty(response.headers['content-type'])) {
if(response.headers['content-length'] <= cfg.maxFileSize) {
Lib.prototype.checkRepost(url, (cbcr) => {
if(cbcr === true) {
var file = fs.createWriteStream(dest+"."+cfg.allowedMimes[response.headers['content-type']]);
response.pipe(file);
file.on('finish', () => {
file.close();
var mime = Mime.lookup(dest+"."+cfg.allowedMimes[response.headers['content-type']]);
if(cfg.allowedMimes.hasOwnProperty(mime)) {
probe(dest+"."+cfg.allowedMimes[response.headers['content-type']], (err, probeData) => {
if(probeData.streams[0].height !== undefined || probeData.streams[0].width !== undefined) {
if(probeData.streams[0].height + probeData.streams[0].width <= cfg.minRes)
cb({'status':false, 'msg':'f0ck! your shitpost is too small', 'type':1});
else
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']]}});
}
else
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']]}});
});
}
else
cb({'status':false, 'msg':'lol, go f0ck yourself', 'type':1});
});
file.on('error', (err) => {
fs.unlink(dest+"."+cfg.allowedMimes[response.headers['content-type']]);
file.close();
cb({'status':false, 'msg':err.message, 'type':1});
});
}
else
cb({'status':false, 'msg':'repost motherf0cker: https://f0ck.me/'+cbcr, 'type':1});
});
}
else
cb({'status':false, 'msg':'f0ck! your file is too big (~'+Lib.prototype.formatSize(response.headers['content-length'])+'), max '+Lib.prototype.formatSize(cfg.maxFileSize)+' allowed', 'type':1});
}
else
cb({'status':false, 'msg':'f0ck you', 'type':2});
}).on('error', (msg) => {
cb({'status':false, 'msg':msg, 'type':2});
});
};
Lib.prototype.generateThumbs = () => {
var outdir = './t/';
sql.query("select * from `f0ck`.`items`", (err, rows, fields) => {

View File

@ -1,6 +1,10 @@
var fs = require('fs-extra');
var uuid = require('uuid');
var path = require('path');
var cloudscraper = require('cloudscraper');
var Mime = require('mime');
var probe = require('node-ffprobe');
var cfg = require('../../cfg/main.json');
module.exports = (bot, trigger, lib) => {
trigger.add({
@ -15,41 +19,71 @@ module.exports = (bot, trigger, lib) => {
tmp.forEach((entry,i,a) => {
var tmpdest = uuid.v1().split('-')[0];
if(!entry.match(/f0ck\.me/i)) {
lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item
if(cb.status === true) {
bot.whois(e.user.getNick(), e.network, (err, cbgu) => {
lib.getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs === true) {
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
entry,
"./b/"+tmpdest+"."+cb.infos.ext,
cb.infos.mime,
cb.infos.size,
cbcs,
cbgu['nick'],
e.channel.getName(),
e.network,
Math.floor(new Date() / 1000),
0
]).on('result', (result) => {
lib.generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+lib.formatSize(cb.infos.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
}).on('error', (msg) => {
e.reply(msg);
lib.checkRepost(entry, (cbcr) => {
if(cbcr === true) {
cloudscraper.request({
method: 'GET',
url: entry,
encoding: null,
},
(error, res, data) => {
if(error)
console.log('Error occurred');
else {
var type = res.headers['content-type'];
var length = res.headers['content-length'];
var dest = './b/'+tmpdest+'.'+cfg.allowedMimes[type];
if(cfg.allowedMimes.hasOwnProperty(type)) {
if(length <= cfg.maxFileSize) {
fs.writeFile(dest, data, (err) => {
if(!err) {
lib.getCheckSum(dest, (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs === true) {
var mime = Mime.lookup(dest);
if(cfg.allowedMimes.hasOwnProperty(mime)) {
bot.whois(e.user.getNick(), e.network, (err, cbgu) => {
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
entry,
dest,
mime,
length,
cbcs,
cbgu['nick'],
e.channel.getName(),
e.network,
Math.floor(new Date() / 1000),
0
]).on('result', (result) => {
lib.generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+mime+", ~"+lib.formatSize(length)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
}).on('error', (msg) => {
e.reply(msg);
});
});
}
else
e.reply('lol, go f0ck yourself');
}
else
e.reply("repost motherf0cker: https://f0ck.me/"+cbcrcs);
});
});
}
else
e.reply(err);
});
}
else {
fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost
e.reply("repost motherf0cker: https://f0ck.me/"+cbcrcs);
}
});
});
else
e.reply('f0ck! your file is too big (~'+lib.formatSize(length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed');
}
else
e.reply('lol, go f0ck yourself');
}
});
}
else
if(cb.type == 1)
e.reply(cb.msg);
e.reply('repost motherf0cker: https://f0ck.me/'+cbcr);
});
}
});