From e4450c8417624b71d779cb4f41692538f9165e10 Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 2 Sep 2023 19:12:47 -0400 Subject: first commit --- .../discord.js/src/structures/ModalSubmitFields.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 node_modules/discord.js/src/structures/ModalSubmitFields.js (limited to 'node_modules/discord.js/src/structures/ModalSubmitFields.js') diff --git a/node_modules/discord.js/src/structures/ModalSubmitFields.js b/node_modules/discord.js/src/structures/ModalSubmitFields.js new file mode 100644 index 0000000..8e67b21 --- /dev/null +++ b/node_modules/discord.js/src/structures/ModalSubmitFields.js @@ -0,0 +1,55 @@ +'use strict'; + +const { Collection } = require('@discordjs/collection'); +const { ComponentType } = require('discord-api-types/v10'); +const { DiscordjsTypeError, ErrorCodes } = require('../errors'); + +/** + * Represents the serialized fields from a modal submit interaction + */ +class ModalSubmitFields { + constructor(components) { + /** + * The components within the modal + * @type {ActionRowModalData[]} + */ + this.components = components; + + /** + * The extracted fields from the modal + * @type {Collection} + */ + this.fields = components.reduce((accumulator, next) => { + next.components.forEach(c => accumulator.set(c.customId, c)); + return accumulator; + }, new Collection()); + } + + /** + * Gets a field given a custom id from a component + * @param {string} customId The custom id of the component + * @param {ComponentType} [type] The type of the component + * @returns {ModalData} + */ + getField(customId, type) { + const field = this.fields.get(customId); + if (!field) throw new DiscordjsTypeError(ErrorCodes.ModalSubmitInteractionFieldNotFound, customId); + + if (type !== undefined && type !== field.type) { + throw new DiscordjsTypeError(ErrorCodes.ModalSubmitInteractionFieldType, customId, field.type, type); + } + + return field; + } + + /** + * Gets the value of a text input component given a custom id + * @param {string} customId The custom id of the text input component + * @returns {string} + */ + getTextInputValue(customId) { + return this.getField(customId, ComponentType.TextInput).value; + } +} + +module.exports = ModalSubmitFields; -- cgit v1.2.3