From 6204df19c01c5439b75d8beb7016363d7a342617 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 29 Dec 2013 18:13:59 +0000 Subject: [PATCH] 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 --- modules/admin/commands.js | 2 ++ modules/command/command.js | 13 +++++++------ modules/command/commands.js | 2 +- modules/command/config.json | 4 +++- run.js | 8 ++++++++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/modules/admin/commands.js b/modules/admin/commands.js index 5d4a730..040b53a 100644 --- a/modules/admin/commands.js +++ b/modules/admin/commands.js @@ -166,6 +166,8 @@ var commands = function(dbot) { var configPath = event.input[1], newOption = event.input[2]; + event.reply(event.input[1]); + if(!_.include(noChangeConfig, configPath)) { this.internalAPI.getCurrentConfig(configPath, function(config) { if(config !== null) { diff --git a/modules/command/command.js b/modules/command/command.js index 98cafc8..3fc51b9 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -12,9 +12,10 @@ var command = function(dbot) { */ this.listener = function(event) { var commandName = event.params[0]; - if(commandName.charAt(0) != '~') { + if(commandName.charAt(0) != this.config.commandPrefix || this.config.passiveMode == true) { return; } + commandName = commandName.substring(1); if(!_.has(dbot.commands, commandName)) { if(_.has(dbot.modules, 'quotes')) { var key = event.message.substring(1); @@ -23,7 +24,7 @@ var command = function(dbot) { if(quote) { event.reply(key + ': ' + quote); } else if(_.has(dbot.modules, 'spelling')) { - var commands = _.keys(dbot.commands) + var commands = _.keys(dbot.commands), winner = false, closestMatch = Infinity; @@ -55,7 +56,7 @@ var command = function(dbot) { } else if(_.has(dbot.modules, 'quotes')) { - commandName = '~'; + commandName = this.config.commandPrefix; } else { return; } @@ -65,7 +66,7 @@ var command = function(dbot) { dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) { dbot.api.ignore.isUserBanned(event.rUser, commandName, function(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})); } } 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(); } else { - if(commandName !== '~') { + if(commandName !== this.config.commandPrefix) { if(_.has(dbot.usage, commandName)) { event.reply('Usage: ' + dbot.usage[commandName]); } else { diff --git a/modules/command/commands.js b/modules/command/commands.js index 6fe31f8..1769f86 100644 --- a/modules/command/commands.js +++ b/modules/command/commands.js @@ -3,7 +3,7 @@ var _ = require('underscore')._, var commands = function(dbot) { return { - '~usage': function(event) { + 'usage': function(event) { var commandName = event.params[1]; if(_.has(dbot.usage, commandName)) { event.reply(dbot.t('usage', { diff --git a/modules/command/config.json b/modules/command/config.json index 9374a66..95edfab 100644 --- a/modules/command/config.json +++ b/modules/command/config.json @@ -3,5 +3,7 @@ "dependencies": [ "event", "ignore", "users" ], "useNickserv": false, "accessOutput": false, - "banOutput": false + "banOutput": false, + "passiveMode": false, + "commandPrefix": "~" } diff --git a/run.js b/run.js index f1a1683..b4ab0c2 100644 --- a/run.js +++ b/run.js @@ -316,6 +316,14 @@ DBot.prototype.reloadModules = function() { } } }, 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)); this.save();