({ client, guildId, event })
| 10 | } from './logEmbeds.js'; |
| 11 | |
| 12 | export async function logTicketEvent({ client, guildId, event }) { |
| 13 | try { |
| 14 | const guild = client.guilds.cache.get(guildId) || await client.guilds.fetch(guildId).catch(() => null); |
| 15 | if (!guild) { |
| 16 | logger.warn(`logTicketEvent invoked without valid guild: ${guildId}`); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | const config = await getGuildConfig(client, guildId); |
| 21 | |
| 22 | const logChannelId = getLogChannelForEventType(config, event.type); |
| 23 | if (!logChannelId) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const channel = guild.channels.cache.get(logChannelId) || await guild.channels.fetch(logChannelId).catch(() => null); |
| 28 | if (!channel) { |
| 29 | logger.warn(`Ticket log channel not found: ${logChannelId} for event type: ${event.type}`); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | const permissions = channel.permissionsFor(guild.members.me); |
| 34 | if (!permissions.has(['SendMessages', 'EmbedLinks'])) { |
| 35 | logger.warn(`Missing permissions in ticket log channel: ${logChannelId}`); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | const embed = await createTicketLogEmbed(guild, event); |
| 40 | |
| 41 | const messageOptions = { embeds: [embed] }; |
| 42 | |
| 43 | if (event.attachments && event.attachments.length > 0) { |
| 44 | messageOptions.files = event.attachments; |
| 45 | } |
| 46 | |
| 47 | await channel.send(messageOptions); |
| 48 | logger.info(`Ticket event logged: ${event.type} in guild ${guildId}`); |
| 49 | } catch (error) { |
| 50 | logger.error('Error logging ticket event:', error); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | export async function logTicketFeedback({ |
| 55 | client, |
no test coverage detected