From 683a2c60971f4884db1c34543ab93e968d857d25 Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Sat, 12 Oct 2024 18:34:30 -0400 Subject: [PATCH] Actually fix confession deletions --- src/commands/confessdel.ts | 23 +++++++++++++++-------- src/storeman/client.ts | 9 ++++++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/commands/confessdel.ts b/src/commands/confessdel.ts index 9905cef..7e1a9fc 100644 --- a/src/commands/confessdel.ts +++ b/src/commands/confessdel.ts @@ -16,9 +16,11 @@ * along with this program. If not, see . */ -import { CommandInteraction, IntegrationApplication, SlashCommandBuilder, TextChannel } from "discord.js"; +import { CommandInteraction, EmbedBuilder, SlashCommandBuilder, TextChannel } from "discord.js"; import { dt } from "../main"; import { BotClient } from "../bot"; +import getRandomColor from "../utils/getRandomColor"; +import Logger from "../utils/Logger"; export const data = new SlashCommandBuilder() .setName("confessdel") @@ -41,20 +43,25 @@ export async function execute(interaction: CommandInteraction) { // @ts-ignore const idVal = interaction.options.getString("id"); - - const result = dt.delConfesssion( - interaction, - idVal - ); + const result = dt.getConfession(interaction.guild?.id!, idVal); if (result) { const confession = dt.getConfession(interaction.guild?.id!, idVal)?.messageId; const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings.confessChannel!; + const emptyEmbed = new EmbedBuilder() + .setColor(getRandomColor()) + .setTitle("Confession Deleted") + // @ts-ignore + .setDescription("[Confession Deleted]"); - await (BotClient.channels.cache.get(channelId) as TextChannel).messages.fetch(confession!).then(message => { - message.delete(); + await (BotClient.channels.cache.get(channelId) as TextChannel).messages.fetch(confession!).then(e => { + e.edit({ + embeds: [emptyEmbed] + }) }); + dt.delConfesssion(interaction, idVal); + return interaction.reply({ content: "Confession removed.", ephemeral: true diff --git a/src/storeman/client.ts b/src/storeman/client.ts index e998041..2e18d26 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -21,6 +21,7 @@ import crypto from "crypto"; import { Confession, GuildData, GuildSettings } from "./types"; import { DATA_DIR } from "./config"; import { CommandInteraction, Message } from "discord.js"; +import Logger from "../utils/Logger"; export class StoreMan { public static readonly fullPath: string = @@ -38,13 +39,14 @@ export class StoreMan { id: string, author: string, authorId: string, + content: string ): Confession { return { id: id, messageId: message.id, author: author, authorId: authorId, - content: message.content.replace(/(# Confession .{4}:\n)/, ""), + content: content }; } @@ -116,7 +118,7 @@ export class StoreMan { } // Attempts to add a confession. Returns true if the confession is sent, false if otherwise. - public addConfession(message: Message, id: string, author: string, authorId: string): boolean { + public addConfession(message: Message, id: string, author: string, authorId: string, content: string): boolean { const guildId = message.guild?.id; for (const guild of this.data) { @@ -126,7 +128,7 @@ export class StoreMan { return false; } - guild.confessions.push(StoreMan.toConfession(message, id, author, authorId)); + guild.confessions.push(StoreMan.toConfession(message, id, author, authorId, content)); this.saveFile(); return true; } @@ -141,6 +143,7 @@ export class StoreMan { for (const guild of this.data) { if (guild.id === guildId) { for (const confession of guild.confessions) { + Logger.log(confession); if (confession.id === confessionId) { return confession; }