diff --git a/src/trigger/limit.js b/src/trigger/limit.js new file mode 100644 index 0000000..db0721d --- /dev/null +++ b/src/trigger/limit.js @@ -0,0 +1,12 @@ +module.exports = (lib) => { + lib.trigger.add({ + name: 'limit', + call: /^!limit$/i, + level: 0, + active: 1, + func: (e) => { + e.reply( "up to " + lib.formatSize(lib.cfg.main.maxFileSize) ); + }, + desc: 'limit' + }); +}; \ No newline at end of file diff --git a/src/trigger/parser.js b/src/trigger/parser.js index 81ca068..1259b99 100644 --- a/src/trigger/parser.js +++ b/src/trigger/parser.js @@ -14,13 +14,13 @@ module.exports = (lib) => { call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, level: 0, active: 0, - func: (e) => { + func: (e, userlevel) => { if(e.channel.getName() === lib.cfg.main.debugchannel || e.message.match(/(!|-)f0ck/i)) { if(!e.message.match(/(!|-)ignore/)) { var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links tmp.forEach((entry,i,a) => { if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) { - getLink(entry, (cb) => { + getLink(entry, ((e.message.match(/(!|-)force/i) && userlevel >= 100)?true:false), (cb) => { if(cb.success === true) { fs.move(cb.file, cb.file + '.' + cb.info.ext, (err) => { if(!err) { @@ -64,7 +64,7 @@ module.exports = (lib) => { desc: 'muh' }); - var getLink = (url, cb) => { + var getLink = (url, force, cb) => { 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) => { @@ -72,7 +72,6 @@ module.exports = (lib) => { if(cbcr === true) { var dat = fs.createWriteStream('./b/' + tmpdest); var info; - if(url.match(yt)) { // ytdl ytdl.getInfo(url, (err, inf) => { if(!err) { @@ -81,12 +80,7 @@ module.exports = (lib) => { try { ytdl.downloadFromInfo(inf, { filter: (format) => { return format.container === 'webm'; } }) .on('response', (res) => { - if(res.headers['content-length'] > lib.cfg.main.maxFileSize) { - res.destroy(); - dat.end(); - cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); - } - else { + if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || force ) { info = { type: 'youtube', title: title, @@ -95,6 +89,11 @@ module.exports = (lib) => { thumb: iurl }; } + else { + res.destroy(); + dat.end(); + cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); + } }) .on('error', (err) => { dat.end(); @@ -141,7 +140,7 @@ module.exports = (lib) => { lib.log('MimeType: '+type); var length = res.headers['content-length']; if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) { - if(data.length <= lib.cfg.main.maxFileSize) { + if( ( data.length <= lib.cfg.main.maxFileSize ) || force ) { var s = new Readable s.push(data); s.push(null); @@ -175,9 +174,7 @@ module.exports = (lib) => { .on('finish', () => { var size = dat.bytesWritten; dat.end(); - if(size > lib.cfg.main.maxFileSize) - cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); - else { + if( ( size <= lib.cfg.main.maxFileSize ) || force ) { fs.stat('./b/' + tmpdest, (err, stat) => { if(!err && stat.isFile() && stat.size > 300) { lib.log('Datei '+tmpdest+' existiert'); @@ -199,6 +196,9 @@ module.exports = (lib) => { } }); } + else { + cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' }); + } }) .on('error', (err) => { cb({ success: false, file: tmpdest, msg: err });