first step of [#616]

This commit is contained in:
reality 2014-06-03 22:47:52 +00:00
parent 58b9e430ad
commit 51426264d6
2 changed files with 56 additions and 37 deletions

View File

@ -5,46 +5,36 @@ var api = function(dbot) {
/**
* Does the user have the correct access level to use the command?
*/
'hasAccess': function(user, channel, command, callback) {
var accessNeeded = dbot.commands[command].access;
'hasAccess': function(event, command, callback) {
var accessNeeded = dbot.commands[command].access,
allowedNicks,
user = event.rUser;
if(accessNeeded == 'admin' || accessNeeded == 'moderator' ||
accessNeeded == 'power_user' || accessNeeded == 'voice') {
var allowedNicks = dbot.config.admins;
if(accessNeeded == 'moderator') allowedNicks = _.union(allowedNicks, dbot.config.moderators);
if(accessNeeded == 'power_user') {
allowedNicks = _.union(allowedNicks, dbot.config.moderators);
allowedNicks = _.union(allowedNicks, dbot.config.power_users);
}
if(accessNeeded == 'voice') {
allowedNicks = _.union(allowedNicks, dbot.config.moderators);
allowedNicks = _.union(allowedNicks, dbot.config.power_users);
allowedNicks = _.union(allowedNicks,
_.chain(channel.nicks)
.filter(function(nick) {
return nick.op == true || nick.voice == true;
})
.pluck('name')
.value());
}
if(!_.include(allowedNicks, user.primaryNick) && !_.include(allowedNicks, user.currentNick)) {
callback(false);
if(_.isUndefined(accessNeeded) || accessNeeded == null) {
return callback(true);
} else if(!_.isFunction(accessNeeded)) {
if(_.has(dbot.access, accessNeeded)) {
accessNeeded = dbot.access[accessNeeded];
} else {
if(_.has(dbot.modules, 'nickserv') && this.config.useNickserv == true) {
dbot.api.nickserv.auth(user.server, user.currentNick, function(result, primary) {
if(result == true && primary == user.primaryNick) {
callback(true);
} else {
callback(false);
}
});
} else {
callback(true);
}
return callback(true);
}
}
allowedNicks = accessNeeded(event);
if(!_.include(allowedNicks, user.primaryNick) && !_.include(allowedNicks, user.currentNick)) {
callback(false);
} else {
callback(true);
if(_.has(dbot.modules, 'nickserv') && this.config.useNickserv == true) {
dbot.api.nickserv.auth(user.server, user.currentNick, function(result, primary) {
if(result == true && primary == user.primaryNick) {
callback(true);
} else {
callback(false);
}
});
} else {
callback(true);
}
}
},

View File

@ -58,7 +58,7 @@ var command = function(dbot) {
}
}
this.api.hasAccess(event.rUser, event.channel, commandName, function(hasAccess) {
this.api.hasAccess(event, commandName, function(hasAccess) {
dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) {
dbot.api.ignore.isUserBanned(event.rUser, commandName, function(isBanned) {
if(isBanned) {
@ -114,6 +114,35 @@ var command = function(dbot) {
}.bind(this));
}.bind(this);
this.on = 'PRIVMSG';
this.onLoad = function() {
// Not sure this is the right place for this. Perhaps they should be in
// another file?
dbot.access = {
'admin': function(event) {
return dbot.config.admins;
},
'moderator': function(event) {
return [].concat(dbot.access.admin(event), dbot.config.moderators);
},
'power_user': function(event) {
return [].concat(dbot.access.admin(event), dbot.access.moderator(event), dbot.config.power_users);
},
'voice': function(event) {
return [].concat(dbot.access.admin(event), dbot.access.moderator(event), dbot.access.power_user(event),
_.chain(event.channel.nicks)
.filter(function(nick) {
return nick.op == true || nick.voice == true;
})
.pluck('name')
.value());
}
};
}.bind(this);
};
exports.fetch = function(dbot) {