2013-01-14 17:02:40 +01:00
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
var api = function(dbot) {
|
|
|
|
return {
|
|
|
|
'isBanned': function(user, command) {
|
|
|
|
var banned = false;
|
2013-03-21 11:34:33 +01:00
|
|
|
if(_.has(dbot.db.bans, user)) {
|
|
|
|
if(_.include(dbot.db.bans[user], command) ||
|
|
|
|
_.include(dbot.db.bans[user], dbot.commands[command].module) ||
|
|
|
|
_.include(dbot.db.bans[user], '*')) {
|
2013-01-14 17:24:38 +01:00
|
|
|
banned = true;
|
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
2013-01-14 17:24:38 +01:00
|
|
|
return banned;
|
|
|
|
},
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
/**
|
|
|
|
* Does the user have the correct access level to use the command?
|
|
|
|
*/
|
|
|
|
'hasAccess': function(user, command) {
|
|
|
|
var access = true;
|
|
|
|
var accessNeeded = dbot.commands[command].access;
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
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;
|
|
|
|
}
|
2013-01-14 17:02:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
return access;
|
|
|
|
},
|
2013-01-14 17:02:40 +01:00
|
|
|
|
2013-01-14 17:24:38 +01:00
|
|
|
/**
|
2013-01-27 17:48:14 +01:00
|
|
|
* Is item (user or channel) ignoring command?
|
2013-01-14 17:24:38 +01:00
|
|
|
*/
|
2013-01-27 17:48:14 +01:00
|
|
|
'isIgnoring': function(item, command) {
|
2013-01-14 17:24:38 +01:00
|
|
|
var module = dbot.commands[command].module;
|
2013-01-27 17:48:14 +01:00
|
|
|
return (_.has(dbot.db.ignores, item) &&
|
2013-03-21 11:34:33 +01:00
|
|
|
(_.include(dbot.db.ignores[item], module) ||
|
|
|
|
_.include(dbot.db.ignores[item], '*')));
|
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;
|
|
|
|
if(_.has(dbot.commands[commandName], 'regex')) {
|
|
|
|
var cRegex = dbot.commands[commandName].regex;
|
2013-04-14 15:58:45 +02:00
|
|
|
if(_.isArray(cRegex) && cRegex.length == 2) {
|
|
|
|
var q = event.message.valMatch(cRegex[0], cRegex[1]);
|
|
|
|
if(q) {
|
|
|
|
applies = true;
|
|
|
|
event.input = q;
|
|
|
|
}
|
|
|
|
} else if {
|
|
|
|
var q = event.message.match(cRegex);
|
|
|
|
if(q) {
|
|
|
|
applies = true;
|
|
|
|
event.input = q;
|
|
|
|
]
|
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-15 18:23:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'addHook': function(command, callback) {
|
|
|
|
console.log('adding hook');
|
|
|
|
if(_.has(dbot.commands, command)) {
|
|
|
|
if(!_.has(dbot.commands[command], 'hooks')) {
|
|
|
|
dbot.commands[command].hooks = [];
|
|
|
|
}
|
|
|
|
dbot.commands[command].hooks.push(callback);
|
|
|
|
}
|
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);
|
|
|
|
};
|