MCPcopy
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Moderation/warnings.js:22–102  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

20 category: "moderation",
21
22 async execute(interaction, config, client) {
23 const deferSuccess = await InteractionHelper.safeDefer(interaction);
24 if (!deferSuccess) {
25 logger.warn(`Warnings interaction defer failed`, {
26 userId: interaction.user.id,
27 guildId: interaction.guildId,
28 commandName: 'warnings'
29 });
30 return;
31 }
32
33 try {
34 const target = interaction.options.getUser("target");
35 const guildId = interaction.guildId;
36
37 const validWarnings = await WarningService.getWarnings(guildId, target.id);
38 const totalWarns = validWarnings.length;
39
40 if (totalWarns === 0) {
41 await InteractionHelper.safeEditReply(interaction, {
42 embeds: [
43 createEmbed({
44 title: `Warnings: ${target.tag}`,
45 description: "This user has no recorded warnings."
46 }).setColor(getColor('success')),
47 ],
48 });
49 return;
50 }
51
52 const embed = createEmbed({
53 title: `Warnings: ${target.tag}`,
54 description: `Total Warnings: **${totalWarns}**`
55 }).setColor(getColor('warning'));
56
57 const warningFields = validWarnings
58 .map((w, i) => {
59 const discordTimestamp = Math.floor(w.timestamp / 1000);
60 return {
61 name: `[#${i + 1}] Reason: ${w.reason.substring(0, 100)}`,
62 value: `**Moderator:** <@${w.moderatorId}>\n**Date:** <t:${discordTimestamp}:F> (<t:${discordTimestamp}:R>)`,
63 inline: false,
64 };
65 })
66 .slice(0, 25);
67
68 embed.addFields(warningFields);
69
70 const actionRow = new ActionRowBuilder().addComponents(
71 new ButtonBuilder()
72 .setCustomId(`warning_delete_specific:${target.id}:${interaction.user.id}`)
73 .setLabel('Delete Specific Warning')
74 .setStyle(ButtonStyle.Danger),
75 new ButtonBuilder()
76 .setCustomId(`warning_clear_all:${target.id}:${interaction.user.id}`)
77 .setLabel('Clear All Warnings')
78 .setStyle(ButtonStyle.Danger)
79 );

Callers

nothing calls this directly

Calls 7

createEmbedFunction · 0.90
getColorFunction · 0.90
logEventFunction · 0.90
handleInteractionErrorFunction · 0.90
safeDeferMethod · 0.80
getWarningsMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected