diff --git a/src/commands/confessdel.ts b/src/commands/confessdel.ts new file mode 100644 index 0000000..9905cef --- /dev/null +++ b/src/commands/confessdel.ts @@ -0,0 +1,68 @@ +/* + * Confoss: Anonymous confessions for Discord, free as in freedom and price! + * Copyright (C) 2024 powermaker450 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . +*/ + +import { CommandInteraction, IntegrationApplication, SlashCommandBuilder, TextChannel } from "discord.js"; +import { dt } from "../main"; +import { BotClient } from "../bot"; + +export const data = new SlashCommandBuilder() + .setName("confessdel") + .setDescription("Deletes a confession") + .addStringOption(option => + option + .setName("id") + .setDescription("The confession id") + .setRequired(true) + ) + +export async function execute(interaction: CommandInteraction) { + if (!dt.getGuildInfo(interaction.guild?.id!)) { + return interaction.reply({ + content: + "The bot hasn't been set up yet! Ask the server admins to set it up.", + ephemeral: true, + }); + } + + // @ts-ignore + const idVal = interaction.options.getString("id"); + + const result = dt.delConfesssion( + interaction, + idVal + ); + + if (result) { + const confession = dt.getConfession(interaction.guild?.id!, idVal)?.messageId; + const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings.confessChannel!; + + await (BotClient.channels.cache.get(channelId) as TextChannel).messages.fetch(confession!).then(message => { + message.delete(); + }); + + return interaction.reply({ + content: "Confession removed.", + ephemeral: true + }) + } else { + return interaction.reply({ + content: "Either the confession wasn't found or you may not be allowed to remove it.", + ephemeral: true + }); + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index b620607..ac8a054 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -17,6 +17,7 @@ */ import * as confess from "./confess"; +import * as confessdel from "./confessdel"; import * as confessban from "./confessban"; import * as confesspardon from "./confesspardon"; import * as ping from "./ping"; @@ -24,6 +25,7 @@ import * as setup from "./setup"; export const commands = { confess, + confessdel, confessban, confesspardon, ping, diff --git a/src/storeman/client.ts b/src/storeman/client.ts index f126703..1d30a8c 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -164,6 +164,7 @@ export class StoreMan { return confession.id !== confessionId; }); + this.saveFile(); return true; } }