js-discord-modularcommand 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modularbutton.d.ts +24 -7
- package/dist/modularbutton.js +28 -6
- package/dist/modularcommand.js +2 -2
- package/dist/modularmodal.d.ts +11 -4
- package/dist/modularmodal.js +15 -1
- package/dist/registercommand.js +2 -2
- package/package.json +1 -1
package/dist/modularbutton.d.ts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* @author vicentefelipechile
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
import { ButtonBuilder
|
|
7
|
-
import { ButtonExecuteFunction } from "./types";
|
|
6
|
+
import { ButtonBuilder } from "discord.js";
|
|
7
|
+
import { ButtonExecuteFunction, LocaleKey } from "./types";
|
|
8
|
+
import ModularCommand from "./modularcommand";
|
|
8
9
|
/**
|
|
9
10
|
* @class ModularButton
|
|
10
11
|
* @description A class to create and manage reusable button components.
|
|
@@ -14,21 +15,37 @@ export default class ModularButton {
|
|
|
14
15
|
buttonObject: ButtonBuilder;
|
|
15
16
|
/** The custom ID for the button, used to identify it in interactions. */
|
|
16
17
|
customId: string;
|
|
17
|
-
/** The
|
|
18
|
-
|
|
18
|
+
/** The base ID for the button, used for localization. */
|
|
19
|
+
buttonId: string;
|
|
20
|
+
/** The command instance to which this modal belongs. */
|
|
21
|
+
command: ModularCommand;
|
|
19
22
|
/** Use other mechanisms to handle button interactions. */
|
|
20
23
|
execute: ButtonExecuteFunction;
|
|
21
24
|
/**
|
|
22
25
|
* @description Creates a new ModularButton instance.
|
|
23
26
|
* @param {string} customId The custom ID for the button. This should be unique within the context of a message.
|
|
24
27
|
*/
|
|
25
|
-
constructor(customId: string);
|
|
28
|
+
constructor(customId: string, command: ModularCommand);
|
|
29
|
+
/**
|
|
30
|
+
* @description Retrieves the underlying ButtonBuilder instance.
|
|
31
|
+
* @returns {ButtonBuilder} The ButtonBuilder instance.
|
|
32
|
+
*/
|
|
33
|
+
getButton(): ButtonBuilder;
|
|
34
|
+
/**
|
|
35
|
+
* @description Retrieves the custom ID of the button.
|
|
36
|
+
* @returns {string} The custom ID of the button.
|
|
37
|
+
*/
|
|
38
|
+
getCustomId(): string;
|
|
26
39
|
/**
|
|
27
|
-
* @deprecated This method is deprecated and will be removed in future versions.
|
|
28
|
-
* Use other mechanisms to handle button interactions.
|
|
29
40
|
* @description Sets the execution function for the button's click event.
|
|
30
41
|
* @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
|
|
31
42
|
* @returns {this} The current ModularButton instance for method chaining.
|
|
32
43
|
*/
|
|
33
44
|
setExecute(executeFunction: ButtonExecuteFunction): this;
|
|
45
|
+
/**
|
|
46
|
+
* @description Builds the button with localized label.
|
|
47
|
+
* @param {LocaleKey} locale The locale object containing localized strings.
|
|
48
|
+
* @returns {ButtonBuilder} The built ButtonBuilder instance with localized label.
|
|
49
|
+
*/
|
|
50
|
+
build(locale: LocaleKey): ButtonBuilder;
|
|
34
51
|
}
|
package/dist/modularbutton.js
CHANGED
|
@@ -18,17 +18,30 @@ class ModularButton {
|
|
|
18
18
|
* @description Creates a new ModularButton instance.
|
|
19
19
|
* @param {string} customId The custom ID for the button. This should be unique within the context of a message.
|
|
20
20
|
*/
|
|
21
|
-
constructor(customId) {
|
|
21
|
+
constructor(customId, command) {
|
|
22
22
|
/** Use other mechanisms to handle button interactions. */
|
|
23
23
|
this.execute = async () => { };
|
|
24
24
|
this.buttonObject = new discord_js_1.ButtonBuilder()
|
|
25
|
-
.setCustomId(customId);
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
25
|
+
.setCustomId(`${command.name}_${customId}`);
|
|
26
|
+
this.command = command;
|
|
27
|
+
this.customId = `${command.name}_${customId}`;
|
|
28
|
+
this.buttonId = customId;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @description Retrieves the underlying ButtonBuilder instance.
|
|
32
|
+
* @returns {ButtonBuilder} The ButtonBuilder instance.
|
|
33
|
+
*/
|
|
34
|
+
getButton() {
|
|
35
|
+
return this.buttonObject;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description Retrieves the custom ID of the button.
|
|
39
|
+
* @returns {string} The custom ID of the button.
|
|
40
|
+
*/
|
|
41
|
+
getCustomId() {
|
|
42
|
+
return this.customId;
|
|
28
43
|
}
|
|
29
44
|
/**
|
|
30
|
-
* @deprecated This method is deprecated and will be removed in future versions.
|
|
31
|
-
* Use other mechanisms to handle button interactions.
|
|
32
45
|
* @description Sets the execution function for the button's click event.
|
|
33
46
|
* @param {ButtonExecuteFunction} executeFunction The function to run when the button is interacted with.
|
|
34
47
|
* @returns {this} The current ModularButton instance for method chaining.
|
|
@@ -37,5 +50,14 @@ class ModularButton {
|
|
|
37
50
|
this.execute = executeFunction;
|
|
38
51
|
return this;
|
|
39
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @description Builds the button with localized label.
|
|
55
|
+
* @param {LocaleKey} locale The locale object containing localized strings.
|
|
56
|
+
* @returns {ButtonBuilder} The built ButtonBuilder instance with localized label.
|
|
57
|
+
*/
|
|
58
|
+
build(locale) {
|
|
59
|
+
this.buttonObject.setLabel(locale[`${this.command.name}.${this.buttonId}`]);
|
|
60
|
+
return this.buttonObject;
|
|
61
|
+
}
|
|
40
62
|
}
|
|
41
63
|
exports.default = ModularButton;
|
package/dist/modularcommand.js
CHANGED
|
@@ -190,10 +190,10 @@ class ModularCommand {
|
|
|
190
190
|
* @return {ModularButton} The created button instance.
|
|
191
191
|
*/
|
|
192
192
|
addButton(customId, execute) {
|
|
193
|
-
const button = new modularbutton_js_1.default(customId);
|
|
193
|
+
const button = new modularbutton_js_1.default(customId, this);
|
|
194
|
+
button.setExecute(execute);
|
|
194
195
|
this.buttons.set(customId, button);
|
|
195
196
|
this.buttonsArray.push(button);
|
|
196
|
-
this.addCustomIDHandler(customId, execute);
|
|
197
197
|
return button;
|
|
198
198
|
}
|
|
199
199
|
}
|
package/dist/modularmodal.d.ts
CHANGED
|
@@ -15,10 +15,7 @@ export default class ModularModal {
|
|
|
15
15
|
modalObject: ModalBuilder;
|
|
16
16
|
/** The unique custom ID for the modal, formatted as `${command.name}_${modalId}`. */
|
|
17
17
|
customId: string;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated This property is deprecated and will be removed in future versions.
|
|
20
|
-
* The base ID for the modal, used for localization.
|
|
21
|
-
*/
|
|
18
|
+
/** The base ID for the modal, used for localization. */
|
|
22
19
|
modalId: string;
|
|
23
20
|
/** A map to store the text input components of the modal. */
|
|
24
21
|
modalInputs: Map<string, TextInputBuilder>;
|
|
@@ -32,6 +29,16 @@ export default class ModularModal {
|
|
|
32
29
|
* @param {ModularCommand} command The command that this modal is associated with.
|
|
33
30
|
*/
|
|
34
31
|
constructor(modalId: string, command: ModularCommand);
|
|
32
|
+
/**
|
|
33
|
+
* @description Retrieves the underlying ModalBuilder instance.
|
|
34
|
+
* @returns {ModalBuilder} The ModalBuilder instance.
|
|
35
|
+
*/
|
|
36
|
+
getModal(): ModalBuilder;
|
|
37
|
+
/**
|
|
38
|
+
* @description Retrieves the custom ID of the modal.
|
|
39
|
+
* @returns {string} The custom ID of the modal.
|
|
40
|
+
*/
|
|
41
|
+
getCustomId(): string;
|
|
35
42
|
/**
|
|
36
43
|
* @description Sets the execution function for the modal's submission event.
|
|
37
44
|
* @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
|
package/dist/modularmodal.js
CHANGED
|
@@ -22,12 +22,26 @@ class ModularModal {
|
|
|
22
22
|
constructor(modalId, command) {
|
|
23
23
|
/** The function to execute when the modal is submitted. */
|
|
24
24
|
this.execute = async () => { };
|
|
25
|
-
this.customId = modalId
|
|
25
|
+
this.customId = `${command.name}_${modalId}`;
|
|
26
26
|
this.modalId = modalId;
|
|
27
27
|
this.command = command;
|
|
28
28
|
this.modalObject = new discord_js_1.ModalBuilder().setCustomId(this.customId);
|
|
29
29
|
this.modalInputs = new Map();
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* @description Retrieves the underlying ModalBuilder instance.
|
|
33
|
+
* @returns {ModalBuilder} The ModalBuilder instance.
|
|
34
|
+
*/
|
|
35
|
+
getModal() {
|
|
36
|
+
return this.modalObject;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description Retrieves the custom ID of the modal.
|
|
40
|
+
* @returns {string} The custom ID of the modal.
|
|
41
|
+
*/
|
|
42
|
+
getCustomId() {
|
|
43
|
+
return this.customId;
|
|
44
|
+
}
|
|
31
45
|
/**
|
|
32
46
|
* @description Sets the execution function for the modal's submission event.
|
|
33
47
|
* @param {ModalExecuteFunction} executeFunction The function to run when the modal is submitted.
|
package/dist/registercommand.js
CHANGED
|
@@ -146,7 +146,7 @@ function createModalExecutor(command) {
|
|
|
146
146
|
if (command.modals.size === 0)
|
|
147
147
|
return undefined;
|
|
148
148
|
return async (interaction) => {
|
|
149
|
-
const modalObject = command.modals.get(interaction.customId);
|
|
149
|
+
const modalObject = command.modals.get(interaction.customId.split('_')[1]);
|
|
150
150
|
if (!modalObject)
|
|
151
151
|
return;
|
|
152
152
|
const args = {};
|
|
@@ -170,7 +170,7 @@ function createButtonExecutor(command) {
|
|
|
170
170
|
if (command.buttons.size === 0)
|
|
171
171
|
return undefined;
|
|
172
172
|
return async (interaction) => {
|
|
173
|
-
const buttonObject = command.buttons.get(interaction.customId);
|
|
173
|
+
const buttonObject = command.buttons.get(interaction.customId.split('_')[1]);
|
|
174
174
|
if (!buttonObject)
|
|
175
175
|
return;
|
|
176
176
|
await buttonObject.execute({
|