summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/structures/ModalSubmitInteraction.js
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
committersowgro <tpoke.ferrari@gmail.com>2023-09-02 19:12:47 -0400
commite4450c8417624b71d779cb4f41692538f9165e10 (patch)
treeb70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/discord.js/src/structures/ModalSubmitInteraction.js
downloadsowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip
first commit
Diffstat (limited to 'node_modules/discord.js/src/structures/ModalSubmitInteraction.js')
-rw-r--r--node_modules/discord.js/src/structures/ModalSubmitInteraction.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/structures/ModalSubmitInteraction.js b/node_modules/discord.js/src/structures/ModalSubmitInteraction.js
new file mode 100644
index 0000000..8f0ccf1
--- /dev/null
+++ b/node_modules/discord.js/src/structures/ModalSubmitInteraction.js
@@ -0,0 +1,122 @@
+'use strict';
+
+const { lazy } = require('@discordjs/util');
+const BaseInteraction = require('./BaseInteraction');
+const InteractionWebhook = require('./InteractionWebhook');
+const ModalSubmitFields = require('./ModalSubmitFields');
+const InteractionResponses = require('./interfaces/InteractionResponses');
+
+const getMessage = lazy(() => require('./Message').Message);
+
+/**
+ * @typedef {Object} ModalData
+ * @property {string} value The value of the field
+ * @property {ComponentType} type The component type of the field
+ * @property {string} customId The custom id of the field
+ */
+
+/**
+ * @typedef {Object} ActionRowModalData
+ * @property {ModalData[]} components The components of this action row
+ * @property {ComponentType} type The component type of the action row
+ */
+
+/**
+ * Represents a modal interaction
+ * @extends {BaseInteraction}
+ * @implements {InteractionResponses}
+ */
+class ModalSubmitInteraction extends BaseInteraction {
+ constructor(client, data) {
+ super(client, data);
+ /**
+ * The custom id of the modal.
+ * @type {string}
+ */
+ this.customId = data.data.custom_id;
+
+ if ('message' in data) {
+ /**
+ * The message associated with this interaction
+ * @type {?Message}
+ */
+ this.message = this.channel?.messages._add(data.message) ?? new (getMessage())(this.client, data.message);
+ } else {
+ this.message = null;
+ }
+
+ /**
+ * The components within the modal
+ * @type {ActionRowModalData[]}
+ */
+ this.components = data.data.components?.map(c => ModalSubmitInteraction.transformComponent(c));
+
+ /**
+ * The fields within the modal
+ * @type {ModalSubmitFields}
+ */
+ this.fields = new ModalSubmitFields(this.components);
+
+ /**
+ * Whether the reply to this interaction has been deferred
+ * @type {boolean}
+ */
+ this.deferred = false;
+
+ /**
+ * Whether this interaction has already been replied to
+ * @type {boolean}
+ */
+ this.replied = false;
+
+ /**
+ * Whether the reply to this interaction is ephemeral
+ * @type {?boolean}
+ */
+ this.ephemeral = null;
+
+ /**
+ * An associated interaction webhook, can be used to further interact with this interaction
+ * @type {InteractionWebhook}
+ */
+ this.webhook = new InteractionWebhook(this.client, this.applicationId, this.token);
+ }
+
+ /**
+ * Transforms component data to discord.js-compatible data
+ * @param {*} rawComponent The data to transform
+ * @returns {ModalData[]}
+ */
+ static transformComponent(rawComponent) {
+ return rawComponent.components
+ ? { type: rawComponent.type, components: rawComponent.components.map(c => this.transformComponent(c)) }
+ : {
+ value: rawComponent.value,
+ type: rawComponent.type,
+ customId: rawComponent.custom_id,
+ };
+ }
+
+ /**
+ * Whether this is from a {@link MessageComponentInteraction}.
+ * @returns {boolean}
+ */
+ isFromMessage() {
+ return Boolean(this.message);
+ }
+
+ // These are here only for documentation purposes - they are implemented by InteractionResponses
+ /* eslint-disable no-empty-function */
+ deferReply() {}
+ reply() {}
+ fetchReply() {}
+ editReply() {}
+ deleteReply() {}
+ followUp() {}
+ deferUpdate() {}
+ update() {}
+}
+
+InteractionResponses.applyToClass(ModalSubmitInteraction, 'showModal');
+
+module.exports = ModalSubmitInteraction;