Code cleanup
This commit is contained in:
parent
c9ff3cc83e
commit
0784d1b8ad
3 changed files with 11 additions and 18 deletions
|
@ -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)
|
||||
)
|
||||
|
|
|
@ -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
6
src/lib/types/modalresponse.d.ts
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { type Interaction } from "@discordeno/bot";
|
||||
|
||||
type ModalResponse = {
|
||||
interaction: Interaction;
|
||||
values: Map<string, string>;
|
||||
};
|
Loading…
Reference in a new issue