command can use nickserv [#421]

This commit is contained in:
reality 2013-04-23 19:07:23 +00:00
parent c37e9cded7
commit 8475aa46e8
4 changed files with 47 additions and 40 deletions

View File

@ -17,22 +17,24 @@ var api = function(dbot) {
/** /**
* Does the user have the correct access level to use the command? * Does the user have the correct access level to use the command?
*/ */
'hasAccess': function(user, command) { 'hasAccess': function(server, user, command, callback) {
var access = true;
var accessNeeded = dbot.commands[command].access; var accessNeeded = dbot.commands[command].access;
if(accessNeeded == 'admin') { if(accessNeeded == 'admin' || accessNeeded == 'moderator') {
if(!_.include(dbot.config.admins, user)) { if(!_.include(dbot.config[accessNeeded + 's'], user)) { // lol
access = false; callback(false);
} } else {
} else if(accessNeeded == 'moderator') { if(_.has(dbot.modules, 'nickserv') && this.config.useNickserv == true) {
if(!_.include(dbot.config.moderators, user) && dbot.api.nickserv.auth(server, user, function(result) {
!_.include(dbot.config.admins, user)) { callback(result);
access = false; });
} else {
callback(true);
}
} }
} else {
callback(true);
} }
return access;
}, },
/** /**

View File

@ -20,41 +20,44 @@ var command = function(dbot) {
return; return;
} }
} }
if(this.api.isBanned(event.user, commandName)) { if(this.api.isBanned(event.user, commandName)) {
event.reply(dbot.t('command_ban', {'user': event.user})); event.reply(dbot.t('command_ban', {'user': event.user}));
} else { } else {
if(!this.api.isIgnoring(event.user, commandName) && this.api.hasAccess(event.server, event.user, commandName, function(result) {
!this.api.isIgnoring(event.channel, commandName) && if(result) {
this.api.hasAccess(event.user, commandName) && if(!this.api.isIgnoring(event.user, commandName) &&
dbot.commands[commandName].disabled !== true) { !this.api.isIgnoring(event.channel, commandName) &&
if(this.api.applyRegex(commandName, event)) { dbot.commands[commandName].disabled !== true) {
try { if(this.api.applyRegex(commandName, event)) {
var command = dbot.commands[commandName]; try {
var results = command.apply(dbot.modules[command.module], [event]); var command = dbot.commands[commandName];
if(_.has(command, 'hooks') && results !== false) { var results = command.apply(dbot.modules[command.module], [event]);
_.each(command['hooks'], function(hook) { if(_.has(command, 'hooks') && results !== false) {
hook.apply(hook.module, _.values(results)); _.each(command['hooks'], function(hook) {
}, this); hook.apply(hook.module, _.values(results));
} }, this);
} catch(err) { }
if(dbot.config.debugMode == true) { } catch(err) {
event.reply('- Error in ' + commandName + ':'); if(dbot.config.debugMode == true) {
event.reply('- Message: ' + err); event.reply('- Error in ' + commandName + ':');
event.reply('- Top of stack: ' + err.stack.split('\n')[1].trim()); event.reply('- Message: ' + err);
} event.reply('- Top of stack: ' + err.stack.split('\n')[1].trim());
} }
dbot.save(); }
} else { dbot.save();
if(commandName !== '~') {
if(_.has(dbot.usage, commandName)) {
event.reply('Usage: ' + dbot.usage[commandName]);
} else { } 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); }.bind(this);
this.on = 'PRIVMSG'; this.on = 'PRIVMSG';

View File

@ -1,5 +1,6 @@
{ {
"ignorable": false, "ignorable": false,
"help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md", "help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md",
"useNickserv": false,
"dbKeys": [ "ignores", "bans" ] "dbKeys": [ "ignores", "bans" ]
} }

View File

@ -18,6 +18,7 @@ var nickserv = function(dbot) {
statusRegex = this.config.servers[event.server].matcher, statusRegex = this.config.servers[event.server].matcher,
acceptableState = this.config.servers[event.server].acceptableState; acceptableState = this.config.servers[event.server].acceptableState;
if(event.user == nickserv) { if(event.user == nickserv) {
var info = event.params.match(statusRegex); var info = event.params.match(statusRegex);
if(info && _.has(this.authStack, event.server)) { if(info && _.has(this.authStack, event.server)) {