summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/util/Components.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/util/Components.js
downloadsowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2
sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip
first commit
Diffstat (limited to 'node_modules/discord.js/src/util/Components.js')
-rw-r--r--node_modules/discord.js/src/util/Components.js152
1 files changed, 152 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/util/Components.js b/node_modules/discord.js/src/util/Components.js
new file mode 100644
index 0000000..1a2ccbc
--- /dev/null
+++ b/node_modules/discord.js/src/util/Components.js
@@ -0,0 +1,152 @@
+'use strict';
+
+// This file contains the typedefs for camel-cased JSON data
+const { ComponentBuilder } = require('@discordjs/builders');
+const { ComponentType } = require('discord-api-types/v10');
+/**
+ * @typedef {Object} BaseComponentData
+ * @property {ComponentType} type The type of component
+ */
+
+/**
+ * @typedef {BaseComponentData} ActionRowData
+ * @property {ComponentData[]} components The components in this action row
+ */
+
+/**
+ * @typedef {BaseComponentData} ButtonComponentData
+ * @property {ButtonStyle} style The style of the button
+ * @property {?boolean} disabled Whether this button is disabled
+ * @property {string} label The label of this button
+ * @property {?APIMessageComponentEmoji} emoji The emoji on this button
+ * @property {?string} customId The custom id of the button
+ * @property {?string} url The URL of the button
+ */
+
+/**
+ * @typedef {object} SelectMenuComponentOptionData
+ * @property {string} label The label of the option
+ * @property {string} value The value of the option
+ * @property {?string} description The description of the option
+ * @property {?APIMessageComponentEmoji} emoji The emoji on the option
+ * @property {?boolean} default Whether this option is selected by default
+ */
+
+/**
+ * @typedef {BaseComponentData} SelectMenuComponentData
+ * @property {string} customId The custom id of the select menu
+ * @property {?boolean} disabled Whether the select menu is disabled or not
+ * @property {?number} maxValues The maximum amount of options that can be selected
+ * @property {?number} minValues The minimum amount of options that can be selected
+ * @property {?SelectMenuComponentOptionData[]} options The options in this select menu
+ * @property {?string} placeholder The placeholder of the select menu
+ */
+
+/**
+ * @typedef {ActionRowData|ButtonComponentData|SelectMenuComponentData} MessageComponentData
+ */
+
+/**
+ * @typedef {BaseComponentData} TextInputComponentData
+ * @property {string} customId The custom id of the text input
+ * @property {TextInputStyle} style The style of the text input
+ * @property {string} label The text that appears on top of the text input field
+ * @property {?number} minLength The minimum number of characters that can be entered in the text input
+ * @property {?number} maxLength The maximum number of characters that can be entered in the text input
+ * @property {?boolean} required Whether or not the text input is required or not
+ * @property {?string} value The pre-filled text in the text input
+ * @property {?string} placeholder Placeholder for the text input
+ */
+
+/**
+ * @typedef {ActionRowData|ButtonComponentData|SelectMenuComponentData|TextInputComponentData} ComponentData
+ */
+
+/**
+ * Any emoji data that can be used within a button
+ * @typedef {APIMessageComponentEmoji|string} ComponentEmojiResolvable
+ */
+
+/**
+ * Transforms API data into a component
+ * @param {APIMessageComponent|Component} data The data to create the component from
+ * @returns {Component}
+ */
+function createComponent(data) {
+ if (data instanceof Component) {
+ return data;
+ }
+
+ switch (data.type) {
+ case ComponentType.ActionRow:
+ return new ActionRow(data);
+ case ComponentType.Button:
+ return new ButtonComponent(data);
+ case ComponentType.StringSelect:
+ return new StringSelectMenuComponent(data);
+ case ComponentType.TextInput:
+ return new TextInputComponent(data);
+ case ComponentType.UserSelect:
+ return new UserSelectMenuComponent(data);
+ case ComponentType.RoleSelect:
+ return new RoleSelectMenuComponent(data);
+ case ComponentType.MentionableSelect:
+ return new MentionableSelectMenuComponent(data);
+ case ComponentType.ChannelSelect:
+ return new ChannelSelectMenuComponent(data);
+ default:
+ return new Component(data);
+ }
+}
+
+/**
+ * Transforms API data into a component builder
+ * @param {APIMessageComponent|ComponentBuilder} data The data to create the component from
+ * @returns {ComponentBuilder}
+ */
+function createComponentBuilder(data) {
+ if (data instanceof ComponentBuilder) {
+ return data;
+ }
+
+ switch (data.type) {
+ case ComponentType.ActionRow:
+ return new ActionRowBuilder(data);
+ case ComponentType.Button:
+ return new ButtonBuilder(data);
+ case ComponentType.StringSelect:
+ return new StringSelectMenuBuilder(data);
+ case ComponentType.TextInput:
+ return new TextInputBuilder(data);
+ case ComponentType.UserSelect:
+ return new UserSelectMenuBuilder(data);
+ case ComponentType.RoleSelect:
+ return new RoleSelectMenuBuilder(data);
+ case ComponentType.MentionableSelect:
+ return new MentionableSelectMenuBuilder(data);
+ case ComponentType.ChannelSelect:
+ return new ChannelSelectMenuBuilder(data);
+ default:
+ return new ComponentBuilder(data);
+ }
+}
+
+module.exports = { createComponent, createComponentBuilder };
+
+const ActionRow = require('../structures/ActionRow');
+const ActionRowBuilder = require('../structures/ActionRowBuilder');
+const ButtonBuilder = require('../structures/ButtonBuilder');
+const ButtonComponent = require('../structures/ButtonComponent');
+const ChannelSelectMenuBuilder = require('../structures/ChannelSelectMenuBuilder');
+const ChannelSelectMenuComponent = require('../structures/ChannelSelectMenuComponent');
+const Component = require('../structures/Component');
+const MentionableSelectMenuBuilder = require('../structures/MentionableSelectMenuBuilder');
+const MentionableSelectMenuComponent = require('../structures/MentionableSelectMenuComponent');
+const RoleSelectMenuBuilder = require('../structures/RoleSelectMenuBuilder');
+const RoleSelectMenuComponent = require('../structures/RoleSelectMenuComponent');
+const StringSelectMenuBuilder = require('../structures/StringSelectMenuBuilder');
+const StringSelectMenuComponent = require('../structures/StringSelectMenuComponent');
+const TextInputBuilder = require('../structures/TextInputBuilder');
+const TextInputComponent = require('../structures/TextInputComponent');
+const UserSelectMenuBuilder = require('../structures/UserSelectMenuBuilder');
+const UserSelectMenuComponent = require('../structures/UserSelectMenuComponent');