Skip to content

Commit ddae9ed

Browse files
authored
Add permissions gates to new escalate controls (#127)
1 parent 6cf287d commit ddae9ed

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

app/helpers/escalate.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChannelType } from "discord.js";
1+
import { ChannelType, PermissionsBitField } from "discord.js";
22
import type { Message, TextChannel, ThreadChannel, User } from "discord.js";
33

44
import { reacord } from "#~/discord/client.server";
@@ -18,10 +18,18 @@ export async function escalationControls(
1818
) {
1919
reacord.createChannelMessage(thread.id).render(
2020
<>
21+
Moderator controls
2122
<Button
2223
label="Delete"
2324
style="danger"
2425
onClick={async (e) => {
26+
const { guild } = reportedMessage;
27+
const actor = await guild?.members.fetch(e.user.id);
28+
if (
29+
!actor?.permissions.has(PermissionsBitField.Flags.ManageMessages)
30+
) {
31+
return;
32+
}
2533
await Promise.allSettled([
2634
reportedMessage.delete(),
2735
e.reply(`deleted by ${e.user.username}`),
@@ -30,14 +38,9 @@ export async function escalationControls(
3038
/>
3139
<Button
3240
onClick={async (e) => {
33-
const member = await thread.guild.members.fetch(e.user.id);
34-
escalate(member.user, reportedMessage, thread, modRoleId);
35-
}}
36-
style="primary"
37-
label="Escalate"
38-
/>
39-
<Button
40-
onClick={async (e) => {
41+
if (!e.guild?.member.roles?.includes(modRoleId)) {
42+
return;
43+
}
4144
console.log(
4245
"escalationControls",
4346
`${reportedMessage.author.username} kicked by ${e.user.username}`,
@@ -54,6 +57,9 @@ export async function escalationControls(
5457
/>
5558
<Button
5659
onClick={async (e) => {
60+
if (!e.guild?.member.roles?.includes(modRoleId)) {
61+
return;
62+
}
5763
console.log(
5864
"escalationControls",
5965
`${reportedMessage.author.username} banned by ${e.user.username}`,
@@ -70,6 +76,20 @@ export async function escalationControls(
7076
/>
7177
</>,
7278
);
79+
reacord.createChannelMessage(thread.id).render(
80+
<>
81+
Anyone can escalate, which will notify moderators and call for a vote on
82+
how to respond.
83+
<Button
84+
onClick={async (e) => {
85+
const member = await thread.guild.members.fetch(e.user.id);
86+
escalate(member.user, reportedMessage, thread, modRoleId);
87+
}}
88+
style="primary"
89+
label="Escalate"
90+
/>
91+
</>,
92+
);
7393
}
7494

7595
export async function escalate(

0 commit comments

Comments
 (0)