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 Readable = require('stream').Readable;
module.exports = (lib) => {
module.exports = (lib, userlevel) => {
lib.trigger.add({
name: 'parser',
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
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)?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) => {
@ -81,12 +81,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 ) || ( userlevel >= 100 && force ) ) {
info = {
type: 'youtube',
title: title,
@ -95,6 +90,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 +141,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 ) || ( userlevel >= 100 && force ) ) {
var s = new Readable
s.push(data);
s.push(null);
@ -175,9 +175,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 ) || ( userlevel >= 100 && force ) ) {
fs.stat('./b/' + tmpdest, (err, stat) => {
if(!err && stat.isFile() && stat.size > 300) {
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) => {
cb({ success: false, file: tmpdest, msg: err });