import { MessageFlags, PermissionFlagsBits, SlashCommandSubcommandBuilder } from "discord.js"; import { Command, requirePermission } from "@voidy/framework"; import { ChatbotRepository } from "../../schemas/ChatbotRepository"; export default new Command({ id: "chatbot.profile.remove", use: [requirePermission(PermissionFlagsBits.ManageGuild)], data: new SlashCommandSubcommandBuilder() .setName("remove") .setDescription("Remove a profile from a content repository.") .addStringOption((option) => option.setName("name").setDescription("Profile name.").setRequired(true), ) .addStringOption((option) => option.setName("repository").setDescription("Local repository name. Omit for global."), ), execute: async ({ interaction }) => { const name = interaction.options.getString("name", true); const repoName = interaction.options.getString("repository"); const query = repoName ? { scope: "local" as const, guildId: interaction.guildId, name: repoName } : { scope: "global" as const }; const repo = await ChatbotRepository.findOne(query); if (!repo) { const target = repoName ? `Local repository "${repoName}"` : "Global repository"; await interaction.reply({ content: `${target} not found.`, flags: [MessageFlags.Ephemeral], }); return; } const index = repo.profiles.findIndex((p) => p.name === name); if (index === -1) { await interaction.reply({ content: `Profile "${name}" not found in this repository.`, flags: [MessageFlags.Ephemeral], }); return; } repo.profiles.splice(index, 1); await repo.save(); await interaction.reply({ content: `Profile "${name}" removed from **${repo.name}** (${repo.scope}).`, flags: [MessageFlags.Ephemeral], }); }, });