Browse Source

Fix broken command lookup

* Migrate to helpAndUsage templates for standard help
pull/10/head
Drew Short 5 years ago
parent
commit
4c16d8161e
  1. 28
      bot/module/abstract.js
  2. 2
      bot/module/admin.js
  3. 2
      bot/module/giphy.js

28
bot/module/abstract.js

@ -17,6 +17,12 @@ class AbstractModule {
*/
description = "Base Module That All Other Modules Extend";
/*
A helpful multiline string that defines the module usage
*/
helpAndUsage = `Example: !abstract_module <command>
!abstract_module <boo> : scares people`
/*
The exported command used to invoke the module directly.
*/
@ -40,15 +46,17 @@ class AbstractModule {
this.name = name;
this.description = description;
this.command = command;
this._recognizedCommands = new Map();
this._recognizedCommands = [];
this._recognizedCommandMap = new Map();
}
addRecognizedCommand(command, methodName) {
this._recognizedCommands.set(command, methodName)
this._recognizedCommands.push(command);
this._recognizedCommandMap.set(command, methodName);
}
getRecognizedCommands() {
return this._recognizedCommands.keys();
return this._recognizedCommandMap.keys();
}
/**
@ -69,7 +77,7 @@ class AbstractModule {
}
logger.debug("Attempting to call %s with %s", command, args);
let responseMessage = this.processMessage(command, args);
let responseMessage = this.processMessage(command, ...args);
callback(
room,
@ -81,16 +89,16 @@ class AbstractModule {
Call the command method with the args
*/
processMessage(command, ...args) {
if (command in this._recognizedCommands) {
logger.debug("Calling %s with %s", this._recognizedCommands.get(command), args);
return this[this._recognizedCommands.get(command)](...args);
if (this._recognizedCommands.includes(command)) {
logger.debug("Calling %s with %s", this._recognizedCommandMap.get(command), args);
return this[this._recognizedCommandMap.get(command)](...args);
} else {
if (this.defaultCommand != null) {
logger.debug("Attempting to use default command %s", this.defaultCommand);
try {
let newArgs = [command].concat(...args);
logger.debug("Calling %s with %s", this._recognizedCommands.get(this.defaultCommand), newArgs);
return this[this._recognizedCommands.get(this.defaultCommand)](...newArgs);
logger.debug("Calling %s with %s", this._recognizedCommandMap.get(this.defaultCommand), newArgs);
return this[this._recognizedCommandMap.get(this.defaultCommand)](...newArgs);
} catch (e) {
logger.error("Error while calling default command %s %s", this.defaultCommand, e);
return this.cmd_help();
@ -108,7 +116,7 @@ class AbstractModule {
return basic help information,.
*/
cmd_help(...args) {
return message.createBasic(this.name + " HELP!");
return message.createBasic(this.helpAndUsage);
}
}

2
bot/module/admin.js

@ -11,6 +11,8 @@ class AdminModule extends AbstractModule {
"Support administration tasks",
"admin"
);
this.helpAndUsage = `Usage: admin <command>
...`
}
}

2
bot/module/giphy.js

@ -11,6 +11,8 @@ class GiphyModule extends AbstractModule {
"Insert Giphy Links/Media",
"giphy"
);
this.helpAndUsage = `Usage: !giphy itsworking
...`
}
}
Loading…
Cancel
Save