2012-03-10 16:28:42 +01:00
|
|
|
// Module which handles the command execution syntax for DBot. Not much is going
|
|
|
|
// to work without this.
|
|
|
|
var command = function(dbot) {
|
|
|
|
var dbot = dbot;
|
|
|
|
|
|
|
|
return {
|
2012-03-12 14:45:52 +01:00
|
|
|
'onLoad': function() {
|
|
|
|
return {
|
2012-04-15 22:43:02 +02:00
|
|
|
'~ignore': function(data, params) {
|
|
|
|
var ignorableModules = [];
|
|
|
|
for(var i=0;i<dbot.modules.length;i++) {
|
|
|
|
if(dbot.modules[i].ignorable != null && dbot.modules[i].ignorable == true) {
|
|
|
|
ignorableModules.push(dbot.modules[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(params[1] == undefined) {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel,
|
|
|
|
dbot.t('ignore_usage', {'user': data.user, 'modules': ignorableModules.join(', ')}));
|
2012-04-15 22:43:02 +02:00
|
|
|
} else {
|
|
|
|
if(dbot.moduleNames.include(params[1])) {
|
|
|
|
if(!dbot.db.ignores.hasOwnProperty(data.user)) {
|
|
|
|
dbot.db.ignores[data.user] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dbot.db.ignores[data.user].include(params[1])) {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('already_ignoring', {'user': data.user}));
|
2012-04-15 22:43:02 +02:00
|
|
|
} else {
|
|
|
|
dbot.db.ignores[data.user].push(params[1]);
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('ignored', {'user': data.user, 'module': params[1]}));
|
2012-04-15 22:43:02 +02:00
|
|
|
}
|
|
|
|
} else {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('invalid_ignore', {'user': data.user}));
|
2012-04-15 22:43:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'~unignore': function(data, params) {
|
|
|
|
var ignoredModules = [];
|
|
|
|
if(dbot.db.ignores.hasOwnProperty(data.user)) {
|
|
|
|
ignoredModules = dbot.db.ignores[data.user];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(params[1] == undefined) {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel,
|
|
|
|
dbot.t('unignore_usage', {'user': data.user, 'modules': ignoredModules.join(', ')}));
|
2012-04-15 22:43:02 +02:00
|
|
|
} else {
|
|
|
|
if(ignoredModules.include(params[1]) == false) {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('invalid_unignore', {'user': data.user}));
|
2012-04-15 22:43:02 +02:00
|
|
|
} else {
|
|
|
|
dbot.db.ignores[data.user].splice(dbot.db.ignores[data.user].indexOf(params[1]), 1);
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('unignored', {'user': data.user, 'module': params[1]}));
|
2012-04-15 22:43:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-12 14:45:52 +01:00
|
|
|
};
|
|
|
|
},
|
2012-04-14 07:06:40 +02:00
|
|
|
|
2012-03-10 16:28:42 +01:00
|
|
|
'listener': function(data) {
|
2012-03-14 16:47:00 +01:00
|
|
|
var params = data.message.split(' ');
|
2012-03-10 16:28:42 +01:00
|
|
|
if(data.channel == dbot.name) data.channel = data.user;
|
2012-04-15 21:04:34 +02:00
|
|
|
|
2012-03-12 14:49:55 +01:00
|
|
|
if(dbot.commands.hasOwnProperty(params[0])) {
|
2012-03-10 16:28:42 +01:00
|
|
|
if((dbot.db.bans.hasOwnProperty(params[0]) &&
|
2012-03-12 14:45:52 +01:00
|
|
|
dbot.db.bans[params[0]].include(data.user)) || dbot.db.bans['*'].include(data.user)) {
|
2012-05-19 17:48:01 +02:00
|
|
|
dbot.say(data.channel, dbot.t('command_ban', {'user': data.user}));
|
2012-03-12 14:45:52 +01:00
|
|
|
} else {
|
2012-04-15 22:43:02 +02:00
|
|
|
var commandBelongsTo = dbot.commandMap[params[0]];
|
|
|
|
if(dbot.db.ignores.hasOwnProperty(data.user) &&
|
|
|
|
dbot.db.ignores[data.user].include(commandBelongsTo)) {
|
|
|
|
// do nothing
|
|
|
|
} else {
|
|
|
|
dbot.commands[params[0]](data, params);
|
|
|
|
dbot.save();
|
|
|
|
}
|
2012-03-10 16:28:42 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var q = data.message.valMatch(/^~([\d\w\s-]*)/, 2);
|
|
|
|
if(q) {
|
|
|
|
if(dbot.db.bans['*'].include(data.user)) {
|
2012-05-19 17:48:01 +02:00
|
|
|
dbot.say(data.channel, dbot.t('command_ban', {'user': data.user}));
|
2012-03-10 16:28:42 +01:00
|
|
|
} else {
|
|
|
|
q[1] = q[1].trim();
|
|
|
|
key = dbot.cleanNick(q[1])
|
2012-04-16 00:26:14 +02:00
|
|
|
if(dbot.db.quoteArrs.hasOwnProperty(key) && dbot.moduleNames.include('quotes') &&
|
|
|
|
(dbot.db.ignores.hasOwnProperty(data.user) &&
|
2012-04-16 00:27:14 +02:00
|
|
|
dbot.db.ignores[data.user].include('quotes')) == false) {
|
2012-03-14 14:59:26 +01:00
|
|
|
var params = ['~q'];
|
|
|
|
key.split(' ').each((function(word) {
|
|
|
|
this.push(word);
|
|
|
|
}).bind(params));
|
|
|
|
data.message = params.join(' ');
|
|
|
|
dbot.commands[params[0]](data, params);
|
|
|
|
dbot.save();
|
2012-03-10 16:28:42 +01:00
|
|
|
} else {
|
|
|
|
// See if it's similar to anything
|
|
|
|
var winnerDistance = Infinity;
|
|
|
|
var winner = false;
|
|
|
|
for(var commandName in dbot.commands) {
|
|
|
|
var distance = String.prototype.distance(params[0], commandName);
|
|
|
|
if(distance < winnerDistance) {
|
|
|
|
winner = commandName;
|
|
|
|
winnerDistance = distance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(winnerDistance < 3) {
|
2012-05-19 18:36:21 +02:00
|
|
|
dbot.say(data.channel, dbot.t('command_typo', {'command': winner}));
|
2012-03-10 16:28:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-15 22:43:02 +02:00
|
|
|
'on': 'PRIVMSG',
|
|
|
|
|
|
|
|
'name': 'command',
|
|
|
|
|
|
|
|
'ignorable': false
|
2012-03-10 16:28:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return command(dbot);
|
|
|
|
};
|
|
|
|
|