all repos — stealth-developers @ ffa2c91027d77bb42b875d24dd139172e61aa2c3

src/interactions/commands/tickets/modals.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
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
import { parseComponentId } from "@/utils/components";
import { loggers } from "@/utils/logging";
import { getGuild, getTicket } from "@/utils/queries";
import type { Client, ModalSubmitInteraction } from "discord.js";
import { INPUT_IDS } from "./_shared";
import { handleClose } from "./actions";

const logger = loggers.interactions.child({ name: "ticket/modals" });

export async function handleReasonModal(
	_client: Client,
	interaction: ModalSubmitInteraction,
) {
	await interaction.deferReply({ flags: ["Ephemeral"] });

	if (!interaction.channelId || !interaction.guildId) {
		await interaction.editReply({
			content: "This command can only be used in a server.",
		});
		return;
	}

	const publicReason = interaction.fields.getTextInputValue(INPUT_IDS.REASON);
	let privateReason = "";
	try {
		privateReason = interaction.fields.getTextInputValue(
			INPUT_IDS.PRIVATE_REASON,
		);
	} catch {}

	const { data: ticket, exists } = await getTicket(
		interaction.guildId,
		interaction.channelId,
	);
	if (!exists || !ticket) {
		await interaction.editReply({
			content: "❌ This channel is not a valid ticket.",
		});
		return;
	}

	const { data: guildData } = await getGuild(interaction.guildId);
	await handleClose(interaction.client, interaction, ticket, guildData, {
		publicReason: publicReason || undefined,
		privateReason: privateReason || undefined,
	});
}