modified: src/main.js

This commit is contained in:
Flummi 2016-08-14 14:06:18 +02:00
parent e341a2d52f
commit 059b713555

View File

@ -44,17 +44,25 @@ bot.on('motd', (e) => {
bot.on('message', (e) => {
var orig = e.message;
if(e.channel.getName().toString() == "#f0ck") { // (debug) only in channel #f0ck
if(orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi)) { // shitpostcatcher
var tmp = orig.match(/https?:\/\/[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?/gi); // get links
tmp.forEach((entry,i,a) => {
dl(entry, "./b/"+path.parse(entry).base, (cb) => { // download item
if(cb.status === true) {
var tmpuser = getUser(e.user.getNick(), e.network);
setTimeout(()=>{
sql.query("insert into `f0ck`.`items` values (?,?,?,?,?,?,?)",tmp, "./b/"+path.parse(entry).base,tmpuser['username'],e.channel.getName(),new Date().getTime(),0);
sql.query("insert into `f0ck`.`items` (`src`,`dest`,`username`,`userchannel`,`usernetwork`,`stamp`,`active`) values (?,?,?,?,?,?,?)", [
entry,
"./b/"+path.parse(entry).base,
tmpuser['nick'],
e.channel.getName(),
e.network,
new Date().getTime(),
0
]).on('end', () => {
e.reply(cb.msg+" for "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
}, 1600);
}).on('error', (msg) => {
e.reply(msg);
});
}
else
e.reply(cb.msg);
@ -65,13 +73,20 @@ bot.on('message', (e) => {
var tmp = getUser(e.user.getNick(), e.network);
setTimeout(()=>{ e.reply(tmp); }, 1500);
}
else if(orig.match(/^\.del/) && e.channel.getName().toString() == "#f0ck") {
sql.query("truncate table `f0ck`.`items`")
.on('end', () => {
e.reply("database truncated");
}).on('error', (msg) => {
e.reply(msg);
});
}
});
var getUser = (u, n) => {
bot.whois(u, n, (fn)=>{ }); // send whois
var start = Date.now();
while(Date.now() < start + 2000) {} // block script for catch whois
while(Date.now() < start + 1000) {} // block script for catch whois
return bot.getUser(u, n);
};
@ -109,7 +124,6 @@ var dl = (url, dest, cb) => {
};
var checkRepost = (url, cbcr) => {
console.log(url);
sql.query("select count(*) as count from `f0ck`.`items` where `src` = ?", url, (err, rows, fields) => {
cbcr((rows[0].count == 0)?true:false);
});