modified: src/main.js

This commit is contained in:
Flummi 2016-08-14 16:54:37 +02:00
parent 93653c5e53
commit 97bf115120

View File

@ -66,7 +66,7 @@ bot.on('message', (e) => {
tmpuser['nick'], tmpuser['nick'],
e.channel.getName(), e.channel.getName(),
e.network, e.network,
new Date().getTime(), Math.floor(new Date() / 1000),
0 0
]).on('result', (result) => { ]).on('result', (result) => {
@ -108,41 +108,37 @@ var getUser = (u, n) => {
}; };
var dl = (url, dest, cb) => { var dl = (url, dest, cb) => {
var request = (url.match(/^https/)?https:http).get(url, (response) => { var request = (url.match(/^https/)?https:http).get(url, (response) => { // type:1=post,type:2=stfu
try { // type:1=post,type:2=stfu if(allowed.indexOf(response.headers['content-type']) != -1) {
console.log(response.headers['content-type']); if(response.headers['content-length'] <= maxFileSize) {
if(allowed.indexOf(response.headers['content-type']) != -1) { checkRepost(url, (cbcr) => {
if(response.headers['content-length'] <= maxFileSize) { if(cbcr) {
checkRepost(url, (cbcr) => { var file = fs.createWriteStream(dest);
if(cbcr) { response.pipe(file);
var file = fs.createWriteStream(dest); file.on('finish', () => {
response.pipe(file); file.close();
file.on('finish', () => { cb({'status':true, 'msg':'downloaded '+dest, 'type':1, 'infos':{'mime':response.headers['content-type'], 'size':response.headers['content-length']}});
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.on('error', (err) => { file.close();
fs.unlink(dest); cb({'status':false, 'msg':err.message, 'type':1});
file.close(); });
cb({'status':false, 'msg':err.message, 'type':1}); }
}); else {
} cb({'status':false, 'msg':'repost motherf0cker', '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});
}
} }
else { 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) { else {
e.reply(ex); cb({'status':false, 'msg':'f0ck you', 'type':2});
} }
}).on('error', (msg) => {
cb({'status':false, 'msg':msg, 'type':2});
}); });
}; };