2013-01-14 17:02:40 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
var api = function(dbot) {
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Does the user have the correct access level to use the command?
|
|
|
|
*/
|
2014-06-04 00:47:52 +02:00
|
|
|
'hasAccess': function(event, command, callback) {
|
|
|
|
var accessNeeded = dbot.commands[command].access,
|
|
|
|
allowedNicks,
|
|
|
|
user = event.rUser;
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2014-06-04 00:47:52 +02:00
|
|
|
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);
|
2013-09-07 19:55:48 +02:00
|
|
|
}
|
2014-06-04 00:47:52 +02:00
|
|
|
}
|
|
|
|
allowedNicks = accessNeeded(event);
|
2013-05-06 23:49:45 +02:00
|
|
|
|
2014-06-04 00:47:52 +02:00
|
|
|
if(!_.include(allowedNicks, user.primaryNick) && !_.include(allowedNicks, user.currentNick)) {
|
|
|
|
callback(false);
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
});
|
2013-04-23 21:07:23 +02:00
|
|
|
} else {
|
2014-06-04 00:47:52 +02:00
|
|
|
callback(true);
|
2013-01-14 17:24:38 +01:00
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
},
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
/**
|
|
|
|
* Apply Regex to event message, store result. Return false if it doesn't
|
|
|
|
* apply.
|
|
|
|
*/
|
|
|
|
'applyRegex': function(commandName, event) {
|
|
|
|
var applies = false;
|
2013-12-29 19:47:31 +01:00
|
|
|
event.message = event.message.substring(1);
|
2013-01-14 17:24:38 +01:00
|
|
|
if(_.has(dbot.commands[commandName], 'regex')) {
|
|
|
|
var cRegex = dbot.commands[commandName].regex;
|
2013-12-29 19:47:31 +01:00
|
|
|
if(_.isArray(cRegex) && cRegex.length === 2) {
|
2013-04-14 15:58:45 +02:00
|
|
|
var q = event.message.valMatch(cRegex[0], cRegex[1]);
|
|
|
|
if(q) {
|
|
|
|
applies = true;
|
|
|
|
event.input = q;
|
|
|
|
}
|
2013-04-14 16:29:14 +02:00
|
|
|
} else {
|
2013-04-14 15:58:45 +02:00
|
|
|
var q = event.message.match(cRegex);
|
|
|
|
if(q) {
|
|
|
|
applies = true;
|
|
|
|
event.input = q;
|
2013-04-14 16:29:14 +02:00
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-01-14 17:02:40 +01:00
|
|
|
applies = true;
|
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
return applies;
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
};
|
2013-01-14 17:02:40 +01:00
|
|
|
};
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return api(dbot);
|
|
|
|
};
|