Skip to content

Commit

Permalink
add custom id field
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Nov 16, 2024
1 parent 76879b5 commit 01d44a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/structures/ModalResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import util from "util";
*/
class ModalResponse extends Interaction {
#values;
#custom_id;
/**
* Creates a modal submitted interaction structure.
* @param {Client} client The client instance.
Expand All @@ -23,6 +24,13 @@ class ModalResponse extends Interaction {
if (typeof data !== "object")
throw new TypeError("GLUON: Data must be an object");

/**
* The custom id of the button.
* @type {String}
* @private
*/
this.#custom_id = data.data.custom_id;

/**
* The entered modal values.
* @type {Array<Object>}
Expand All @@ -31,6 +39,16 @@ class ModalResponse extends Interaction {
this.#values = data.data.components[0].components;
}

/**
* The custom id of the modal.
* @type {String}
* @readonly
* @public
*/
get customId() {
return this.#custom_id;
}

/**
* The entered modal values.
* @type {Array<Object>}
Expand Down Expand Up @@ -72,13 +90,15 @@ class ModalResponse extends Interaction {
return {
...super.toJSON(format),
values: this.values,
custom_id: this.customId,
};
}
case TO_JSON_TYPES_ENUM.DISCORD_FORMAT:
default: {
return {
...super.toJSON(format),
data: {
custom_id: this.customId,
components: [
{
components: this.values,
Expand Down
1 change: 1 addition & 0 deletions src/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ export const TEST_DATA = {
id: "123451189012345678",
type: 5,
data: {
custom_id: "test",
components: [
{
type: 1,
Expand Down
4 changes: 4 additions & 0 deletions test/structures/ModalResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe("ModalResponse", function () {
expect(modalResponse).to.have.property("guildId");
expect(modalResponse).to.have.property("channelId");
expect(modalResponse).to.have.property("member");
expect(modalResponse).to.have.property("customId");
expect(modalResponse).to.have.property("values");
expect(modalResponse).to.have.property("guild");
expect(modalResponse).to.have.property("channel");
Expand Down Expand Up @@ -101,6 +102,7 @@ describe("ModalResponse", function () {
TEST_DATA.MODAL_RESPONSE.data.components[0].components,
},
],
custom_id: TEST_DATA.MODAL_RESPONSE.data.custom_id,
},
});
});
Expand Down Expand Up @@ -137,6 +139,7 @@ describe("ModalResponse", function () {
},
type: TEST_DATA.MODAL_RESPONSE.type,
values: TEST_DATA.MODAL_RESPONSE.data.components[0].components,
custom_id: TEST_DATA.MODAL_RESPONSE.data.custom_id,
});
expect(
modalResponse.toJSON(TO_JSON_TYPES_ENUM.DISCORD_FORMAT),
Expand Down Expand Up @@ -171,6 +174,7 @@ describe("ModalResponse", function () {
TEST_DATA.MODAL_RESPONSE.data.components[0].components,
},
],
custom_id: "test",
},
});
});
Expand Down

0 comments on commit 01d44a5

Please sign in to comment.