Merge branch 'f0ckdev' into 'master'

fixed some bugs in parser



See merge request !17
This commit is contained in:
Flummi 2016-11-02 17:27:23 +00:00
commit 52e41d7ba1
2 changed files with 45 additions and 44 deletions

2
bot.js
View File

@ -26,7 +26,7 @@ var child = new (forever.Monitor)(__dirname+'/src/main.js', {
silent: false,
cwd: __dirname,
args: [],
spinSleepTime: 2000,
spinSleepTime: 5000,
watch: true,
watchIgnoreDotFiles: true,
watchIgnorePatterns: [

View File

@ -48,9 +48,14 @@ module.exports = (lib) => {
}
});
}
else
if(cb.msg != '')
else {
fs.stat('./b/' + cb.file, (err, stat) => {
if(cb.msg !== '')
e.reply(cb.msg);
if(!err && stat.isFile())
fs.unlinkSync('./b/' + cb.file);
});
}
});
}
});
@ -64,8 +69,8 @@ module.exports = (lib) => {
var yt = /https?:\/\/(www\.)?youtu(\.be\/|be\.com\/)((.+\/)?(watch(\?v=|.+&v=))?(v=)?)([\w_-]{11})(&.+)?/gi;
var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi;
lib.checkRepost(url, (cbcr) => {
if(cbcr === true) {
var tmpdest = uuid.v1().split('-')[0];
if(cbcr === true) {
var dat = fs.createWriteStream('./b/' + tmpdest);
var info;
@ -79,9 +84,8 @@ module.exports = (lib) => {
.on('response', (res) => {
if(res.headers['content-length'] > cfg.maxFileSize) {
res.destroy();
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
}
else {
info = {
@ -94,16 +98,14 @@ module.exports = (lib) => {
}
})
.on('error', (err) => {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: ex });
dat.end();
cb({ success: false, file: tmpdest, msg: err.message });
})
.pipe(dat);
}
catch(ex) {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: ex });
dat.end();
cb({ success: false, file: tmpdest, msg: ex.message });
}
}
});
@ -123,9 +125,8 @@ module.exports = (lib) => {
};
}
else {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: 'f0ck sc-api' });
dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' });
}
});
}
@ -141,7 +142,6 @@ module.exports = (lib) => {
lib.log('MimeType: '+type);
var length = res.headers['content-length'];
if(cfg.allowedMimes.hasOwnProperty(type)) {
//if(length <= cfg.maxFileSize) {
if(data.length <= cfg.maxFileSize) {
var s = new Readable
s.push(data);
@ -156,21 +156,18 @@ module.exports = (lib) => {
};
}
else {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
}
}
else {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: '' });
dat.end();
cb({ success: false, file: tmpdest, msg: '' });
}
}
else {
dat.close();
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: err });
dat.end();
cb({ success: false, file: tmpdest, msg: err });
}
});
}
@ -178,10 +175,13 @@ module.exports = (lib) => {
dat
.on('finish', () => {
var size = dat.bytesWritten;
dat.close();
dat.end();
if(size > cfg.maxFileSize)
cb({ success: false, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
else {
fs.stat('./b/' + tmpdest, (err, stat) => {
if(!err && stat.isFile() && stat.size > 300) {
lib.log('Datei '+tmpdest+' existiert');
lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs === true) {
@ -189,21 +189,22 @@ module.exports = (lib) => {
if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
else
cb({ success: false, msg: 'lol, go f0ck yourself ('+mime+')' });
cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime+')' });
}
else
cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
});
});
}
});
}
})
.on('error', (err) => {
fs.unlinkSync('./b/' + tmpdest);
cb({ success: false, msg: err });
cb({ success: false, file: tmpdest, msg: err });
});
}
else
cb({ success: false, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
});
};
};