refactor(menu): Made sure the menu can be used for more than group

This commit is contained in:
Michel Fedde 2025-06-20 17:48:00 +02:00
parent a79898b2e9
commit 1d73ee8a78
16 changed files with 650 additions and 406 deletions

View file

@ -0,0 +1,31 @@
import {EventHandler} from "../../Events/EventHandler";
import {randomUUID} from "node:crypto";
import {ModalBuilder, ModalSubmitInteraction} from "discord.js";
import {ModalInteractionEvent} from "../../Events/ModalInteractionEvent";
export abstract class Modal {
private readonly modalId: string;
protected constructor(
private readonly eventHandler: EventHandler
) {
this.modalId = randomUUID();
}
protected getBuilder(): ModalBuilder {
return new ModalBuilder()
.setCustomId(this.modalId);
}
protected awaitResponse(): Promise<ModalSubmitInteraction>
{
return new Promise<ModalSubmitInteraction>((resolve) => {
this.eventHandler.addHandler<ModalInteractionEvent>(ModalInteractionEvent.name, (ev) => {
if (this.modalId !== ev.interaction.customId) {
return;
}
resolve(ev.interaction);
})
})
}
}

View file

@ -0,0 +1,17 @@
import {Modal} from "./Modal";
import {Interaction, MessageComponentInteraction, TextInputBuilder} from "discord.js";
export class Prompt extends Modal {
public async requestValue(
label: string,
field: TextInputBuilder,
interaction: MessageComponentInteraction
): Promise<string> {
const modal = this.getBuilder()
.setTitle(label);
await interaction.showModal(modal);
const responseInteraction = await this.awaitResponse();
responseInteraction.fields.getTextInputValue()
}
}