modified: src/main.js

This commit is contained in:
Flummi 2016-08-18 09:22:46 +02:00
parent 6bea0bfd30
commit 5ab7713f97

View File

@ -116,6 +116,17 @@ bot.on('message', (e) => {
e.reply("debugmessages activated");
}
}
else if(orig.match(/^\!load user$/)) {
loadUser((cb) => {
e.reply(admins);
});
}
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) => {
e.reply("level from "+e.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
});
}
});
var getUser = (u, n) => {
@ -125,18 +136,30 @@ var getUser = (u, n) => {
return bot.getUser(u, n);
};
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 loadUser = (cb) => {
admins = [];
sql.query("select * from `f0ck`.`user`", (err, rows, fields) => {
rows.forEach((e,i,a) => {
admins.push(e.nick);
admins[e.nick].push({
id: e.id,
nick: e.nick,
vhost: e.vhost,
level: e.level,
server: e.server
});
admins[e.nick] = {
'id': e.id,
'nick': e.nick,
'vhost': e.vhost,
'level': e.level,
'server': e.server
};
});
cb(true);
}).on('error', () => {
@ -417,3 +440,5 @@ var generateThumbs = () => {
});
});
};
loadUser((cb)=>{});