File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { config } from "@lib/config.js" ;
22
33import {
4- canUserInteractWithThread ,
4+ canMemberInteractWithThread ,
55 getChannelFromInteraction ,
66 isHelpPost ,
77} from "@lib/channels.js" ;
@@ -15,7 +15,7 @@ import {
1515
1616// TODO: find a better way to do this
1717const getStateWord = ( close ) => ( close ? "closed" : "reopened" ) ;
18- const getStateVerb = ( close ) => ( close ? "close" : "reopene " ) ;
18+ const getStateVerb = ( close ) => ( close ? "close" : "reopen " ) ;
1919
2020export async function handleIssueState (
2121 interaction : ChatInputCommandInteraction ,
@@ -85,11 +85,10 @@ export async function handleIssueStateCommand(
8585
8686 // Check if thread is a help post and if user can interact
8787 if ( await isHelpPost ( interactionChannel ) ) {
88+ const member = await interaction . guild . members . fetch ( interaction . user . id ) ;
89+
8890 if (
89- canUserInteractWithThread (
90- interaction . channel as ThreadChannel ,
91- interaction . user ,
92- )
91+ await canMemberInteractWithThread ( interaction . channel as ThreadChannel , member )
9392 ) {
9493 return handleIssueState ( interaction , close , lock ) ;
9594 } else {
Original file line number Diff line number Diff line change 44 type ChatInputCommandInteraction ,
55 ChannelType ,
66 type ThreadChannel ,
7- type User ,
87 type GuildTextBasedChannel ,
8+ PermissionsBitField ,
9+ type GuildMember ,
910} from "discord.js" ;
1011
1112export async function getChannelFromInteraction (
@@ -36,14 +37,18 @@ export async function isHelpPost(channel: GuildTextBasedChannel) {
3637 ) ;
3738}
3839
39- export async function canUserInteractWithThread (
40+ export async function canMemberInteractWithThread (
4041 channel : ThreadChannel ,
41- user : User ,
42+ member : GuildMember ,
4243) {
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+ }
4954}
You can’t perform that action at this time.
0 commit comments