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