refactor(menu): Made sure the menu can be used for more than group
This commit is contained in:
parent
a79898b2e9
commit
1d73ee8a78
16 changed files with 650 additions and 406 deletions
31
source/Menu/Modals/Modal.ts
Normal file
31
source/Menu/Modals/Modal.ts
Normal 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);
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue