Merge branch 'f0ckdev' into 'master'
limittrigger & limitforce See merge request !59
This commit is contained in:
commit
21d11da375
12
src/trigger/limit.js
Normal file
12
src/trigger/limit.js
Normal 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'
|
||||||
|
});
|
||||||
|
};
|
@ -14,13 +14,13 @@ module.exports = (lib) => {
|
|||||||
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
||||||
level: 0,
|
level: 0,
|
||||||
active: 0,
|
active: 0,
|
||||||
func: (e) => {
|
func: (e, userlevel) => {
|
||||||
if(e.channel.getName() === lib.cfg.main.debugchannel || e.message.match(/(!|-)f0ck/i)) {
|
if(e.channel.getName() === lib.cfg.main.debugchannel || e.message.match(/(!|-)f0ck/i)) {
|
||||||
if(!e.message.match(/(!|-)ignore/)) {
|
if(!e.message.match(/(!|-)ignore/)) {
|
||||||
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) && userlevel >= 100)?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) => {
|
||||||
@ -72,7 +72,6 @@ module.exports = (lib) => {
|
|||||||
if(cbcr === true) {
|
if(cbcr === true) {
|
||||||
var dat = fs.createWriteStream('./b/' + tmpdest);
|
var dat = fs.createWriteStream('./b/' + tmpdest);
|
||||||
var info;
|
var info;
|
||||||
|
|
||||||
if(url.match(yt)) { // ytdl
|
if(url.match(yt)) { // ytdl
|
||||||
ytdl.getInfo(url, (err, inf) => {
|
ytdl.getInfo(url, (err, inf) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
@ -81,12 +80,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 ) || 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 +89,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 +140,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 ) || force ) {
|
||||||
var s = new Readable
|
var s = new Readable
|
||||||
s.push(data);
|
s.push(data);
|
||||||
s.push(null);
|
s.push(null);
|
||||||
@ -175,9 +174,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 ) || 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 +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) => {
|
.on('error', (err) => {
|
||||||
cb({ success: false, file: tmpdest, msg: err });
|
cb({ success: false, file: tmpdest, msg: err });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user