From 0784d1b8ad604c85dabb821e35896119355dee2f Mon Sep 17 00:00:00 2001 From: cirroskais Date: Tue, 5 Mar 2024 23:13:29 -0500 Subject: [PATCH] Code cleanup --- src/lib/handlers/CommandHandler.ts | 5 ++--- src/lib/handlers/ModalHandler.ts | 18 +++--------------- src/lib/types/modalresponse.d.ts | 6 ++++++ 3 files changed, 11 insertions(+), 18 deletions(-) create mode 100644 src/lib/types/modalresponse.d.ts diff --git a/src/lib/handlers/CommandHandler.ts b/src/lib/handlers/CommandHandler.ts index 70f438d..1c7683c 100644 --- a/src/lib/handlers/CommandHandler.ts +++ b/src/lib/handlers/CommandHandler.ts @@ -1,5 +1,4 @@ import type { Bot, Interaction, InteractionResponse } from "@discordeno/bot"; -import type { Command } from "../types/command"; import REST from "./RESTHandler"; export const commands = new Map(); @@ -14,9 +13,9 @@ export function handle(interaction: Interaction) { if (!interaction.data) return; const resolved = commands.get(interaction.data.name); - if (!resolved) return interaction.respond("What the fuck did you do"); + if (!resolved) return interaction.respond("Internal Error: SLASHCOMMAND_NOT_FOUND", { isPrivate: true }); resolved - .run() + .run(interaction) .then((response: InteractionResponse) => REST.sendInteractionResponse(interaction.id, interaction.token, response) ) diff --git a/src/lib/handlers/ModalHandler.ts b/src/lib/handlers/ModalHandler.ts index a53d862..c7f1168 100644 --- a/src/lib/handlers/ModalHandler.ts +++ b/src/lib/handlers/ModalHandler.ts @@ -1,15 +1,10 @@ import { randomUUID } from "node:crypto"; import Modal from "../classes/Modal"; -import { InteractionResponseTypes, type Interaction, type Component } from "@discordeno/bot"; -import REST from "./RESTHandler"; +import { type Interaction, type Component } from "@discordeno/bot"; +import type { ModalResponse } from "../types/modalresponse"; const modals = new Map(); -type ModalResponse = { - interaction: Interaction; - values: Map; -}; - function getModalValues(interaction: Interaction): Map { const values = new Map(); if (!interaction.data?.components) return values; @@ -39,14 +34,7 @@ export function handle(interaction: Interaction) { const { customId } = interaction.data; const modal = modals.get(customId); - if (!modal) - return REST.sendInteractionResponse(interaction.id, interaction.token, { - type: InteractionResponseTypes.ChannelMessageWithSource, - data: { - content: "Internal Error: MODAL_NOT_FOUND", - flags: 64, - }, - }); + if (!modal) return interaction.respond("Internal Error: MODAL_NOT_FOUND", { isPrivate: true }); return modal({ interaction, values: getModalValues(interaction) }); } diff --git a/src/lib/types/modalresponse.d.ts b/src/lib/types/modalresponse.d.ts new file mode 100644 index 0000000..ba7b441 --- /dev/null +++ b/src/lib/types/modalresponse.d.ts @@ -0,0 +1,6 @@ +import { type Interaction } from "@discordeno/bot"; + +type ModalResponse = { + interaction: Interaction; + values: Map; +};