apps/bot/src/components/ConfigModal.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import { errorMessage } from "@/lib";
import { modalRegistry } from "@/lib/registries";
import { ComponentDefinition } from "@/lib/structures/ComponentDefinition";
import db, { eq, getGuildByDiscordId, guilds } from "@stealth-developers/db";
import { MessageFlags } from "discord.js";
export const ConfigTextModal = new ComponentDefinition<
"config-text",
[key: "ticketPrompt" | "ticketGreeting"]
>("config-text");
modalRegistry.register(ConfigTextModal, async (interaction, [key]) => {
const value = interaction.fields.getTextInputValue("text-value");
if (!interaction.guildId)
return errorMessage(interaction, "This interaction can only be used in a server.");
const guild = await getGuildByDiscordId(interaction.guildId);
if (!guild) return errorMessage(interaction, "Failed to update configuration: Guild not found.");
const [res] = await db
.update(guilds)
.set({ [key]: value })
.where(eq(guilds.id, guild.id))
.returning();
if (!res) return errorMessage(interaction, "Failed to update configuration.");
return interaction.reply({
content: "Configuration updated successfully!",
flags: [MessageFlags.Ephemeral],
});
});
|