File tree Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Expand file tree Collapse file tree 2 files changed +19
-15
lines changed Original file line number Diff line number Diff line change 1
1
import { config } from "@lib/config.js" ;
2
2
3
3
import {
4
- canUserInteractWithThread ,
4
+ canMemberInteractWithThread ,
5
5
getChannelFromInteraction ,
6
6
isHelpPost ,
7
7
} from "@lib/channels.js" ;
@@ -15,7 +15,7 @@ import {
15
15
16
16
// TODO: find a better way to do this
17
17
const getStateWord = ( close ) => ( close ? "closed" : "reopened" ) ;
18
- const getStateVerb = ( close ) => ( close ? "close" : "reopene " ) ;
18
+ const getStateVerb = ( close ) => ( close ? "close" : "reopen " ) ;
19
19
20
20
export async function handleIssueState (
21
21
interaction : ChatInputCommandInteraction ,
@@ -85,11 +85,10 @@ export async function handleIssueStateCommand(
85
85
86
86
// Check if thread is a help post and if user can interact
87
87
if ( await isHelpPost ( interactionChannel ) ) {
88
+ const member = await interaction . guild . members . fetch ( interaction . user . id ) ;
89
+
88
90
if (
89
- canUserInteractWithThread (
90
- interaction . channel as ThreadChannel ,
91
- interaction . user ,
92
- )
91
+ await canMemberInteractWithThread ( interaction . channel as ThreadChannel , member )
93
92
) {
94
93
return handleIssueState ( interaction , close , lock ) ;
95
94
} else {
Original file line number Diff line number Diff line change 4
4
type ChatInputCommandInteraction ,
5
5
ChannelType ,
6
6
type ThreadChannel ,
7
- type User ,
8
7
type GuildTextBasedChannel ,
8
+ PermissionsBitField ,
9
+ type GuildMember ,
9
10
} from "discord.js" ;
10
11
11
12
export async function getChannelFromInteraction (
@@ -36,14 +37,18 @@ export async function isHelpPost(channel: GuildTextBasedChannel) {
36
37
) ;
37
38
}
38
39
39
- export async function canUserInteractWithThread (
40
+ export async function canMemberInteractWithThread (
40
41
channel : ThreadChannel ,
41
- user : User ,
42
+ member : GuildMember ,
42
43
) {
43
- /*const threadChannel: ThreadChannel<true> = await interaction.client.channels.fetch(interaction.channelId) as ThreadChannel;
44
-
45
- const firstMessage = await threadChannel.fetchStarterMessage();*/
46
-
47
- // TODO: actually check
48
- return true ;
44
+ if ( member . permissions . has ( PermissionsBitField . Flags . ManageChannels ) ) {
45
+ return true ;
46
+ } else {
47
+ // Sometimes fetchOwner() will fail, so this is just a failsafe
48
+ const owner =
49
+ ( await channel . fetchOwner ( ) ) ?. guildMember ??
50
+ ( await channel . fetchStarterMessage ( ) ) . member ;
51
+
52
+ return member . id === owner . id ;
53
+ }
49
54
}
You can’t perform that action at this time.
0 commit comments