1
- import { ChannelType } from "discord.js" ;
1
+ import { ChannelType , PermissionsBitField } from "discord.js" ;
2
2
import type { Message , TextChannel , ThreadChannel , User } from "discord.js" ;
3
3
4
4
import { reacord } from "#~/discord/client.server" ;
@@ -18,10 +18,18 @@ export async function escalationControls(
18
18
) {
19
19
reacord . createChannelMessage ( thread . id ) . render (
20
20
< >
21
+ Moderator controls
21
22
< Button
22
23
label = "Delete"
23
24
style = "danger"
24
25
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
+ }
25
33
await Promise . allSettled ( [
26
34
reportedMessage . delete ( ) ,
27
35
e . reply ( `deleted by ${ e . user . username } ` ) ,
@@ -30,14 +38,9 @@ export async function escalationControls(
30
38
/>
31
39
< Button
32
40
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
+ }
41
44
console . log (
42
45
"escalationControls" ,
43
46
`${ reportedMessage . author . username } kicked by ${ e . user . username } ` ,
@@ -54,6 +57,9 @@ export async function escalationControls(
54
57
/>
55
58
< Button
56
59
onClick = { async ( e ) => {
60
+ if ( ! e . guild ?. member . roles ?. includes ( modRoleId ) ) {
61
+ return ;
62
+ }
57
63
console . log (
58
64
"escalationControls" ,
59
65
`${ reportedMessage . author . username } banned by ${ e . user . username } ` ,
@@ -70,6 +76,20 @@ export async function escalationControls(
70
76
/>
71
77
</ > ,
72
78
) ;
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
+ ) ;
73
93
}
74
94
75
95
export async function escalate (
0 commit comments