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 {
14
14
* @param {function } callback - Callback to command.
15
15
*/
16
16
register ( cmd ) {
17
+ if ( ! Commands . isValid ( cmd ) ) {
18
+ throw new Error ( `${ cmd } isn't a valid Command!` ) ;
19
+ }
20
+
17
21
this . commands [ cmd . name ] = cmd ;
18
22
}
19
23
20
24
/**
21
25
* 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.
23
27
* @returns {boolean } `True` if the command is set in Commands instance, `False` if not.
24
28
*/
25
- has ( cmd ) {
29
+ has ( cmdName ) {
26
30
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 ;
28
44
}
29
45
30
46
/**
31
47
* 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.
33
49
* @param {object } data - The data extracted from the message that called the command.
34
50
* @param {string } data.command - The command's name extracted from the message.
35
51
* @param {string[] } data.args - The args extracted from the message.
You can’t perform that action at this time.
0 commit comments