new configsystem

This commit is contained in:
Flummi
2016-11-07 02:02:02 +01:00
parent 74b6c99295
commit 948fd4e647
3 changed files with 85 additions and 43 deletions

View File

@ -7,7 +7,7 @@ var fileType = require('file-type');
var request = require('request');
var ytdl = require('ytdl-core');
var Readable = require('stream').Readable;
var cfg = require('../../cfg/main.json');
//var cfg = require('../../cfg/main.json');
module.exports = (lib) => {
lib.trigger.add({
@ -40,7 +40,7 @@ module.exports = (lib) => {
(cb.info.thumb !== null)?cb.info.thumb:''
]).on('result', (result) => {
lib.generateThumbs();
e.reply(cfg.url+"/"+result.insertId+" - "+cb.info.title+" ("+cb.info.mime+", ~"+lib.formatSize(cb.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
e.reply(lib.cfg.main.url+"/"+result.insertId+" - "+cb.info.title+" ("+cb.info.mime+", ~"+lib.formatSize(cb.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
}).on('error', (msg) => {
e.reply(msg);
});
@ -82,10 +82,10 @@ module.exports = (lib) => {
try {
ytdl.downloadFromInfo(inf, { filter: (format) => { return format.container === 'webm'; } })
.on('response', (res) => {
if(res.headers['content-length'] > cfg.maxFileSize) {
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(cfg.maxFileSize)+' allowed' });
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 = {
@ -111,10 +111,10 @@ module.exports = (lib) => {
});
}
else if(url.match(sc)) { // scdl
request('https://api.soundcloud.com/resolve.json?client_id=' + cfg.scclientid + '&url=' + url, (err, res, body) => {
request('https://api.soundcloud.com/resolve.json?client_id=' + lib.cfg.main.scclientid + '&url=' + url, (err, res, body) => {
if(!err && res.statusCode === 200) {
var data = JSON.parse(body);
request(data.stream_url + ((data.stream_url.indexOf('?') === -1)?'?':'&') + 'client_id=' + cfg.scclientid)
request(data.stream_url + ((data.stream_url.indexOf('?') === -1)?'?':'&') + 'client_id=' + lib.cfg.main.scclientid)
.pipe(dat);
info = {
type: 'soundcloud',
@ -141,8 +141,8 @@ module.exports = (lib) => {
var type = res.headers['content-type'];
lib.log('MimeType: '+type);
var length = res.headers['content-length'];
if(cfg.allowedMimes.hasOwnProperty(type)) {
if(data.length <= cfg.maxFileSize) {
if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) {
if(data.length <= lib.cfg.main.maxFileSize) {
var s = new Readable
s.push(data);
s.push(null);
@ -151,13 +151,13 @@ module.exports = (lib) => {
type: 'other',
title: path.parse(url).base,
mime: type,
ext: cfg.allowedMimes[type],
ext: lib.cfg.main.allowedMimes[type],
thumb: null
};
}
else {
dat.end();
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize(lib.cfg.main.maxFileSize)+' allowed' });
}
}
else {
@ -176,8 +176,8 @@ module.exports = (lib) => {
.on('finish', () => {
var size = dat.bytesWritten;
dat.end();
if(size > cfg.maxFileSize)
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed' });
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 {
fs.stat('./b/' + tmpdest, (err, stat) => {
if(!err && stat.isFile() && stat.size > 300) {
@ -186,13 +186,13 @@ module.exports = (lib) => {
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs === true) {
var mime = fileType(readChunk.sync('./b/' + tmpdest, 0, 262));
if(cfg.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
if(lib.cfg.main.allowedMimes.hasOwnProperty(mime.mime) || info.type === 'soundcloud')
cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
else
cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime+')' });
}
else
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcrcs });
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcrcs });
});
});
}
@ -204,7 +204,7 @@ module.exports = (lib) => {
});
}
else
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+cfg.url+'/'+cbcr });
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcr });
});
};
};