|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|