(channel, client)
| 11 | export default { |
| 12 | name: 'channelDelete', |
| 13 | async execute(channel, client) { |
| 14 | |
| 15 | if (channel.type === 0 && channel.guild) { |
| 16 | try { |
| 17 | const ticketData = await getTicketData(channel.guild.id, channel.id); |
| 18 | if (ticketData && ticketData.status === 'open') { |
| 19 | ticketData.status = 'deleted'; |
| 20 | ticketData.closedAt = new Date().toISOString(); |
| 21 | await saveTicketData(channel.guild.id, channel.id, ticketData); |
| 22 | logger.info(`Ticket channel ${channel.id} was manually deleted in guild ${channel.guild.id}, marked as deleted`); |
| 23 | } |
| 24 | } catch (err) { |
| 25 | logger.warn(`Could not clean up ticket record for deleted channel ${channel.id}:`, err); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | if (channel.type !== 2 && channel.type !== 4) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | const guildId = channel.guild.id; |
| 34 | |
| 35 | try { |
| 36 | |
| 37 | const counters = await getServerCounters(client, guildId); |
| 38 | const orphanedCounter = counters.find(c => c.channelId === channel.id); |
| 39 | |
| 40 | if (orphanedCounter) { |
| 41 | logger.info(`Counter channel ${channel.name} (${channel.id}) was deleted, removing counter ${orphanedCounter.id} from database`); |
| 42 | |
| 43 | const updatedCounters = counters.filter(c => c.channelId !== channel.id); |
| 44 | const success = await saveServerCounters(client, guildId, updatedCounters); |
| 45 | |
| 46 | if (success) { |
| 47 | logger.info(`Successfully removed orphaned counter ${orphanedCounter.id} (type: ${orphanedCounter.type}) from guild ${guildId}`); |
| 48 | } else { |
| 49 | logger.warn(`Failed to remove orphaned counter ${orphanedCounter.id} from guild ${guildId}`); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | const config = await getJoinToCreateConfig(client, guildId); |
| 54 | |
| 55 | if (!config.enabled) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (config.triggerChannels.includes(channel.id)) { |
| 60 | logger.info(`Join to Create trigger channel ${channel.name} (${channel.id}) was deleted, removing from configuration`); |
| 61 | |
| 62 | const success = await removeJoinToCreateTrigger(client, guildId, channel.id); |
| 63 | if (success) { |
| 64 | logger.info(`Successfully removed trigger channel ${channel.id} from Join to Create configuration`); |
| 65 | } else { |
| 66 | logger.warn(`Failed to remove trigger channel ${channel.id} from Join to Create configuration`); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if (config.temporaryChannels[channel.id]) { |
nothing calls this directly
no test coverage detected