This commit is contained in:
Flummi 2016-09-07 11:03:13 +00:00
parent 958bc1d1c0
commit 33f7b0b4a3
4 changed files with 80 additions and 43 deletions

View File

@ -7,21 +7,22 @@ var crypto = require('crypto');
var Mime = require('mime');
var cfg;
var bot, sql, debug;
var bot, sql;
module.exports = Lib;
function Lib(tbot, tsql) {
this.bot = bot = tbot;
this.sql = sql = tsql;
this.debug = debug = false;
this.cfg = cfg = require('../cfg/main.json');
this.admins = [];
Lib.prototype.loadUser((cb) => {
console.log((cb)?"Admins wurden geladen":"Admins konnten nicht geladen werden");
});
}
Lib.prototype.admins = [];
Lib.prototype.debug = false;
Lib.prototype.getUser = (e, cbgu) => {
var u = e.user.getNick();
var n = e.network;
@ -60,8 +61,8 @@ Lib.prototype.getUserlevel = (e, cb) => {
var host = cbgu.username+'@'+cbgu.hostname;
var lvl_channel = (cbgu.nick in e.channel.names)? cfg.level[ e.channel.names[cbgu.nick] ] : 0;
var lvl_db = 0;
if(host in this.admins)
lvl_db = (this.admins[host].server == e.network)? this.admins[host].level : 0;
if(host in Lib.prototype.admins)
lvl_db = (Lib.prototype.admins[host].server == e.network)? Lib.prototype.admins[host].level : 0;
cb({
'channel': lvl_channel,
'db': lvl_db,
@ -70,11 +71,11 @@ Lib.prototype.getUserlevel = (e, cb) => {
});
};
Lib.prototype.loadUser = (cb) => {
this.admins = [];
Lib.prototype.admins = [];
sql.query("select * from `f0ck`.`user`", (err, rows, fields) => {
rows.forEach((e,i,a) => {
this.admins.push(e.nick);
this.admins[e.vhost] = {
rows.forEach(e => {
Lib.prototype.admins.push(e.vhost);
Lib.prototype.admins[e.vhost] = {
'id': e.id,
'nick': e.nick,
'vhost': e.vhost,
@ -82,9 +83,9 @@ Lib.prototype.loadUser = (cb) => {
'server': e.server
};
});
cb(true);
if(cb) cb(true);
}).on('error', () => {
cb(false);
if(cb) cb(false);
});
}
Lib.prototype.checkRepost = (url, cbcr) => {
@ -182,16 +183,6 @@ Lib.prototype.generateThumbs = () => {
});
};
Lib.prototype.log = (msg) => {
if(debug)
if(Lib.prototype.debug)
bot.send("#f0ck", msg, 'n0xy');
};
Lib.prototype.toggleDebug = () => {
if(debug) {
debug = false;
return 'debugmode deactivated';
}
else {
debug = true;
return 'debugmode activated';
}
};

View File

@ -46,7 +46,7 @@ bot.on('message', (e) => {
lib.log('trigger: '+entry.name);
lib.getUserlevel(e, (cb) => {
if(cb.level >= entry.level)
entry.func(e);
entry.func(e, cb.level);
else
e.reply('no permission, min level '+entry.level+' required');
});

View File

@ -5,7 +5,14 @@ module.exports = (bot, trigger, lib) => {
level: 100,
active: 1,
func: (e) => {
e.reply(lib.toggleDebug());
if(lib.debug) {
lib.debug = false;
e.reply('debugmode disabled');
}
else {
lib.debug = true;
e.reply('debugmode enabled');
}
},
desc: 'toggle debug'
});

View File

@ -4,27 +4,66 @@ module.exports = (bot, trigger, lib) => {
call: /^\!level(?: +\@.*)?/i,
level: 0,
active: 1,
func: (e) => {
var user, etmp;
if(user = e.message.match(/^\!level(?: +@(.*))?/i)[1]) {
// e nachbauen xD
etmp = {
network: e.network,
user: {
getNick: () => {
return user.trim();
}
},
channel: {
names: e.channel.names
func: (e, userlevel) => {
var args = e.message.split(' ');
if(Number.isInteger(parseInt(args[2]))) {
if(userlevel >= 100) {
var name = args[1].replace('@','');
var level = (args[2]>=100)?100:args[2];
if( name in e.channel.names ) {
lib.getUser( { network: e.network, user: { getNick: () => { return name.trim(); } }, channel: { names: e.channel.names } }, cb => {
var host = cb.username+'@'+cb.hostname;
if( host in lib.admins ) {
if(level <= 0) {
lib.sql.query('delete from `f0ck`.`user` where `id` = ? limit 1', [lib.admins[host].id], () => {
lib.loadUser();
e.reply('deleted user '+cb.nick+' ('+host+')');
});
}
else {
lib.sql.query('update `f0ck`.`user` set `level` = ? where `id` = ?', [level, lib.admins[host].id], () => {
lib.loadUser();
e.reply('changed user '+cb.nick+' ('+host+') to level '+level);
});
}
}
else {
lib.sql.query('insert into `f0ck`.`user` (`nick`,`vhost`,`level`,`server`) values (?,?,?,?)', [cb.nick, host, level, e.network], () => {
lib.loadUser();
e.reply('added new user '+cb.nick+' ('+host+') with level '+level);
});
}
});
}
};
else
e.reply('user '+name+' not found');
}
else
e.reply('no permission, min level 100 required');
}
else {
var user, etmp;
if(user = e.message.match(/^\!level(?: +@(.*))?/i)[1]) {
etmp = {
network: e.network,
user: {
getNick: () => {
return user.trim();
}
},
channel: {
names: e.channel.names
}
};
}
else
etmp = e;
lib.getUserlevel(etmp, (cb) => {
e.reply("level from "+etmp.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
});
}
else
etmp = e;
lib.getUserlevel(etmp, (cb) => {
e.reply("level from "+etmp.user.getNick()+": "+cb.level+" (Channel: "+cb.channel+" DB: "+cb.db+")");
});
},
desc: 'get Userlevel'
});