From c719020e17cb1c98da55be6cc7efe0e50ab51ffa Mon Sep 17 00:00:00 2001 From: marzavec Date: Sat, 29 Sep 2018 23:44:36 -0700 Subject: Added hooks, modules and cleaned up code --- server/src/managers/commands.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'server/src/managers/commands.js') diff --git a/server/src/managers/commands.js b/server/src/managers/commands.js index fd743fb..a5ef464 100644 --- a/server/src/managers/commands.js +++ b/server/src/managers/commands.js @@ -71,8 +71,9 @@ class CommandManager { command.info.category = category; - if (this._categories.indexOf(category) === -1) + if (this._categories.indexOf(category) === -1) { this._categories.push(category); + } } if (typeof command.init === 'function') { @@ -114,7 +115,7 @@ class CommandManager { /** * Pulls all command names from a passed `category` * - * @param {String} category reference to the newly loaded object + * @param {String} category [Optional] filter return results by this category */ all (category) { return !category ? this._commands : this._commands.filter(c => c.info.category.toLowerCase() === category.toLowerCase()); @@ -148,6 +149,15 @@ class CommandManager { return this._commands.find(c => c.info[key] === value); } + /** + * Runs `initHooks` function on any modules that utilize the event + * + * @param {Object} server main server object + */ + initCommandHooks (server) { + this._commands.filter(c => typeof c.initHooks !== 'undefined').forEach(c => c.initHooks(server)); + } + /** * Finds and executes the requested command, or fails with semi-intelligent error * -- cgit v1.2.1