fixed whois
This commit is contained in:
parent
611a7e4d61
commit
9911d199e0
110
src/main.js
110
src/main.js
@ -63,32 +63,33 @@ bot.on('message', (e) => {
|
||||
var tmpdest = uuid.v1().split('-')[0];
|
||||
dl(entry, "./b/"+tmpdest, (cb) => { // download item
|
||||
if(cb.status === true) {
|
||||
var tmpuser = getUser(e.user.getNick(), e.network);
|
||||
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
|
||||
checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||
if(cbcrcs) {
|
||||
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,
|
||||
tmpuser['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 "+tmpuser['nick']+" ("+tmpuser['username']+"@"+tmpuser['hostname']+")");
|
||||
}).on('error', (msg) => {
|
||||
e.reply(msg);
|
||||
});
|
||||
}
|
||||
else {
|
||||
fs.unlink("./b/"+tmpdest+"."+cb.infos.ext); // delete repost
|
||||
e.reply("repost motherf0cker");
|
||||
}
|
||||
getUser(e.user.getNick(), e.network, (cbgu) => {
|
||||
getCheckSum("./b/"+tmpdest+"."+cb.infos.ext, (cbcs) => {
|
||||
checkRepostCheckSum(cbcs, (cbcrcs) => {
|
||||
if(cbcrcs) {
|
||||
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");
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -100,8 +101,9 @@ bot.on('message', (e) => {
|
||||
}
|
||||
}
|
||||
else if(orig.match(/^\.user/)) { // (debug) get userinfos
|
||||
var tmp = getUser(e.user.getNick(), e.network);
|
||||
setTimeout(()=>{ e.reply(tmp); }, 500);
|
||||
getUser(e.user.getNick(), e.network, (cbgu) => {
|
||||
e.reply(cbgu);
|
||||
});
|
||||
}
|
||||
else if(orig.match(/^\!reload tpl$/)) {
|
||||
getTpls();
|
||||
@ -134,13 +136,13 @@ bot.on('message', (e) => {
|
||||
}
|
||||
else if(orig.match(/^\!level$/)) {
|
||||
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+")");
|
||||
});
|
||||
}
|
||||
else if(orig.match(/^\!del (\d+)$/i)) {
|
||||
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) {
|
||||
var id = orig.split(' ')[1];
|
||||
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)) {
|
||||
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) {
|
||||
//exec('rm ./t/*.png', (error) => {
|
||||
e.reply("generating Thumbnails...");
|
||||
@ -166,22 +168,38 @@ bot.on('message', (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
var getUser = (u, n) => {
|
||||
bot.whois(u, n, (fn)=>{ }); // send whois
|
||||
var start = Date.now();
|
||||
while(Date.now() < start + 500) {} // block script for catch whois
|
||||
return bot.getUser(u, n);
|
||||
var getUser = (u, n, cbgu) => {
|
||||
bot.write('WHOIS '+u, n, () => {
|
||||
bot.once('data', (err, msg) => {
|
||||
var params;
|
||||
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 lvl_channel = (name in tmp_channel)? cfg.level[ tmp_channel[name] ] : 0;
|
||||
var lvl_db = 0;
|
||||
if(name.toLowerCase() in admins)
|
||||
lvl_db = (admins[name.toLowerCase()].server == e.network)? admins[name.toLowerCase()].level : 0;
|
||||
cb({
|
||||
'channel': lvl_channel,
|
||||
'db': lvl_db,
|
||||
'level': Math.max(lvl_channel, lvl_db)
|
||||
var getUserlevel = (e, tmp_channel, cb) => {
|
||||
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;
|
||||
if(host in admins)
|
||||
lvl_db = (admins[host].server == e.network)? admins[host].level : 0;
|
||||
cb({
|
||||
'channel': lvl_channel,
|
||||
'db': lvl_db,
|
||||
'level': Math.max(lvl_channel, lvl_db)
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -190,7 +208,7 @@ var loadUser = (cb) => {
|
||||
sql.query("select * from `f0ck`.`user`", (err, rows, fields) => {
|
||||
rows.forEach((e,i,a) => {
|
||||
admins.push(e.nick);
|
||||
admins[e.nick] = {
|
||||
admins[e.vhost] = {
|
||||
'id': e.id,
|
||||
'nick': e.nick,
|
||||
'vhost': e.vhost,
|
||||
|
Loading…
Reference in New Issue
Block a user