Skip to content

Commit 401b0f4

Browse files
committed
Add report command
1 parent 1ad0d16 commit 401b0f4

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

app/commands/report.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ContextMenuCommandBuilder } from "@discordjs/builders";
2+
import { ApplicationCommandType } from "discord-api-types/v10";
3+
import type { MessageContextMenuInteraction } from "discord.js";
4+
import { Message } from "discord.js";
5+
import { ReportReasons, reportUser } from "../helpers/modLog";
6+
7+
export default new ContextMenuCommandBuilder()
8+
.setName("Report")
9+
.setType(ApplicationCommandType.Message);
10+
11+
export const handler = async (interaction: MessageContextMenuInteraction) => {
12+
const message = interaction.targetMessage;
13+
if (!(message instanceof Message)) {
14+
return;
15+
}
16+
17+
await reportUser({ reason: ReportReasons.anonReport, message });
18+
19+
await interaction.reply({
20+
ephemeral: true,
21+
content: "This message has been reported anonymously",
22+
});
23+
};

app/discord/deployCommands.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { applicationId, discordToken } from "~/helpers/env";
77
import { difference } from "~/helpers/sets";
88

99
import setup from "~/commands/setup";
10+
import report from "~/commands/report";
1011

1112
export const deployCommands = async (client: Client) => {
1213
const guilds = await client.guilds.fetch();
@@ -15,7 +16,7 @@ export const deployCommands = async (client: Client) => {
1516
);
1617
};
1718

18-
const commands = [setup].map((x) => x.toJSON());
19+
const commands = [setup, report].map((x) => x.toJSON());
1920
const names = new Set(commands.map((c) => c.name));
2021

2122
const rest = new REST({ version: "10" }).setToken(discordToken);

app/discord/gateway.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import onboardCommand, { handler as onboardHandler } from "~/commands/setup";
2+
import reportCommand, { handler as reportHandler } from "~/commands/report";
23

34
import automod from "~/discord/automod";
45
import onboardGuild from "~/discord/onboardGuild";
@@ -22,6 +23,11 @@ export default function init() {
2223
case onboardCommand.name:
2324
return onboardHandler(interaction);
2425
}
26+
} else if (interaction.isMessageContextMenu()) {
27+
switch (interaction.commandName) {
28+
case reportCommand.name:
29+
return reportHandler(interaction);
30+
}
2531
}
2632
});
2733

0 commit comments

Comments
 (0)