A powerful and extendable Discord bot, with it's own module system :3
thevoid.cafe/projects/voidy
1import { MessageFlags, PermissionFlagsBits, SlashCommandSubcommandBuilder } from "discord.js";
2import { Command, requirePermission } from "@voidy/framework";
3import { ChatbotRepository } from "../../schemas/ChatbotRepository";
4
5export default new Command({
6 id: "chatbot.profile.remove",
7 use: [requirePermission(PermissionFlagsBits.ManageGuild)],
8 data: new SlashCommandSubcommandBuilder()
9 .setName("remove")
10 .setDescription("Remove a profile from a content repository.")
11 .addStringOption((option) =>
12 option.setName("name").setDescription("Profile name.").setRequired(true),
13 )
14 .addStringOption((option) =>
15 option.setName("repository").setDescription("Local repository name. Omit for global."),
16 ),
17
18 execute: async ({ interaction }) => {
19 const name = interaction.options.getString("name", true);
20 const repoName = interaction.options.getString("repository");
21
22 const query = repoName
23 ? { scope: "local" as const, guildId: interaction.guildId, name: repoName }
24 : { scope: "global" as const };
25
26 const repo = await ChatbotRepository.findOne(query);
27
28 if (!repo) {
29 const target = repoName ? `Local repository "${repoName}"` : "Global repository";
30 await interaction.reply({
31 content: `${target} not found.`,
32 flags: [MessageFlags.Ephemeral],
33 });
34 return;
35 }
36
37 const index = repo.profiles.findIndex((p) => p.name === name);
38 if (index === -1) {
39 await interaction.reply({
40 content: `Profile "${name}" not found in this repository.`,
41 flags: [MessageFlags.Ephemeral],
42 });
43 return;
44 }
45
46 repo.profiles.splice(index, 1);
47 await repo.save();
48
49 await interaction.reply({
50 content: `Profile "${name}" removed from **${repo.name}** (${repo.scope}).`,
51 flags: [MessageFlags.Ephemeral],
52 });
53 },
54});