Update Bot

This commit is contained in:
2026-03-15 11:58:43 +01:00
parent b67c111ffc
commit cd99275933
560 changed files with 23173 additions and 55113 deletions

View File

@@ -1,61 +1,24 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const { lazy } = require('@discordjs/util');
const BaseInteraction = require('./BaseInteraction');
const InteractionWebhook = require('./InteractionWebhook');
const ModalSubmitFields = require('./ModalSubmitFields');
const InteractionResponses = require('./interfaces/InteractionResponses');
const { transformResolved } = require('../util/Util');
const getMessage = lazy(() => require('./Message').Message);
const getAttachment = lazy(() => require('./Attachment'));
/**
* @typedef {Object} BaseModalData
* @property {ComponentType} type The component type of the field
* @property {number} id The id of the field
*/
/**
* @typedef {BaseModalData} FileUploadModalData
* @property {string} customId The custom id of the file upload
* @property {Snowflake[]} values The values of the file upload
* @property {Collection<Snowflake, Attachment>} [attachments] The resolved attachments
*/
/**
* @typedef {BaseModalData} TextInputModalData
* @property {string} customId The custom id of the field
* @typedef {Object} ModalData
* @property {string} value The value of the field
*/
/**
* @typedef {BaseModalData} SelectMenuModalData
* @property {ComponentType} type The component type of the field
* @property {string} customId The custom id of the field
* @property {string[]} values The values of the field
* @property {Collection<Snowflake, GuildMember|APIGuildMember>} [members] The resolved members
* @property {Collection<Snowflake, User|APIUser>} [users] The resolved users
* @property {Collection<Snowflake, Role|APIRole>} [roles] The resolved roles
* @property {Collection<Snowflake, BaseChannel|APIChannel>} [channels] The resolved channels
*/
/**
* @typedef {BaseModalData} TextDisplayModalData
*/
/**
* @typedef {SelectMenuModalData|TextInputModalData|FileUploadModalData} ModalData
*/
/**
* @typedef {BaseModalData} LabelModalData
* @property {ModalData} component The component within the label
*/
/**
* @typedef {BaseModalData} ActionRowModalData
* @property {TextInputModalData[]} components The components of this action row
* @typedef {Object} ActionRowModalData
* @property {ModalData[]} components The components of this action row
* @property {ComponentType} type The component type of the action row
*/
/**
@@ -84,24 +47,15 @@ class ModalSubmitInteraction extends BaseInteraction {
/**
* The components within the modal
*
* @type {Array<ActionRowModalData | LabelModalData | TextDisplayModalData>}
* @type {ActionRowModalData[]}
*/
this.components = data.data.components?.map(component =>
ModalSubmitInteraction.transformComponent(component, data.data.resolved, {
client: this.client,
guild: this.guild,
}),
);
this.components = data.data.components?.map(component => ModalSubmitInteraction.transformComponent(component));
/**
* The fields within the modal
* @type {ModalSubmitFields}
*/
this.fields = new ModalSubmitFields(
this.components,
transformResolved({ client: this.client, guild: this.guild, channel: this.channel }, data.data.resolved),
);
this.fields = new ModalSubmitFields(this.components);
/**
* Whether the reply to this interaction has been deferred
@@ -131,102 +85,19 @@ class ModalSubmitInteraction extends BaseInteraction {
/**
* Transforms component data to discord.js-compatible data
* @param {*} rawComponent The data to transform
* @param {APIInteractionDataResolved} [resolved] The resolved data for the interaction
* @param {*} [extra] Extra data required for the transformation
* @returns {ModalData[]}
*/
static transformComponent(rawComponent, resolved, { client, guild } = {}) {
if ('components' in rawComponent) {
return {
type: rawComponent.type,
id: rawComponent.id,
components: rawComponent.components.map(component =>
this.transformComponent(component, resolved, { client, guild }),
),
};
}
if ('component' in rawComponent) {
return {
type: rawComponent.type,
id: rawComponent.id,
component: this.transformComponent(rawComponent.component, resolved, { client, guild }),
};
}
const data = {
type: rawComponent.type,
id: rawComponent.id,
};
// Text display components do not have custom ids.
if ('custom_id' in rawComponent) data.customId = rawComponent.custom_id;
if ('value' in rawComponent) data.value = rawComponent.value;
if (rawComponent.values) {
data.values = rawComponent.values;
/* eslint-disable max-depth */
if (resolved) {
const { members, users, channels, roles, attachments } = resolved;
const valueSet = new Set(rawComponent.values);
if (users) {
data.users = new Collection();
for (const [id, user] of Object.entries(users)) {
if (valueSet.has(id)) {
data.users.set(id, client.users._add(user));
}
}
static transformComponent(rawComponent) {
return rawComponent.components
? {
type: rawComponent.type,
components: rawComponent.components.map(component => this.transformComponent(component)),
}
if (channels) {
data.channels = new Collection();
for (const [id, apiChannel] of Object.entries(channels)) {
if (valueSet.has(id)) {
data.channels.set(id, client.channels._add(apiChannel, guild) ?? apiChannel);
}
}
}
if (members) {
data.members = new Collection();
for (const [id, member] of Object.entries(members)) {
if (valueSet.has(id)) {
const user = users?.[id];
data.members.set(id, guild?.members._add({ user, ...member }) ?? member);
}
}
}
if (roles) {
data.roles = new Collection();
for (const [id, role] of Object.entries(roles)) {
if (valueSet.has(id)) {
data.roles.set(id, guild?.roles._add(role) ?? role);
}
}
}
if (attachments) {
data.attachments = new Collection();
for (const [id, attachment] of Object.entries(attachments)) {
if (valueSet.has(id)) {
data.attachments.set(id, new (getAttachment())(attachment));
}
}
}
}
/* eslint-enable max-depth */
}
return data;
: {
value: rawComponent.value,
type: rawComponent.type,
customId: rawComponent.custom_id,
};
}
/**