-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathreport.ts
More file actions
87 lines (74 loc) · 2.74 KB
/
report.ts
File metadata and controls
87 lines (74 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { ApplicationCommandType } from "discord-api-types/v10";
import {
ContextMenuCommandBuilder,
PermissionFlagsBits,
type MessageContextMenuCommandInteraction,
} from "discord.js";
import { ReportReasons } from "#~/effects/models/reportedMessages.js";
import { commandStats } from "#~/helpers/metrics";
import { reportUser } from "#~/helpers/modLog";
import { log, trackPerformance } from "#~/helpers/observability";
const command = new ContextMenuCommandBuilder()
.setName("Report")
.setType(ApplicationCommandType.Message)
.setDefaultMemberPermissions(PermissionFlagsBits.SendMessages);
const handler = async (interaction: MessageContextMenuCommandInteraction) => {
await trackPerformance(
"reportCommand",
async () => {
const { targetMessage: message } = interaction;
log("info", "Commands", "Report command executed", {
guildId: interaction.guildId,
reporterUserId: interaction.user.id,
targetUserId: message.author.id,
targetMessageId: message.id,
channelId: interaction.channelId,
});
try {
await reportUser({
reason: ReportReasons.anonReport,
message,
staff: false,
});
log("info", "Commands", "Report submitted successfully", {
guildId: interaction.guildId,
reporterUserId: interaction.user.id,
targetUserId: message.author.id,
targetMessageId: message.id,
reason: ReportReasons.anonReport,
});
// Track successful report in business analytics
commandStats.reportSubmitted(interaction, message.author.id);
// Track command success
commandStats.commandExecuted(interaction, "report", true);
await interaction.reply({
ephemeral: true,
content: "This message has been reported anonymously",
});
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
log("error", "Commands", "Report command failed", {
guildId: interaction.guildId,
reporterUserId: interaction.user.id,
targetUserId: message.author.id,
targetMessageId: message.id,
error: err.message,
stack: err.stack,
});
// Track command failure in business analytics
commandStats.commandFailed(interaction, "report", err.message);
await interaction.reply({
ephemeral: true,
content: "Failed to submit report. Please try again later.",
});
}
},
{
commandName: "report",
guildId: interaction.guildId,
reporterUserId: interaction.user.id,
targetUserId: interaction.targetMessage.author.id,
},
);
};
export const Command = { handler, command };