mirror of
https://github.com/reality/dbot.git
synced 2024-11-23 20:39:25 +01:00
command can use nickserv [#421]
This commit is contained in:
parent
c37e9cded7
commit
8475aa46e8
@ -17,22 +17,24 @@ var api = function(dbot) {
|
||||
/**
|
||||
* Does the user have the correct access level to use the command?
|
||||
*/
|
||||
'hasAccess': function(user, command) {
|
||||
var access = true;
|
||||
'hasAccess': function(server, user, command, callback) {
|
||||
var accessNeeded = dbot.commands[command].access;
|
||||
|
||||
if(accessNeeded == 'admin') {
|
||||
if(!_.include(dbot.config.admins, user)) {
|
||||
access = false;
|
||||
}
|
||||
} else if(accessNeeded == 'moderator') {
|
||||
if(!_.include(dbot.config.moderators, user) &&
|
||||
!_.include(dbot.config.admins, user)) {
|
||||
access = false;
|
||||
if(accessNeeded == 'admin' || accessNeeded == 'moderator') {
|
||||
if(!_.include(dbot.config[accessNeeded + 's'], user)) { // lol
|
||||
callback(false);
|
||||
} else {
|
||||
if(_.has(dbot.modules, 'nickserv') && this.config.useNickserv == true) {
|
||||
dbot.api.nickserv.auth(server, user, function(result) {
|
||||
callback(result);
|
||||
});
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback(true);
|
||||
}
|
||||
|
||||
return access;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -20,41 +20,44 @@ var command = function(dbot) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(this.api.isBanned(event.user, commandName)) {
|
||||
event.reply(dbot.t('command_ban', {'user': event.user}));
|
||||
} else {
|
||||
if(!this.api.isIgnoring(event.user, commandName) &&
|
||||
!this.api.isIgnoring(event.channel, commandName) &&
|
||||
this.api.hasAccess(event.user, commandName) &&
|
||||
dbot.commands[commandName].disabled !== true) {
|
||||
if(this.api.applyRegex(commandName, event)) {
|
||||
try {
|
||||
var command = dbot.commands[commandName];
|
||||
var results = command.apply(dbot.modules[command.module], [event]);
|
||||
if(_.has(command, 'hooks') && results !== false) {
|
||||
_.each(command['hooks'], function(hook) {
|
||||
hook.apply(hook.module, _.values(results));
|
||||
}, this);
|
||||
}
|
||||
} catch(err) {
|
||||
if(dbot.config.debugMode == true) {
|
||||
event.reply('- Error in ' + commandName + ':');
|
||||
event.reply('- Message: ' + err);
|
||||
event.reply('- Top of stack: ' + err.stack.split('\n')[1].trim());
|
||||
}
|
||||
}
|
||||
dbot.save();
|
||||
} else {
|
||||
if(commandName !== '~') {
|
||||
if(_.has(dbot.usage, commandName)) {
|
||||
event.reply('Usage: ' + dbot.usage[commandName]);
|
||||
this.api.hasAccess(event.server, event.user, commandName, function(result) {
|
||||
if(result) {
|
||||
if(!this.api.isIgnoring(event.user, commandName) &&
|
||||
!this.api.isIgnoring(event.channel, commandName) &&
|
||||
dbot.commands[commandName].disabled !== true) {
|
||||
if(this.api.applyRegex(commandName, event)) {
|
||||
try {
|
||||
var command = dbot.commands[commandName];
|
||||
var results = command.apply(dbot.modules[command.module], [event]);
|
||||
if(_.has(command, 'hooks') && results !== false) {
|
||||
_.each(command['hooks'], function(hook) {
|
||||
hook.apply(hook.module, _.values(results));
|
||||
}, this);
|
||||
}
|
||||
} catch(err) {
|
||||
if(dbot.config.debugMode == true) {
|
||||
event.reply('- Error in ' + commandName + ':');
|
||||
event.reply('- Message: ' + err);
|
||||
event.reply('- Top of stack: ' + err.stack.split('\n')[1].trim());
|
||||
}
|
||||
}
|
||||
dbot.save();
|
||||
} else {
|
||||
event.reply(dbot.t('syntax_error'));
|
||||
if(commandName !== '~') {
|
||||
if(_.has(dbot.usage, commandName)) {
|
||||
event.reply('Usage: ' + dbot.usage[commandName]);
|
||||
} else {
|
||||
event.reply(dbot.t('syntax_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
}.bind(this);
|
||||
this.on = 'PRIVMSG';
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"ignorable": false,
|
||||
"help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md",
|
||||
"useNickserv": false,
|
||||
"dbKeys": [ "ignores", "bans" ]
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ var nickserv = function(dbot) {
|
||||
statusRegex = this.config.servers[event.server].matcher,
|
||||
acceptableState = this.config.servers[event.server].acceptableState;
|
||||
|
||||
|
||||
if(event.user == nickserv) {
|
||||
var info = event.params.match(statusRegex);
|
||||
if(info && _.has(this.authStack, event.server)) {
|
||||
|
Loading…
Reference in New Issue
Block a user