55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
|
var fs = require('fs-extra');
|
||
|
var uuid = require('uuid');
|
||
|
|
||
|
module.exports = (bot, trigger, lib) => {
|
||
|
trigger.add({
|
||
|
name: 'parser',
|
||
|
call: 'https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?',
|
||
|
level: 0,
|
||
|
func: (e) => {
|
||
|
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];
|
||
|
lib.dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||
|
if(cb.status === true) {
|
||
|
lib.getUser(e.user.getNick(), e.network, (cbgu) => {
|
||
|
lib.getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
|
||
|
lib.checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||
|
if(cbcrcs) {
|
||
|
lib.sql.query("insert into `f0ck`.`items` (`src`,`dest`,`mime`,`size`,`checksum`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?,?,?,?)", [
|
||
|
entry,
|
||
|
"./b/"+tmpdest+"."+cb.infos.ext,
|
||
|
cb.infos.mime,
|
||
|
cb.infos.size,
|
||
|
cbcs,
|
||
|
cbgu['nick'],
|
||
|
e.channel.getName(),
|
||
|
e.network,
|
||
|
Math.floor(new Date() / 1000),
|
||
|
0
|
||
|
]).on('result', (result) => {
|
||
|
generateThumbs();
|
||
|
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+cbgu['nick']+" ("+cbgu['username']+"@"+cbgu['hostname']+")");
|
||
|
}).on('error', (msg) => {
|
||
|
e.reply(msg);
|
||
|
});
|
||
|
}
|
||
|
else {
|
||
|
fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost
|
||
|
e.reply("repost motherf0cker");
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
else
|
||
|
if(cb.type == 1)
|
||
|
e.reply(cb.msg);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
desc: 'muh'
|
||
|
});
|
||
|
};
|