Complete contextdelete command

This commit is contained in:
powermaker450 2024-12-14 16:24:12 -05:00
parent 9d57598352
commit 654e360f37
2 changed files with 30 additions and 7 deletions

View file

@ -23,8 +23,9 @@ import {
ContextMenuCommandType
} from "discord.js";
import Logger from "../utils/Logger";
import { dt } from "../main";
import { deleteConfession } from "../commandutils";
import { messageOpts } from "../constants";
import { BotClient } from "../bot";
const logger = new Logger("(:) contextdel");
@ -37,12 +38,20 @@ export const data = new ContextMenuCommandBuilder()
.setType(ApplicationCommandType.Message as ContextMenuCommandType);
export async function execute(interaction: ContextMenuCommandInteraction) {
const text = `Target: ${interaction.targetId}`;
logger.log(text);
const { guildId, targetId } = interaction;
if (!dt.getConfessionById(guildId!, targetId)) {
return interaction.reply({
content: text,
content: "Either that confession wasn't found or you aren't allowed to remove it.",
...messageOpts
});
}
const { id: confessionId } = dt.getConfessionById(guildId!, targetId)!;
try {
deleteConfession(interaction, confessionId);
} catch (err) {
logger.error("An error occured:", err);
}
}

View file

@ -182,6 +182,20 @@ export class StoreMan {
return null;
}
public getConfessionById(guildId: string, messageId: string): Confession | null {
for (const guild of this.data) {
if (guild.id === guildId) {
for (const confession of guild.confessions) {
if (confession.messageId === messageId) {
return confession;
}
}
}
}
return null;
}
// Attempts to delete a confession. If it is sucessfully deleted, returns true, else false.
public delConfesssion(
{ guild, user }: CommandInteraction,