85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
import { createCommand } from "@shared/lib/utils";
|
|
import { SlashCommandBuilder, PermissionFlagsBits, MessageFlags } from "discord.js";
|
|
import { ModerationService } from "@shared/modules/moderation/moderation.service";
|
|
import { getClearSuccessEmbed, getModerationErrorEmbed } from "@/modules/moderation/moderation.view";
|
|
|
|
export const clearwarning = createCommand({
|
|
data: new SlashCommandBuilder()
|
|
.setName("clearwarning")
|
|
.setDescription("Clear/resolve a warning")
|
|
.addStringOption(option =>
|
|
option
|
|
.setName("case_id")
|
|
.setDescription("The case ID to clear (e.g., CASE-0001)")
|
|
.setRequired(true)
|
|
)
|
|
.addStringOption(option =>
|
|
option
|
|
.setName("reason")
|
|
.setDescription("Reason for clearing the warning")
|
|
.setRequired(false)
|
|
.setMaxLength(500)
|
|
)
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
|
|
|
execute: async (interaction) => {
|
|
await interaction.deferReply({ flags: MessageFlags.Ephemeral });
|
|
|
|
try {
|
|
const caseId = interaction.options.getString("case_id", true).toUpperCase();
|
|
const reason = interaction.options.getString("reason") || "Cleared by moderator";
|
|
|
|
// Validate case ID format
|
|
if (!caseId.match(/^CASE-\d+$/)) {
|
|
await interaction.editReply({
|
|
embeds: [getModerationErrorEmbed("Invalid case ID format. Expected format: CASE-0001")]
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Check if case exists and is active
|
|
const existingCase = await ModerationService.getCaseById(caseId);
|
|
|
|
if (!existingCase) {
|
|
await interaction.editReply({
|
|
embeds: [getModerationErrorEmbed(`Case **${caseId}** not found.`)]
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (!existingCase.active) {
|
|
await interaction.editReply({
|
|
embeds: [getModerationErrorEmbed(`Case **${caseId}** is already resolved.`)]
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (existingCase.type !== 'warn') {
|
|
await interaction.editReply({
|
|
embeds: [getModerationErrorEmbed(`Case **${caseId}** is not a warning. Only warnings can be cleared.`)]
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Clear the warning
|
|
await ModerationService.clearCase({
|
|
caseId,
|
|
clearedBy: interaction.user.id,
|
|
clearedByName: interaction.user.username,
|
|
reason
|
|
});
|
|
|
|
// Send success message
|
|
await interaction.editReply({
|
|
embeds: [getClearSuccessEmbed(caseId)]
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error("Clear warning command error:", error);
|
|
await interaction.editReply({
|
|
embeds: [getModerationErrorEmbed("An error occurred while clearing the warning.")]
|
|
});
|
|
}
|
|
}
|
|
});
|