Skip to content

Commit b8a2e76

Browse files
committed
[DOCS] documents some files in the 'build' folder
1 parent 4028551 commit b8a2e76

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/build/Commands.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ function isFunction(object) {
22
return typeof object === 'function';
33
}
44

5+
/**
6+
* Commands wrapper
7+
* @param {object} commands - Object that contains the commands.
8+
* @param {object} commands.* - A command. The key and value must be, respectively, the command name and a callback function for the command.
9+
*/
510
class Commands {
611
constructor() {
712
this.commands = {};
813
}
914

15+
/**
16+
* Sets a command in Commands instance.
17+
* @param {string} name - Command's name.
18+
* @param {function} callback - Callback to command.
19+
*/
1020
set(name, callback) {
1121
if (!isFunction(callback)) {
1222
throw new Error(`${callback} must be a function`);
@@ -15,11 +25,29 @@ class Commands {
1525
this.commands[name] = callback;
1626
}
1727

28+
/**
29+
* Checks if a command is set in Commands instance.
30+
* @param {string} cmd - The command's name.
31+
* @returns {boolean} `True` if the command is set in Commands instance, `False` if not.
32+
*/
1833
has(cmd) {
1934
const availableCommands = Object.keys(this.commands);
2035
return availableCommands.includes(cmd);
2136
}
2237

38+
/**
39+
* Calls (executes) a command.
40+
* @param {string} cmd - The command's name to be called.
41+
* @param {object} data - The data extracted from the message that called the command.
42+
* @param {string} data.command - The command's name extracted from the message.
43+
* @param {string[]} data.args - The args extracted from the message.
44+
* @param {object} data.kwargs - The kwargs extracted from the message.
45+
* @param {string} data.text - The text extracted from the message. This text NOT includes command's name, args and kwargs.
46+
* @param {Message} message - The message that called the command.
47+
* @param {Session} client - The whatsapp web session.
48+
* @see https://docs.wwebjs.dev/Message.html
49+
* @see https://docs.wwebjs.dev/Client.html
50+
*/
2351
async call(cmd, data, message, client) {
2452
if (!this.has(cmd)) {
2553
throw new Error(`${cmd} is not registered`);

0 commit comments

Comments
 (0)