all repos — stealth-developers @ 5b4e11e209be50e047f45841492df7729088bfa6

apps/bot/src/feats/tickets/misc.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
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];