initial support for optional command prefix. module commands can currently either use ~command or just command as key, since module loader implements legacy support by shifting the key. there may be a couple of bugs too if there are any recursive commands

This commit is contained in:
reality 2013-12-29 18:13:59 +00:00
parent 6d28aa272b
commit 6204df19c0
5 changed files with 21 additions and 8 deletions

View File

@ -166,6 +166,8 @@ var commands = function(dbot) {
var configPath = event.input[1], var configPath = event.input[1],
newOption = event.input[2]; newOption = event.input[2];
event.reply(event.input[1]);
if(!_.include(noChangeConfig, configPath)) { if(!_.include(noChangeConfig, configPath)) {
this.internalAPI.getCurrentConfig(configPath, function(config) { this.internalAPI.getCurrentConfig(configPath, function(config) {
if(config !== null) { if(config !== null) {

View File

@ -12,9 +12,10 @@ var command = function(dbot) {
*/ */
this.listener = function(event) { this.listener = function(event) {
var commandName = event.params[0]; var commandName = event.params[0];
if(commandName.charAt(0) != '~') { if(commandName.charAt(0) != this.config.commandPrefix || this.config.passiveMode == true) {
return; return;
} }
commandName = commandName.substring(1);
if(!_.has(dbot.commands, commandName)) { if(!_.has(dbot.commands, commandName)) {
if(_.has(dbot.modules, 'quotes')) { if(_.has(dbot.modules, 'quotes')) {
var key = event.message.substring(1); var key = event.message.substring(1);
@ -23,7 +24,7 @@ var command = function(dbot) {
if(quote) { if(quote) {
event.reply(key + ': ' + quote); event.reply(key + ': ' + quote);
} else if(_.has(dbot.modules, 'spelling')) { } else if(_.has(dbot.modules, 'spelling')) {
var commands = _.keys(dbot.commands) var commands = _.keys(dbot.commands),
winner = false, winner = false,
closestMatch = Infinity; closestMatch = Infinity;
@ -55,7 +56,7 @@ var command = function(dbot) {
} }
else if(_.has(dbot.modules, 'quotes')) { else if(_.has(dbot.modules, 'quotes')) {
commandName = '~'; commandName = this.config.commandPrefix;
} else { } else {
return; return;
} }
@ -65,7 +66,7 @@ var command = function(dbot) {
dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) { dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) {
dbot.api.ignore.isUserBanned(event.rUser, commandName, function(isBanned) { dbot.api.ignore.isUserBanned(event.rUser, commandName, function(isBanned) {
if(isBanned) { if(isBanned) {
if(this.config.banOutput && commandName != '~') { if(this.config.banOutput && commandName != this.config.commandPrefix) {
event.reply(dbot.t('command_ban', {'user': event.user})); event.reply(dbot.t('command_ban', {'user': event.user}));
} }
} else if(!hasAccess) { } else if(!hasAccess) {
@ -100,10 +101,10 @@ var command = function(dbot) {
}); });
} }
} }
if(!_.include(['~reload', '~load', '~unload', '~setconfig'], commandName)) dbot.api.event.emit('command', [ event ]); if(!_.include(['reload', 'load', 'unload', 'setconfig'], commandName)) dbot.api.event.emit('command', [ event ]);
dbot.save(); dbot.save();
} else { } else {
if(commandName !== '~') { if(commandName !== this.config.commandPrefix) {
if(_.has(dbot.usage, commandName)) { if(_.has(dbot.usage, commandName)) {
event.reply('Usage: ' + dbot.usage[commandName]); event.reply('Usage: ' + dbot.usage[commandName]);
} else { } else {

View File

@ -3,7 +3,7 @@ var _ = require('underscore')._,
var commands = function(dbot) { var commands = function(dbot) {
return { return {
'~usage': function(event) { 'usage': function(event) {
var commandName = event.params[1]; var commandName = event.params[1];
if(_.has(dbot.usage, commandName)) { if(_.has(dbot.usage, commandName)) {
event.reply(dbot.t('usage', { event.reply(dbot.t('usage', {

View File

@ -3,5 +3,7 @@
"dependencies": [ "event", "ignore", "users" ], "dependencies": [ "event", "ignore", "users" ],
"useNickserv": false, "useNickserv": false,
"accessOutput": false, "accessOutput": false,
"banOutput": false "banOutput": false,
"passiveMode": false,
"commandPrefix": "~"
} }

8
run.js
View File

@ -316,6 +316,14 @@ DBot.prototype.reloadModules = function() {
} }
} }
}, this); }, this);
// Legacy fix for ~ command prefix
_.each(this.commands, function(command, cName) {
if(cName.charAt(0) == '~') {
delete this.commands[cName];
this.commands[cName.substring(1)] = command;
}
}, this);
}.bind(this)); }.bind(this));
this.save(); this.save();