forked from syntaxbullet/aurorabot
- Create withCommandErrorHandling utility in bot/lib/commandUtils.ts - Migrate economy commands: daily, exam, pay, trivia - Migrate inventory command: use - Migrate admin/moderation commands: warn, case, cases, clearwarning, warnings, note, notes, create_color, listing, webhook, refresh, terminal, featureflags, settings, prune - Add 9 unit tests for the utility - Update AGENTS.md with new recommended error handling pattern
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { createCommand } from "@shared/lib/utils";
|
|
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
|
|
import { moderationService } from "@shared/modules/moderation/moderation.service";
|
|
import { getCasesListEmbed } from "@/modules/moderation/moderation.view";
|
|
import { withCommandErrorHandling } from "@lib/commandUtils";
|
|
|
|
export const cases = createCommand({
|
|
data: new SlashCommandBuilder()
|
|
.setName("cases")
|
|
.setDescription("View all moderation cases for a user")
|
|
.addUserOption(option =>
|
|
option
|
|
.setName("user")
|
|
.setDescription("The user to check cases for")
|
|
.setRequired(true)
|
|
)
|
|
.addBooleanOption(option =>
|
|
option
|
|
.setName("active_only")
|
|
.setDescription("Show only active cases (warnings)")
|
|
.setRequired(false)
|
|
)
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
|
|
|
execute: async (interaction) => {
|
|
await withCommandErrorHandling(
|
|
interaction,
|
|
async () => {
|
|
const targetUser = interaction.options.getUser("user", true);
|
|
const activeOnly = interaction.options.getBoolean("active_only") || false;
|
|
|
|
// Get cases for the user
|
|
const userCases = await moderationService.getUserCases(targetUser.id, activeOnly);
|
|
|
|
const title = activeOnly
|
|
? `⚠️ Active Cases for ${targetUser.username}`
|
|
: `📋 All Cases for ${targetUser.username}`;
|
|
|
|
const description = userCases.length === 0
|
|
? undefined
|
|
: `Total cases: **${userCases.length}**`;
|
|
|
|
// Display the cases
|
|
await interaction.editReply({
|
|
embeds: [getCasesListEmbed(userCases, title, description)]
|
|
});
|
|
},
|
|
{ ephemeral: true }
|
|
);
|
|
}
|
|
});
|