2016-08-23 11:23:25 +00:00
|
|
|
var fs = require('fs-extra');
|
|
|
|
var uuid = require('uuid');
|
2016-08-23 15:50:30 +00:00
|
|
|
var path = require('path');
|
2016-09-09 07:51:10 +00:00
|
|
|
var cloudscraper = require('cloudscraper');
|
|
|
|
var Mime = require('mime');
|
|
|
|
var cfg = require('../../cfg/main.json');
|
2016-08-23 11:23:25 +00:00
|
|
|
|
|
|
|
module.exports = (bot, trigger, lib) => {
|
|
|
|
trigger.add({
|
|
|
|
name: 'parser',
|
2016-08-24 20:02:20 +00:00
|
|
|
call: /https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi,
|
2016-08-23 11:23:25 +00:00
|
|
|
level: 0,
|
2016-08-24 07:55:40 +00:00
|
|
|
active: 1,
|
2016-08-23 11:23:25 +00:00
|
|
|
func: (e) => {
|
2016-09-08 15:46:14 +00:00
|
|
|
if(e.channel.getName() == '#f0ck' || e.channel.getName() == '#kbot-dev') {
|
2016-08-23 17:36:16 +00:00
|
|
|
if(!e.message.match(/\!ignore$/)) {
|
|
|
|
var tmp = e.message.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
|
|
|
|
tmp.forEach((entry,i,a) => {
|
|
|
|
var tmpdest = uuid.v1().split('-')[0];
|
2016-08-24 20:21:02 +00:00
|
|
|
if(!entry.match(/f0ck\.me/i)) {
|
2016-09-09 07:51:10 +00:00
|
|
|
lib.checkRepost(entry, (cbcr) => {
|
|
|
|
if(cbcr === true) {
|
|
|
|
cloudscraper.request({
|
|
|
|
method: 'GET',
|
|
|
|
url: entry,
|
|
|
|
encoding: null,
|
|
|
|
},
|
|
|
|
(error, res, data) => {
|
|
|
|
if(error)
|
|
|
|
console.log('Error occurred');
|
|
|
|
else {
|
|
|
|
var type = res.headers['content-type'];
|
|
|
|
var length = res.headers['content-length'];
|
|
|
|
var dest = './b/'+tmpdest+'.'+cfg.allowedMimes[type];
|
|
|
|
if(cfg.allowedMimes.hasOwnProperty(type)) {
|
|
|
|
if(length <= cfg.maxFileSize) {
|
|
|
|
fs.writeFile(dest, data, (err) => {
|
|
|
|
if(!err) {
|
|
|
|
lib.getCheckSum(dest, (cbcs) => {
|
|
|
|
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
|
|
|
if(cbcrcs === true) {
|
|
|
|
var mime = Mime.lookup(dest);
|
|
|
|
if(cfg.allowedMimes.hasOwnProperty(mime)) {
|
|
|
|
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`) values (?,?,?,?,?,?,?,?,?,?)", [
|
|
|
|
entry,
|
|
|
|
dest,
|
|
|
|
mime,
|
|
|
|
length,
|
|
|
|
cbcs,
|
|
|
|
cbgu['nick'],
|
|
|
|
e.channel.getName(),
|
|
|
|
e.network,
|
|
|
|
Math.floor(new Date() / 1000),
|
|
|
|
0
|
|
|
|
]).on('result', (result) => {
|
|
|
|
lib.generateThumbs();
|
|
|
|
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+mime+", ~"+lib.formatSize(length)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
|
|
|
|
}).on('error', (msg) => {
|
|
|
|
e.reply(msg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.reply('lol, go f0ck yourself');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.reply("repost motherf0cker: https://f0ck.me/"+cbcrcs);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.reply(err);
|
2016-08-24 20:21:02 +00:00
|
|
|
});
|
|
|
|
}
|
2016-09-09 07:51:10 +00:00
|
|
|
else
|
|
|
|
e.reply('f0ck! your file is too big (~'+lib.formatSize(length)+'), max '+lib.formatSize(cfg.maxFileSize)+' allowed');
|
|
|
|
}
|
|
|
|
}
|
2016-08-23 11:23:25 +00:00
|
|
|
});
|
2016-08-24 20:21:02 +00:00
|
|
|
}
|
|
|
|
else
|
2016-09-09 07:51:10 +00:00
|
|
|
e.reply('repost motherf0cker: https://f0ck.me/'+cbcr);
|
2016-08-24 20:21:02 +00:00
|
|
|
});
|
|
|
|
}
|
2016-08-23 11:23:25 +00:00
|
|
|
});
|
2016-08-23 17:36:16 +00:00
|
|
|
}
|
2016-08-23 11:23:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
desc: 'muh'
|
|
|
|
});
|
|
|
|
};
|