fixed whois

This commit is contained in:
Flummi 2016-08-22 14:00:20 +02:00
parent 611a7e4d61
commit 9911d199e0

View File

@ -63,7 +63,7 @@ bot.on('message', (e) => {
var tmpdest = uuid.v1().split('-')[0]; var tmpdest = uuid.v1().split('-')[0];
dl(entry, "./b/"+tmpdest, (cb) => { // download item dl(entry, "./b/"+tmpdest, (cb) => { // download item
if(cb.status === true) { if(cb.status === true) {
var tmpuser = getUser(e.user.getNick(), e.network); getUser(e.user.getNick(), e.network, (cbgu) => {
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => { getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
checkRepostCheckSum(cbcs, (cbcrcs) => { checkRepostCheckSum(cbcs, (cbcrcs) => {
if(cbcrcs) { if(cbcrcs) {
@ -73,14 +73,14 @@ bot.on('message', (e) => {
cb.infos.mime, cb.infos.mime,
cb.infos.size, cb.infos.size,
cbcs, cbcs,
tmpuser['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
]).on('result', (result) => { ]).on('result', (result) => {
generateThumbs(); generateThumbs();
e.reply("https://f0ck.me/"+result.insertId+" - "+path.parse(entry).base+" ("+cb.infos.mime+", ~"+formatSize(cb.infos.size)+") from "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")"); 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) => { }).on('error', (msg) => {
e.reply(msg); e.reply(msg);
}); });
@ -91,6 +91,7 @@ bot.on('message', (e) => {
} }
}); });
}); });
});
} }
else else
if(cb.type == 1) if(cb.type == 1)
@ -100,8 +101,9 @@ bot.on('message', (e) => {
} }
} }
else if(orig.match(/^\.user/)) { // (debug) get userinfos else if(orig.match(/^\.user/)) { // (debug) get userinfos
var tmp = getUser(e.user.getNick(), e.network); getUser(e.user.getNick(), e.network, (cbgu) => {
setTimeout(()=>{ e.reply(tmp); }, 500); e.reply(cbgu);
});
} }
else if(orig.match(/^\!reload tpl$/)) { else if(orig.match(/^\!reload tpl$/)) {
getTpls(); getTpls();
@ -134,13 +136,13 @@ bot.on('message', (e) => {
} }
else if(orig.match(/^\!level$/)) { else if(orig.match(/^\!level$/)) {
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names; var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
var level = getUserlevel(e, e.user.getNick(), tmp_channel, (cb) => { getUserlevel(e, tmp_channel, (cb) => {
e.reply("level from "+e.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")"); e.reply("level from "+e.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
}); });
} }
else if(orig.match(/^\!del (\d+)$/i)) { else if(orig.match(/^\!del (\d+)$/i)) {
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names; var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
getUserlevel(e, e.user.getNick(), tmp_channel, (cb) => { getUserlevel(e, tmp_channel, (cb) => {
if(cb.level >= 100) { if(cb.level >= 100) {
var id = orig.split(' ')[1]; var id = orig.split(' ')[1];
sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => { sql.query("delete from `f0ck`.`items` where `id` = ?", id).on('end', () => {
@ -153,7 +155,7 @@ bot.on('message', (e) => {
} }
else if(orig.match(/^\!thumbs$/i)) { else if(orig.match(/^\!thumbs$/i)) {
var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names; var tmp_channel = bot.getChannel(e.channel.getName(), e.network).names;
getUserlevel(e, e.user.getNick(), tmp_channel, (cb) => { getUserlevel(e, tmp_channel, (cb) => {
if(cb.level >= 100) { if(cb.level >= 100) {
//exec('rm ./t/*.png', (error) => { //exec('rm ./t/*.png', (error) => {
e.reply("generating Thumbnails..."); e.reply("generating Thumbnails...");
@ -166,23 +168,39 @@ bot.on('message', (e) => {
} }
}); });
var getUser = (u, n) => { var getUser = (u, n, cbgu) => {
bot.whois(u, n, (fn)=>{ }); // send whois bot.write('WHOIS '+u, n, () => {
var start = Date.now(); bot.once('data', (err, msg) => {
while(Date.now() < start + 500) {} // block script for catch whois var params;
return bot.getUser(u, n); var map = [];
map.push(u);
if(msg.command == 'RPL_WHOISUSER') {
params = msg.params.split(' ');
map[u] = map[u] || {};
map[u].nick = u;
map[u].username = params[2];
map[u].hostname = params[3];
map[u].realname = msg.trailing;
}
if(typeof(map[u]) === 'object')
cbgu(map[u]);
});
});
}; };
var getUserlevel = (e, name, tmp_channel, cb) => { var getUserlevel = (e, tmp_channel, cb) => {
var lvl_channel = (name in tmp_channel)? cfg.level[ tmp_channel[name] ] : 0; getUser(e.user.getNick(), e.network, (cbgu) => {
var host = cbgu.username+'@'+cbgu.hostname;
var lvl_channel = (cbgu.nick in tmp_channel)? cfg.level[ tmp_channel[cbgu.nick] ] : 0;
var lvl_db = 0; var lvl_db = 0;
if(name.toLowerCase() in admins) if(host in admins)
lvl_db = (admins[name.toLowerCase()].server == e.network)? admins[name.toLowerCase()].level : 0; lvl_db = (admins[host].server == e.network)? admins[host].level : 0;
cb({ cb({
'channel': lvl_channel, 'channel': lvl_channel,
'db': lvl_db, 'db': lvl_db,
'level': Math.max(lvl_channel, lvl_db) 'level': Math.max(lvl_channel, lvl_db)
}); });
});
}; };
var loadUser = (cb) => { var loadUser = (cb) => {
@ -190,7 +208,7 @@ var loadUser = (cb) => {
sql.query("select * from `f0ck`.`user`", (err, rows, fields) => { sql.query("select * from `f0ck`.`user`", (err, rows, fields) => {
rows.forEach((e,i,a) => { rows.forEach((e,i,a) => {
admins.push(e.nick); admins.push(e.nick);
admins[e.nick] = { admins[e.vhost] = {
'id': e.id, 'id': e.id,
'nick': e.nick, 'nick': e.nick,
'vhost': e.vhost, 'vhost': e.vhost,