Skip to content

Commit

Permalink
fix: top-level components may not always be action rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 6, 2024
1 parent caa425f commit 4d40adf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export interface DMModalSubmitRequestData {
context?: InteractionContextType;
data: {
custom_id: string;
components: ComponentActionRow[];
components: AnyComponent[];
};
}

Expand All @@ -433,7 +433,7 @@ export interface GuildModalSubmitRequestData {
context?: InteractionContextType;
data: {
custom_id: string;
components: ComponentActionRow[];
components: AnyComponent[];
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/structures/interfaces/messageInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentActionRow, InteractionResponseFlags, InteractionResponseType } from '../../constants';
import { AnyComponent, InteractionResponseFlags, InteractionResponseType } from '../../constants';
import { BaseSlashCreator, ComponentRegisterCallback } from '../../creator';
import { RespondFunction } from '../../server';
import { formatAllowedMentions, FormattedAllowedMentions, MessageAllowedMentions } from '../../util';
Expand Down Expand Up @@ -386,7 +386,7 @@ export interface EditMessageOptions {
/** The attachment(s) to send with the message. */
files?: MessageFile[];
/** The components of the message. */
components?: ComponentActionRow[];
components?: AnyComponent[];
/** The attachment data of the message. */
attachments?: MessageAttachmentOptions[];
}
Expand Down
18 changes: 13 additions & 5 deletions src/structures/interfaces/modalInteractionContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ComponentActionRow,
AnyComponent,
ComponentTextInput,
ComponentType,
InteractionResponseType,
ModalSubmitRequestData
} from '../../constants';
Expand Down Expand Up @@ -49,13 +50,20 @@ export class ModalInteractionContext<
if (useTimeout) this._timeout = setTimeout(() => this.defer(false), 2000);
}

static convertComponents(components: ComponentActionRow[]): { [key: string]: string } {
static convertComponents(components: AnyComponent[]): { [key: string]: string } {
const values: { [key: string]: string } = {};

for (const row of components) {
const component = row.components[0] as ComponentTextInput;
// TODO If/when selects are available in modals, this needs to adapt for that change
for (const component of components) {
if (component.type === ComponentType.TEXT_INPUT) {
values[component.custom_id] = component.value!;
continue;
}

values[component.custom_id] = component.value!;
if (component.type !== ComponentType.ACTION_ROW) continue;
const childComponent = component.components[0] as ComponentTextInput;

values[childComponent.custom_id] = childComponent.value!;
}

return values;
Expand Down
4 changes: 2 additions & 2 deletions src/structures/interfaces/modalSendableContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentActionRow, InteractionResponseType } from '../../constants';
import { AnyComponent, InteractionResponseType } from '../../constants';
import { ModalRegisterCallback, BaseSlashCreator } from '../../creator';
import { RespondFunction } from '../../server';
import { generateID } from '../../util';
Expand Down Expand Up @@ -56,5 +56,5 @@ export interface ModalOptions {
/** The custom ID of the modal. If a callback is provided but not a custom ID, one will be generated and returned. */
custom_id?: string;
/** The components of the modal. */
components: ComponentActionRow[];
components: AnyComponent[];
}

0 comments on commit 4d40adf

Please sign in to comment.