import { getTicketByGuild } from "@stealth-developers/db"; import { errorMessage } from "@/lib"; import { useGetData } from "@/middleware"; import { getTicketContainer } from "./actions"; import { hasAccessToTicket } from "./lib"; export const viewTicketMenu = useGetData.selectMenu("s-get-ticket", { async run(interaction, _, ctx) { if (!interaction.isStringSelectMenu()) { return errorMessage(interaction, "This is not a string select menu interaction."); } else if (!ctx.guild) { return errorMessage(interaction, "Failed to retrieve guild data."); } else if (!ctx.actor) { return errorMessage(interaction, "Failed to fetch your data."); } const ticketId = Number(interaction.values[0]); const ticket = await getTicketByGuild(ctx.guild.id, ticketId); if (!ticket) return errorMessage(interaction, "Ticket not found."); if (!hasAccessToTicket(ctx.actor, ctx.guild, ticket)) return errorMessage(interaction, "You do not have access to this ticket."); const container = getTicketContainer(ticket, !ctx.actor.moderator); interaction.reply({ components: [container], flags: ["Ephemeral", "IsComponentsV2"], }); }, }); export const MiscTicketComponents = [viewTicketMenu];