limittrigger & limitforce

This commit is contained in:
Flummi 2016-12-30 18:59:01 +01:00
parent 1d2a798c83
commit aa3dc93eeb
2 changed files with 26 additions and 13 deletions

12
src/trigger/limit.js Normal file
View File

@ -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'
});
};

View File

@ -8,7 +8,7 @@ var request = require('request');
var ytdl = require('ytdl-core'); var ytdl = require('ytdl-core');
var Readable = require('stream').Readable; var Readable = require('stream').Readable;
module.exports = (lib) => { module.exports = (lib, userlevel) => {
lib.trigger.add({ lib.trigger.add({
name: 'parser', name: 'parser',
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi, call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
@ -20,7 +20,7 @@ module.exports = (lib) => {
var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
tmp.forEach((entry,i,a) => { tmp.forEach((entry,i,a) => {
if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) { if(!entry.match(/f0ck\.me/i) && !entry.match(/\.onion/i)) {
getLink(entry, (cb) => { getLink(entry, (e.message.match(/(!|-)force/i)?true:false), (cb) => {
if(cb.success === true) { if(cb.success === true) {
fs.move(cb.file, cb.file + '.' + cb.info.ext, (err) => { fs.move(cb.file, cb.file + '.' + cb.info.ext, (err) => {
if(!err) { if(!err) {
@ -64,7 +64,7 @@ module.exports = (lib) => {
desc: 'muh' 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 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; var sc = /https?:\/\/(www\.)?(soundcloud\.com|snd\.sc)(\/\S*)(\/\S*)/gi;
lib.checkRepost(url, (cbcr) => { lib.checkRepost(url, (cbcr) => {
@ -81,12 +81,7 @@ module.exports = (lib) => {
try { try {
ytdl.downloadFromInfo(inf, { filter: (format) => { return format.container === 'webm'; } }) ytdl.downloadFromInfo(inf, { filter: (format) => { return format.container === 'webm'; } })
.on('response', (res) => { .on('response', (res) => {
if(res.headers['content-length'] > lib.cfg.main.maxFileSize) { if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || ( userlevel >= 100 && force ) ) {
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 {
info = { info = {
type: 'youtube', type: 'youtube',
title: title, title: title,
@ -95,6 +90,11 @@ module.exports = (lib) => {
thumb: iurl 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) => { .on('error', (err) => {
dat.end(); dat.end();
@ -141,7 +141,7 @@ module.exports = (lib) => {
lib.log('MimeType: '+type); lib.log('MimeType: '+type);
var length = res.headers['content-length']; var length = res.headers['content-length'];
if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) { if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) {
if(data.length <= lib.cfg.main.maxFileSize) { if( ( data.length <= lib.cfg.main.maxFileSize ) || ( userlevel >= 100 && force ) ) {
var s = new Readable var s = new Readable
s.push(data); s.push(data);
s.push(null); s.push(null);
@ -175,9 +175,7 @@ module.exports = (lib) => {
.on('finish', () => { .on('finish', () => {
var size = dat.bytesWritten; var size = dat.bytesWritten;
dat.end(); dat.end();
if(size > lib.cfg.main.maxFileSize) if( ( size <= lib.cfg.main.maxFileSize ) || ( userlevel >= 100 && force ) ) {
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' });
else {
fs.stat('./b/' + tmpdest, (err, stat) => { fs.stat('./b/' + tmpdest, (err, stat) => {
if(!err && stat.isFile() && stat.size > 300) { if(!err && stat.isFile() && stat.size > 300) {
lib.log('Datei '+tmpdest+' existiert'); lib.log('Datei '+tmpdest+' existiert');
@ -199,6 +197,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) => { .on('error', (err) => {
cb({ success: false, file: tmpdest, msg: err }); cb({ success: false, file: tmpdest, msg: err });