feat(events): Adds AcknowledgableEvent
This commit is contained in:
parent
6d7a0e7cfb
commit
b82ab7dbc4
18 changed files with 228 additions and 77 deletions
|
|
@ -14,7 +14,7 @@ import {
|
|||
import {Nullable} from "../types/Nullable";
|
||||
import {IconCache} from "../Icons/IconCache";
|
||||
import {MessageActionRowComponentBuilder} from "@discordjs/builders";
|
||||
import {ComponentInteractionEvent} from "../Events/ComponentInteractionEvent";
|
||||
import {ComponentInteractionEvent} from "../Events/EventClasses/ComponentInteractionEvent";
|
||||
import {MenuTraversal} from "./MenuTraversal";
|
||||
import {Prompt} from "./Modals/Prompt";
|
||||
|
||||
|
|
@ -52,7 +52,9 @@ export class MenuRenderer {
|
|||
}
|
||||
|
||||
public async display(interaction: CommandInteraction) {
|
||||
this.eventId = this.eventHandler?.addHandler<ComponentInteractionEvent>(ComponentInteractionEvent.name, this.handleUIEvents.bind(this));
|
||||
this.eventId = this.eventHandler?.addHandler<ComponentInteractionEvent>(ComponentInteractionEvent.name, {
|
||||
method: this.handleUIEvents.bind(this),
|
||||
});
|
||||
|
||||
await interaction.reply({
|
||||
content: "",
|
||||
|
|
@ -91,12 +93,13 @@ export class MenuRenderer {
|
|||
);
|
||||
}
|
||||
|
||||
return Array.from(Array(rowCount).keys())
|
||||
const rows = Array.from(Array(rowCount).keys())
|
||||
.map((index) => {
|
||||
const childStart = index * MenuRenderer.MAX_BUTTON_PER_ROW;
|
||||
return menuItem.children.toSpliced(childStart, MenuRenderer.MAX_BUTTON_PER_ROW);
|
||||
return menuItem.children.slice(childStart, MenuRenderer.MAX_BUTTON_PER_ROW);
|
||||
})
|
||||
.reverse()
|
||||
|
||||
return rows.reverse()
|
||||
.map((items) => new ActionRowBuilder<ButtonBuilder>()
|
||||
.setComponents(
|
||||
...items.map(item => new ButtonBuilder()
|
||||
|
|
@ -150,6 +153,8 @@ export class MenuRenderer {
|
|||
return;
|
||||
}
|
||||
|
||||
ev.acknowledge();
|
||||
|
||||
const [, action, parameter ] = ev.interaction.customId.split(';')
|
||||
const menuAction = <MenuAction>action;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {EventHandler} from "../../Events/EventHandler";
|
||||
import {randomUUID} from "node:crypto";
|
||||
import {ModalBuilder, ModalSubmitInteraction} from "discord.js";
|
||||
import {ModalInteractionEvent} from "../../Events/ModalInteractionEvent";
|
||||
import {ModalInteractionEvent} from "../../Events/EventClasses/ModalInteractionEvent";
|
||||
|
||||
export abstract class Modal {
|
||||
private readonly modalId: string;
|
||||
|
|
@ -19,11 +19,14 @@ export abstract class Modal {
|
|||
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);
|
||||
this.eventHandler.addHandler<ModalInteractionEvent>(ModalInteractionEvent.name, {
|
||||
method: (ev) => {
|
||||
if (this.modalId !== ev.interaction.customId) {
|
||||
return;
|
||||
}
|
||||
resolve(ev.interaction);
|
||||
},
|
||||
persistent: false
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue