Skip to content

Commit 3c33408

Browse files
committed
[REFACTOR][BREAKING] makes Commands.js compatible with Commands made with classes
1 parent 23ab10c commit 3c33408

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/build/Commands.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
function isFunction(object) {
2-
return typeof object === 'function';
3-
}
4-
51
/**
62
* Commands wrapper
73
* @param {object} commands - Object that contains the commands.
@@ -17,12 +13,8 @@ class Commands {
1713
* @param {string} name - Command's name.
1814
* @param {function} callback - Callback to command.
1915
*/
20-
set(name, callback) {
21-
if (!isFunction(callback)) {
22-
throw new Error(`${callback} must be a function`);
23-
}
24-
25-
this.commands[name] = callback;
16+
register(cmd) {
17+
this.commands[cmd.name] = cmd;
2618
}
2719

2820
/**
@@ -48,15 +40,15 @@ class Commands {
4840
* @see https://docs.wwebjs.dev/Message.html
4941
* @see https://docs.wwebjs.dev/Client.html
5042
*/
51-
async call(cmd, data, message, client) {
52-
if (!this.has(cmd)) {
53-
throw new Error(`${cmd} is not registered`);
43+
async call(cmdName, data, message, client) {
44+
if (!this.has(cmdName)) {
45+
throw new Error(`${cmdName} is not registered.`);
5446
}
5547

56-
const response = await this.commands[cmd](data, message, client);
57-
58-
if (response) {
59-
message.reply(String(response));
48+
try {
49+
await this.commands[cmdName].execute(data, message, client);
50+
} catch (e) {
51+
message.reply(`❗ ${e.message}`);
6052
}
6153
}
6254
}

src/build/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
module.exports = {
44
Commands: require('./Commands'),
5-
Path: require('./Path'),
65
};

0 commit comments

Comments
 (0)