File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -14,22 +14,38 @@ class Commands {
1414 * @param {function } callback - Callback to command.
1515 */
1616 register ( cmd ) {
17+ if ( ! Commands . isValid ( cmd ) ) {
18+ throw new Error ( `${ cmd } isn't a valid Command!` ) ;
19+ }
20+
1721 this . commands [ cmd . name ] = cmd ;
1822 }
1923
2024 /**
2125 * Checks if a command is set in Commands instance.
22- * @param {string } cmd - The command's name.
26+ * @param {string } cmdName - The command's name.
2327 * @returns {boolean } `True` if the command is set in Commands instance, `False` if not.
2428 */
25- has ( cmd ) {
29+ has ( cmdName ) {
2630 const availableCommands = Object . keys ( this . commands ) ;
27- return availableCommands . includes ( cmd ) ;
31+ return availableCommands . includes ( cmdName ) ;
32+ }
33+
34+ /**
35+ * Checks if a command is valid.
36+ * @param {any } cmd - The command instance.
37+ * @returns {boolean } `True` if the command is valid, `False` if not.
38+ */
39+ static isValid ( cmd ) {
40+ if ( cmd . name && cmd . execute && typeof cmd . execute === 'function' ) {
41+ return true ;
42+ }
43+ return false ;
2844 }
2945
3046 /**
3147 * Calls (executes) a command.
32- * @param {string } cmd - The command's name to be called.
48+ * @param {string } cmdName - The command's name to be called.
3349 * @param {object } data - The data extracted from the message that called the command.
3450 * @param {string } data.command - The command's name extracted from the message.
3551 * @param {string[] } data.args - The args extracted from the message.
You can’t perform that action at this time.
0 commit comments