mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 11:42:36 +01:00
first step of [#616]
This commit is contained in:
parent
58b9e430ad
commit
51426264d6
@ -5,28 +5,21 @@ 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(_.isUndefined(accessNeeded) || accessNeeded == null) {
|
||||
return callback(true);
|
||||
} else if(!_.isFunction(accessNeeded)) {
|
||||
if(_.has(dbot.access, accessNeeded)) {
|
||||
accessNeeded = dbot.access[accessNeeded];
|
||||
} else {
|
||||
return callback(true);
|
||||
}
|
||||
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());
|
||||
}
|
||||
allowedNicks = accessNeeded(event);
|
||||
|
||||
if(!_.include(allowedNicks, user.primaryNick) && !_.include(allowedNicks, user.currentNick)) {
|
||||
callback(false);
|
||||
@ -43,9 +36,6 @@ var api = function(dbot) {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user