MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Moderation/cases.js:34–173  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

32 ),
33
34 async execute(interaction, config, client) {
35 const deferSuccess = await InteractionHelper.safeDefer(interaction);
36 if (!deferSuccess) {
37 logger.warn(`Cases interaction defer failed`, {
38 userId: interaction.user.id,
39 guildId: interaction.guildId,
40 commandName: 'cases'
41 });
42 return;
43 }
44
45 try {
46 const filterType = interaction.options.getString('filter') || 'all';
47 const targetUser = interaction.options.getUser('user');
48 const limit = interaction.options.getInteger('limit') || 10;
49
50 const filters = {
51 limit,
52 action: filterType === 'all' ? undefined : filterType,
53 userId: targetUser?.id
54 };
55
56 const cases = await getModerationCases(interaction.guild.id, filters);
57
58 if (cases.length === 0) {
59 throw new Error(targetUser
60 ? `No moderation cases found for ${targetUser.tag}`
61 : `No ${filterType === 'all' ? '' : filterType} cases found in this server.`
62 );
63 }
64
65 const CASES_PER_PAGE = 5;
66 const totalPages = Math.ceil(cases.length / CASES_PER_PAGE);
67 let currentPage = 1;
68
69 const createCasesEmbed = (page) => {
70 const startIndex = (page - 1) * CASES_PER_PAGE;
71 const endIndex = startIndex + CASES_PER_PAGE;
72 const pageCases = cases.slice(startIndex, endIndex);
73
74 const embed = createEmbed({
75 title: 'Moderation Cases',
76 description: `Showing moderation cases for **${interaction.guild.name}**\n\n**Page ${page} of ${totalPages}**`
77 });
78
79 pageCases.forEach(case_ => {
80 const date = new Date(case_.createdAt).toLocaleDateString();
81 const time = new Date(case_.createdAt).toLocaleTimeString();
82
83 embed.addFields({
84 name: `Case #${case_.caseId} - ${case_.action}`,
85 value: `**Target:** ${case_.target}\n**Moderator:** ${case_.executor}\n**Date:** ${date} at ${time}\n**Reason:** ${case_.reason || 'No reason provided'}`,
86 inline: false
87 });
88 });
89
90 embed.setFooter({
91 text: `Total cases: ${cases.length} | Filter: ${filterType}${targetUser ?` | User: ${targetUser.tag}`: ''}`

Callers

nothing calls this directly

Calls 7

getModerationCasesFunction · 0.90
createCasesEmbedFunction · 0.85
createNavigationRowFunction · 0.85
replyUserErrorFunction · 0.85
safeDeferMethod · 0.80
followUpMethod · 0.80
editMethod · 0.80

Tested by

no test coverage detected