commit
b6b11af46d
|
@ -9,203 +9,203 @@ var ytdl = require('ytdl-core');
|
||||||
var Readable = require('stream').Readable;
|
var Readable = require('stream').Readable;
|
||||||
|
|
||||||
module.exports = (lib) => {
|
module.exports = (lib) => {
|
||||||
lib.trigger.add({
|
lib.trigger.add({
|
||||||
name: 'parser',
|
name: 'parser',
|
||||||
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
||||||
level: 0,
|
level: 0,
|
||||||
active: 0,
|
active: 0,
|
||||||
func: (e, userlevel) => {
|
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, ((e.message.match(/(!|-)force/i) && userlevel >= 100)?true:false), userlevel, (cb) => {
|
getLink(entry, ((e.message.match(/(!|-)force/i) && userlevel >= 100)?true:false), userlevel, (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) {
|
||||||
lib.bot.whois(e.user.getNick(), e.network, (err, cbgu) => {
|
lib.bot.whois(e.user.getNick(), e.network, (err, cbgu) => {
|
||||||
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`,`thumb`) values (?,?,?,?,?,?,?,?,?,?,?)", [
|
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`,`thumb`) values (?,?,?,?,?,?,?,?,?,?,?)", [
|
||||||
entry,
|
entry,
|
||||||
cb.file + '.' + cb.info.ext,
|
cb.file + '.' + cb.info.ext,
|
||||||
cb.info.mime,
|
cb.info.mime,
|
||||||
cb.size,
|
cb.size,
|
||||||
cb.checksum,
|
cb.checksum,
|
||||||
cbgu['nick'],
|
cbgu['nick'],
|
||||||
e.channel.getName(),
|
e.channel.getName(),
|
||||||
e.network,
|
e.network,
|
||||||
Math.floor(new Date() / 1000),
|
Math.floor(new Date() / 1000),
|
||||||
0,
|
0,
|
||||||
(cb.info.thumb !== null)?cb.info.thumb:''
|
cb.info.thumb ? cb.info.thumb : ''
|
||||||
]).on('result', (result) => {
|
]).on('result', (result) => {
|
||||||
lib.generateThumbs();
|
lib.generateThumbs();
|
||||||
e.reply(lib.cfg.main.url+"/"+result.insertId+" - "+cb.info.title+" ("+cb.info.mime+", ~"+lib.formatSize(cb.size)+") by "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
|
e.reply(lib.cfg.main.url+"/"+result.insertId+" - "+cb.info.title+" ("+cb.info.mime+", ~"+lib.formatSize(cb.size)+") by "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
|
||||||
}).on('error', (msg) => {
|
}).on('error', (msg) => {
|
||||||
e.reply(msg);
|
e.reply(msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fs.stat('./b/' + cb.file, (err, stat) => {
|
fs.stat('./b/' + cb.file, (err, stat) => {
|
||||||
if(cb.msg !== '')
|
if(cb.msg !== '')
|
||||||
e.reply(cb.msg);
|
e.reply(cb.msg);
|
||||||
if(!err && stat.isFile())
|
if(!err && stat.isFile())
|
||||||
fs.unlinkSync('./b/' + cb.file);
|
fs.unlinkSync('./b/' + cb.file);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
desc: 'muh'
|
desc: 'muh'
|
||||||
});
|
});
|
||||||
|
|
||||||
var getLink = (url, force, userlevel, cb) => {
|
var getLink = (url, force, userlevel, 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) => {
|
||||||
var tmpdest = uuid.v1().split('-')[0];
|
var tmpdest = uuid.v1().split('-')[0];
|
||||||
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) {
|
||||||
var title = inf.title;
|
var title = inf.title;
|
||||||
var iurl = JSON.parse(inf.player_response).videoDetails.thumbnail.thumbnails[0].url.split('?')[0];
|
var iurl = JSON.parse(inf.player_response).videoDetails.thumbnail.thumbnails[0].url.split('?')[0];
|
||||||
try {
|
try {
|
||||||
dlformat = { filter: (format) => { return format.container === 'webm'; } };
|
dlformat = { filter: (format) => { return format.container === 'webm'; } };
|
||||||
ytdl.downloadFromInfo(inf, dlformat)
|
ytdl.downloadFromInfo(inf, dlformat)
|
||||||
.on('response', (res) => {
|
.on('response', (res) => {
|
||||||
if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && res.headers['content-length'] <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
if( ( res.headers['content-length'] <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && res.headers['content-length'] <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
||||||
info = {
|
info = {
|
||||||
type: 'youtube',
|
type: 'youtube',
|
||||||
title: title,
|
title: title,
|
||||||
mime: 'video/webm',
|
mime: 'video/webm',
|
||||||
ext: 'webm',
|
ext: 'webm',
|
||||||
thumb: iurl
|
thumb: iurl
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.destroy();
|
res.destroy();
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
|
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(res.headers['content-length'])+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('error', (err) => {
|
.on('error', (err) => {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: err.message });
|
cb({ success: false, file: tmpdest, msg: err.message });
|
||||||
})
|
})
|
||||||
.pipe(dat);
|
.pipe(dat);
|
||||||
}
|
}
|
||||||
catch(ex) {
|
catch(ex) {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: ex.message });
|
cb({ success: false, file: tmpdest, msg: ex.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if(url.match(sc)) { // scdl
|
else if(url.match(sc)) { // scdl
|
||||||
request('https://api.soundcloud.com/resolve.json?client_id=' + lib.cfg.main.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) {
|
if(!err && res.statusCode === 200) {
|
||||||
var data = JSON.parse(body);
|
var data = JSON.parse(body);
|
||||||
request(data.stream_url + ((data.stream_url.indexOf('?') === -1)?'?':'&') + 'client_id=' + lib.cfg.main.scclientid)
|
request(data.stream_url + ((data.stream_url.indexOf('?') === -1)?'?':'&') + 'client_id=' + lib.cfg.main.scclientid)
|
||||||
.pipe(dat);
|
.pipe(dat);
|
||||||
info = {
|
info = {
|
||||||
type: 'soundcloud',
|
type: 'soundcloud',
|
||||||
title: data.title,
|
title: data.title,
|
||||||
mime: 'audio/mpeg',
|
mime: 'audio/mpeg',
|
||||||
ext: 'mp3',
|
ext: 'mp3',
|
||||||
thumb: (data.artwork_url !== null)?data.artwork_url.replace('large.jpg', 't300x300.jpg'):null
|
thumb: (data.artwork_url !== null)?data.artwork_url.replace('large.jpg', 't300x300.jpg'):null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' });
|
cb({ success: false, file: tmpdest, msg: 'f0ck sc-api' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { // various
|
else { // various
|
||||||
cloudscraper.request({
|
cloudscraper.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
url: url,
|
url: url,
|
||||||
encoding: null,
|
encoding: null,
|
||||||
},
|
},
|
||||||
(err, res, data) => {
|
(err, res, data) => {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var type = res.headers['content-type'];
|
var type = res.headers['content-type'];
|
||||||
lib.log('MimeType: '+type);
|
lib.log('MimeType: '+type);
|
||||||
if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) {
|
if(lib.cfg.main.allowedMimes.hasOwnProperty(type)) {
|
||||||
if( ( data.length <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && data.length <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
if( ( data.length <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && data.length <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
||||||
var s = new Readable;
|
var s = new Readable;
|
||||||
s.push(data);
|
s.push(data);
|
||||||
s.push(null);
|
s.push(null);
|
||||||
s.pipe(dat);
|
s.pipe(dat);
|
||||||
info = {
|
info = {
|
||||||
type: 'other',
|
type: 'other',
|
||||||
title: path.parse(url).base,
|
title: path.parse(url).base,
|
||||||
mime: type,
|
mime: type,
|
||||||
ext: lib.cfg.main.allowedMimes[type],
|
ext: lib.cfg.main.allowedMimes[type],
|
||||||
thumb: null
|
thumb: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
|
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(data.length)+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: '' });
|
cb({ success: false, file: tmpdest, msg: '' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dat.end();
|
dat.end();
|
||||||
cb({ success: false, file: tmpdest, msg: err });
|
cb({ success: false, file: tmpdest, msg: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
dat
|
dat
|
||||||
.on('finish', () => {
|
.on('finish', () => {
|
||||||
var size = dat.bytesWritten;
|
var size = dat.bytesWritten;
|
||||||
dat.end();
|
dat.end();
|
||||||
if( ( size <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && size <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
if( ( size <= lib.cfg.main.maxFileSize ) || force || ( userlevel >= 60 && size <= (lib.cfg.main.maxFileSize * 2) ) ) {
|
||||||
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');
|
||||||
lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
|
lib.getCheckSum('./b/' + tmpdest, (cbcs) => {
|
||||||
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||||
if(cbcrcs === true) {
|
if(cbcrcs === true) {
|
||||||
var mime = fileType(readChunk.sync('./b/' + tmpdest, 0, 262));
|
var mime = fileType(readChunk.sync('./b/' + tmpdest, 0, 262));
|
||||||
info.ext = mime.ext;
|
info.ext = mime.ext;
|
||||||
info.mime = mime.mime;
|
info.mime = mime.mime;
|
||||||
if(lib.cfg.main.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 });
|
cb({ success: true, info: info, size: size, file: './b/' + tmpdest, checksum: cbcs });
|
||||||
else
|
else
|
||||||
cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime.mime+')' });
|
cb({ success: false, file: tmpdest, msg: 'lol, go f0ck yourself ('+mime.mime+')' });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcrcs });
|
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcrcs });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):lib.cfg.main.maxFileSize ) )+' allowed' });
|
cb({ success: false, file: tmpdest, msg: 'f0ck! your file is too big (~'+lib.formatSize(size)+'), max '+lib.formatSize( ( userlevel >= 60?(lib.cfg.main.maxFileSize*2):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 });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcr });
|
cb({ success: false, file: tmpdest, msg: 'repost motherf0cker: '+lib.cfg.main.url+'/'+cbcr });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user