Code cleanup

This commit is contained in:
cirroskais 2024-03-05 23:13:29 -05:00
parent c9ff3cc83e
commit 0784d1b8ad
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
3 changed files with 11 additions and 18 deletions

View file

@ -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)
)

View file

@ -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<string, string>;
};
function getModalValues(interaction: Interaction): Map<string, string> {
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) });
}

6
src/lib/types/modalresponse.d.ts vendored Normal file
View file

@ -0,0 +1,6 @@
import { type Interaction } from "@discordeno/bot";
type ModalResponse = {
interaction: Interaction;
values: Map<string, string>;
};