Files
AuroraBot-discord/bot/modules/moderation/prune.view.ts
2026-01-08 16:09:26 +01:00

116 lines
3.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Colors } from "discord.js";
import type { PruneResult, PruneProgress } from "./prune.types";
/**
* Creates a confirmation message for prune operations
*/
export function getConfirmationMessage(
amount: number | 'all',
estimatedCount?: number
): { embeds: EmbedBuilder[], components: ActionRowBuilder<ButtonBuilder>[] } {
const isAll = amount === 'all';
const messageCount = isAll ? estimatedCount : amount;
const embed = new EmbedBuilder()
.setTitle("⚠️ Confirm Deletion")
.setDescription(
isAll
? `You are about to delete **ALL messages** in this channel.\n\n` +
`Estimated messages: **~${estimatedCount || 'Unknown'}**\n` +
`This action **cannot be undone**.`
: `You are about to delete **${amount} messages**.\n\n` +
`This action **cannot be undone**.`
)
.setColor(Colors.Orange)
.setTimestamp();
const confirmButton = new ButtonBuilder()
.setCustomId("confirm_prune")
.setLabel("Confirm")
.setStyle(ButtonStyle.Danger);
const cancelButton = new ButtonBuilder()
.setCustomId("cancel_prune")
.setLabel("Cancel")
.setStyle(ButtonStyle.Secondary);
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(confirmButton, cancelButton);
return { embeds: [embed], components: [row] };
}
/**
* Creates a progress embed for ongoing deletions
*/
export function getProgressEmbed(progress: PruneProgress): EmbedBuilder {
const percentage = Math.round((progress.current / progress.total) * 100);
return new EmbedBuilder()
.setTitle("🔄 Deleting Messages")
.setDescription(
`Progress: **${progress.current}/${progress.total}** (${percentage}%)\n\n` +
`Please wait...`
)
.setColor(Colors.Blue)
.setTimestamp();
}
/**
* Creates a success embed after deletion
*/
export function getSuccessEmbed(result: PruneResult): EmbedBuilder {
let description = `Successfully deleted **${result.deletedCount} messages**.`;
if (result.filtered && result.username) {
description = `Successfully deleted **${result.deletedCount} messages** from **${result.username}**.`;
}
if (result.skippedOld && result.skippedOld > 0) {
description += `\n\n⚠ **${result.skippedOld} messages** were older than 14 days and could not be deleted.`;
}
if (result.deletedCount < result.requestedCount && !result.skippedOld) {
description += `\n\n Only **${result.deletedCount}** messages were available to delete.`;
}
return new EmbedBuilder()
.setTitle("✅ Messages Deleted")
.setDescription(description)
.setColor(Colors.Green)
.setTimestamp();
}
/**
* Creates an error embed
*/
export function getPruneErrorEmbed(message: string): EmbedBuilder {
return new EmbedBuilder()
.setTitle("❌ Prune Failed")
.setDescription(message)
.setColor(Colors.Red)
.setTimestamp();
}
/**
* Creates a warning embed
*/
export function getPruneWarningEmbed(message: string): EmbedBuilder {
return new EmbedBuilder()
.setTitle("⚠️ Warning")
.setDescription(message)
.setColor(Colors.Yellow)
.setTimestamp();
}
/**
* Creates a cancelled embed
*/
export function getCancelledEmbed(): EmbedBuilder {
return new EmbedBuilder()
.setTitle("🚫 Deletion Cancelled")
.setDescription("Message deletion has been cancelled.")
.setColor(Colors.Grey)
.setTimestamp();
}