pnp-scheduler/source/Menu/Modals/Modal.ts

34 lines
No EOL
972 B
TypeScript

import {EventHandler} from "../../Events/EventHandler";
import {randomUUID} from "node:crypto";
import {ModalBuilder, ModalSubmitInteraction} from "discord.js";
import {ModalInteractionEvent} from "../../Events/EventClasses/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, {
method: (ev) => {
if (this.modalId !== ev.interaction.customId) {
return;
}
resolve(ev.interaction);
},
persistent: false
})
})
}
}