2012-05-19 20:14:07 +02:00
|
|
|
/**
|
|
|
|
* Module Name: Command
|
|
|
|
* Description: An essential module which maps PRIVMSG input to an appropriate
|
|
|
|
* command and then runs that command, given the user isn't banned from or
|
|
|
|
* ignoring that command.
|
|
|
|
*/
|
2012-03-10 16:28:42 +01:00
|
|
|
var command = function(dbot) {
|
|
|
|
var dbot = dbot;
|
|
|
|
|
2012-05-19 20:14:07 +02:00
|
|
|
/**
|
|
|
|
* Is user banned from using command?
|
|
|
|
*/
|
|
|
|
var is_banned = function(user, command) {
|
|
|
|
var banned = false;
|
|
|
|
if(dbot.db.bans.hasOwnProperty(command)) {
|
|
|
|
if(dbot.db.bans[command].include(user) || dbot.db.bans['*'].include(user)) {
|
|
|
|
banned = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return banned;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is user ignoring command?
|
|
|
|
*/
|
|
|
|
var is_ignoring = function(user, command) {
|
|
|
|
var module = dbot.commandMap[command];
|
|
|
|
var ignoring = false;
|
|
|
|
if(dbot.db.ignores.hasOwnProperty(user) && dbot.db.ignores[user].include(module)) {
|
|
|
|
ignoring = true;
|
|
|
|
}
|
|
|
|
return ignoring;
|
|
|
|
}
|
2012-04-15 22:43:02 +02:00
|
|
|
|
2012-05-19 20:14:07 +02:00
|
|
|
return {
|
|
|
|
'name': 'command',
|
2012-04-14 07:06:40 +02:00
|
|
|
|
2012-05-19 20:14:07 +02:00
|
|
|
/**
|
|
|
|
* Run the appropriate command given the input.
|
|
|
|
*/
|
|
|
|
'listener': function(event) {
|
|
|
|
var command_name = event.params[0];
|
|
|
|
if(dbot.commands.hasOwnProperty(command_name)) {
|
|
|
|
if(is_banned(event.user, command_name)) {
|
|
|
|
event.reply(dbot.t('command_ban', {'user': event.user}));
|
2012-03-12 14:45:52 +01:00
|
|
|
} else {
|
2012-05-19 20:14:07 +02:00
|
|
|
if(!is_ignoring(event.user, command_name)) {
|
|
|
|
dbot.commands[command_name](event);
|
2012-04-15 22:43:02 +02:00
|
|
|
dbot.save();
|
|
|
|
}
|
2012-03-10 16:28:42 +01:00
|
|
|
}
|
2012-05-19 20:14:07 +02:00
|
|
|
}
|
2012-03-10 16:28:42 +01:00
|
|
|
},
|
|
|
|
|
2012-04-15 22:43:02 +02:00
|
|
|
'on': 'PRIVMSG',
|
|
|
|
'ignorable': false
|
2012-03-10 16:28:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return command(dbot);
|
|
|
|
};
|
|
|
|
|