11import { buildEmbed } from '../utils/embed' ;
2- import { getGuildConfig } from '../config/store' ;
2+ import { getGuildConfig , upsertGuildConfig } from '../config/store' ;
33
44const EPHEMERAL_FLAG = 1 << 6 ; // Discord API flag
55
@@ -23,21 +23,24 @@ export default {
2323 // Remove the user's reaction to keep the trigger clean
2424 await reaction . users . remove ( user . id ) . catch ( ( ) => { } ) ;
2525
26- // Enforce one open ticket per user: if a category with their ticket name exists, ping them in their ticket text channel instead of creating a new one.
27- const existingCategory : any = guild . channels . cache . find (
28- ( ch : any ) => ch . type === 4 && ch . name === `ticket-${ user . username } ` ,
29- ) ;
30- if ( existingCategory ) {
31- const ticketText = guild . channels . cache . find (
32- ( ch : any ) =>
33- ch . parentId === existingCategory . id && ch . name === `ticket-${ user . username } -txt` ,
34- ) ;
26+ const openTickets = cfg . openTickets || { } ;
27+ const existingTicket = openTickets [ user . id ] ;
28+
29+ // Enforce one open ticket per user: if exists, ping in their ticket text channel
30+ if ( existingTicket ) {
31+ const ticketText = existingTicket . textId
32+ ? guild . channels . cache . get ( existingTicket . textId )
33+ : guild . channels . cache . find (
34+ ( ch : any ) =>
35+ ch . parentId === existingTicket . categoryId &&
36+ ch . name === `ticket-${ user . username } -txt` ,
37+ ) ;
3538 const notifyPayload = {
3639 content : `<@${ user . id } > ya tienes un ticket abierto.` ,
3740 flags : EPHEMERAL_FLAG ,
3841 } ;
3942 if ( ticketText && ticketText . isTextBased ?.( ) ) {
40- await ticketText . send ( notifyPayload ) . catch ( ( ) => { } ) ;
43+ await ( ticketText as any ) . send ( notifyPayload ) . catch ( ( ) => { } ) ;
4144 } else {
4245 await reaction . message . channel . send ( notifyPayload ) . catch ( ( ) => { } ) ;
4346 }
@@ -79,6 +82,10 @@ export default {
7982 } ) ) ,
8083 } ) ;
8184
85+ // Persist open ticket for this user
86+ openTickets [ user . id ] = { categoryId : category . id , textId : text . id , voiceId : voice . id } ;
87+ upsertGuildConfig ( { ...cfg , guildId : guild . id , openTickets } ) ;
88+
8289 const embed = buildEmbed ( {
8390 title : 'Ticket creado' ,
8491 description : 'Un miembro de JUNTA te atenderá pronto.' ,
0 commit comments