Actually fix confession deletions

This commit is contained in:
powermaker450 2024-10-12 18:34:30 -04:00
parent 5b2fa6e93f
commit 683a2c6097
2 changed files with 21 additions and 11 deletions

View file

@ -16,9 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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

View file

@ -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;
}