@@ -20,6 +20,7 @@ import { formatAgentResponse, getAgentName, getBase44Client } from './lib/base44
2020const token = process . env . DISCORD_TOKEN ;
2121const ticketCategoryId = process . env . TICKET_CATEGORY_ID || '1383178711511072928' ;
2222const closedTicketCategoryId = process . env . CLOSED_TICKET_CATEGORY_ID || '1383178786756890826' ;
23+ const TICKET_VIEW_ROLE_IDS = [ '1065741580859887707' , '1055639336286175274' ] ;
2324
2425if ( ! token ) {
2526 throw new Error ( 'Missing DISCORD_TOKEN in environment.' ) ;
@@ -79,28 +80,37 @@ async function createTicketChannel(guild, user) {
7980 const baseName = user . username . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 - ] / g, '-' ) . slice ( 0 , 70 ) ;
8081 const channelName = `${ baseName } -${ caseNumber } ` ;
8182
83+ const permissionOverwrites = [
84+ {
85+ id : guild . roles . everyone . id ,
86+ deny : [ PermissionFlagsBits . ViewChannel , PermissionFlagsBits . SendMessages ] ,
87+ } ,
88+ {
89+ id : user . id ,
90+ allow : [
91+ PermissionFlagsBits . ViewChannel ,
92+ PermissionFlagsBits . SendMessages ,
93+ PermissionFlagsBits . ReadMessageHistory ,
94+ PermissionFlagsBits . AttachFiles ,
95+ PermissionFlagsBits . EmbedLinks ,
96+ PermissionFlagsBits . AddReactions ,
97+ ] ,
98+ } ,
99+ ] ;
100+
101+ TICKET_VIEW_ROLE_IDS . forEach ( ( roleId ) => {
102+ permissionOverwrites . push ( {
103+ id : roleId ,
104+ allow : [ PermissionFlagsBits . ViewChannel ] ,
105+ } ) ;
106+ } ) ;
107+
82108 const channel = await guild . channels . create ( {
83109 name : channelName ,
84110 type : ChannelType . GuildText ,
85111 parent : category . id ,
86112 topic : `Support ticket for ${ user . tag } ` ,
87- permissionOverwrites : [
88- {
89- id : guild . roles . everyone . id ,
90- deny : [ PermissionFlagsBits . ViewChannel , PermissionFlagsBits . SendMessages ] ,
91- } ,
92- {
93- id : user . id ,
94- allow : [
95- PermissionFlagsBits . ViewChannel ,
96- PermissionFlagsBits . SendMessages ,
97- PermissionFlagsBits . ReadMessageHistory ,
98- PermissionFlagsBits . AttachFiles ,
99- PermissionFlagsBits . EmbedLinks ,
100- PermissionFlagsBits . AddReactions ,
101- ] ,
102- } ,
103- ] ,
113+ permissionOverwrites,
104114 } ) ;
105115
106116 return channel ;
@@ -119,6 +129,14 @@ async function closeTicketChannel(channel, user) {
119129
120130 await channel . setParent ( closedCategory . id , { lockPermissions : false } ) ;
121131
132+ await Promise . all (
133+ TICKET_VIEW_ROLE_IDS . map ( ( roleId ) =>
134+ channel . permissionOverwrites . edit ( roleId , {
135+ ViewChannel : true ,
136+ } ) . catch ( ( ) => null )
137+ )
138+ ) ;
139+
122140 await channel . permissionOverwrites . edit ( user . id , {
123141 SendMessages : false ,
124142 AddReactions : false ,
0 commit comments