1
1
import {
2
+ PermissionFlagsBits ,
2
3
ChannelType ,
3
4
type ChatInputCommandInteraction ,
4
5
DMChannel ,
6
+ type Channel ,
7
+ type User ,
5
8
type Message ,
6
9
type NonThreadGuildBasedChannel ,
7
10
} from 'discord.js' ;
@@ -62,10 +65,23 @@ export const reactOnEndWithQuoi = async (message: Message) => {
62
65
await reactWithFeur ( message ) ;
63
66
} ;
64
67
65
- export const addQuoiFeurToChannel = async ( interaction : ChatInputCommandInteraction ) => {
66
- const { channel } = interaction ;
67
- if ( ! channel || ! channel . isTextBased ( ) || channel . type !== ChannelType . GuildText ) return ;
68
+ const isOwner = ( channel : Channel , user : User ) => {
69
+ if ( channel . type == ChannelType . PublicThread ) {
70
+ if ( user . id == channel . ownerId ) return true ;
71
+ }
72
+ console . log ( "lol" ) ;
73
+ return ;
74
+ }
68
75
76
+ export const addQuoiFeurToChannel = async ( interaction : ChatInputCommandInteraction ) => {
77
+ const { channel, memberPermissions, user } = interaction ;
78
+
79
+ if ( ! memberPermissions || ! channel || ! channel . isTextBased ( ) || ( channel . type !== ChannelType . GuildText && channel . type !== ChannelType . PublicThread ) ) return ;
80
+ if ( ! memberPermissions . has ( PermissionFlagsBits . ManageChannels ) && ! isOwner ( channel , user ) ) {
81
+ await interaction . reply ( { content : 'You don\'t have permissions to enable Quoi-feur in this channel' , ephemeral : true } ) ;
82
+ return ;
83
+ }
84
+
69
85
const channels = await cache . get ( 'quoiFeurChannels' , [ ] ) ;
70
86
if ( channels . includes ( channel . id ) ) {
71
87
await interaction . reply ( {
@@ -80,9 +96,14 @@ export const addQuoiFeurToChannel = async (interaction: ChatInputCommandInteract
80
96
} ;
81
97
82
98
export const removeQuoiFeurFromChannel = async ( interaction : ChatInputCommandInteraction ) => {
83
- const { channel } = interaction ;
84
- if ( ! channel || ! channel . isTextBased ( ) || channel . type !== ChannelType . GuildText ) return ;
99
+ const { channel, memberPermissions, user } = interaction ;
85
100
101
+ if ( ! memberPermissions || ! channel || ! channel . isTextBased ( ) || ( channel . type !== ChannelType . GuildText && channel . type !== ChannelType . PublicThread ) ) return ;
102
+ if ( ! memberPermissions . has ( PermissionFlagsBits . ManageChannels ) && ! isOwner ( channel , user ) ) {
103
+ await interaction . reply ( { content : 'You don\'t have permissions to disable Quoi-feur in this channel' , ephemeral : true } ) ;
104
+ return ;
105
+ }
106
+
86
107
const channels = await cache . get ( 'quoiFeurChannels' , [ ] ) ;
87
108
if ( ! channels . includes ( channel . id ) ) {
88
109
await interaction . reply ( {
0 commit comments