From 3fc962438910715eab2064ba79fba18657833484 Mon Sep 17 00:00:00 2001 From: xHyroM Date: Sat, 8 Apr 2023 14:15:13 +0200 Subject: [PATCH] feat(bot): add acknowledge to Component --- packages/bot/src/index.ts | 18 +++++++++++------- packages/bot/src/structs/Command.ts | 2 +- packages/bot/src/structs/Component.ts | 5 ++++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/bot/src/index.ts b/packages/bot/src/index.ts index 984b65c..edb429b 100644 --- a/packages/bot/src/index.ts +++ b/packages/bot/src/index.ts @@ -88,14 +88,18 @@ export default { return new Response("Unknown component", { status: 404 }); try { - return respond({ - type: InteractionResponseType.DeferredChannelMessageWithSource, - data: { - flags: component.flags, - }, - }); + if (component.acknowledge) + return respond({ + type: InteractionResponseType.DeferredChannelMessageWithSource, + data: { + flags: component.flags, + }, + }); } finally { - component.run(new ComponentContext(interaction, env)); + if (component.acknowledge) + component.run(new ComponentContext(interaction, env)); + // rome-ignore lint/correctness/noUnsafeFinally: it works, must do better typings etc... + else return component.run(new ComponentContext(interaction, env)); } } } diff --git a/packages/bot/src/structs/Command.ts b/packages/bot/src/structs/Command.ts index 03b8dde..f014dff 100644 --- a/packages/bot/src/structs/Command.ts +++ b/packages/bot/src/structs/Command.ts @@ -9,7 +9,7 @@ interface CommandOptions { run: (interaction: CommandContext) => void; } -export class Command { +export class Command { public name: string; public acknowledge: boolean; public flags: MessageFlags | undefined; diff --git a/packages/bot/src/structs/Component.ts b/packages/bot/src/structs/Component.ts index 1ee0df7..c6eb902 100644 --- a/packages/bot/src/structs/Component.ts +++ b/packages/bot/src/structs/Component.ts @@ -4,17 +4,20 @@ import { ComponentContext } from "./contexts/ComponentContext"; interface ComponentOptions { id: string; + acknowledge?: boolean; flags?: MessageFlags; run: (interaction: ComponentContext) => void; } export class Component { public id: string; + public acknowledge: boolean; public flags: MessageFlags | undefined; - public run: (interaction: ComponentContext) => void; + public run: (interaction: ComponentContext) => void | Response; constructor(options: ComponentOptions) { this.id = options.id; + this.acknowledge = options.acknowledge ?? true; this.flags = options.flags; this.run = options.run;