MCPcopy Create free account
hub / github.com/Sayrix/Ticket-Bot / createTicket

Function createTicket

src/utils/createTicket.ts:28–232  ·  view source on GitHub ↗
(
	interaction: StringSelectMenuInteraction | ModalSubmitInteraction,
	client: ExtendedClient,
	ticketType: TicketType,
	reasons?: Collection<string, TextInputComponent> | string
)

Source from the content-addressed store, hash-verified

26 * @param {Object|string} reasons
27 */
28export const createTicket = async (
29 interaction: StringSelectMenuInteraction | ModalSubmitInteraction,
30 client: ExtendedClient,
31 ticketType: TicketType,
32 reasons?: Collection<string, TextInputComponent> | string
33) => {
34 const locale = client.locales;
35 // eslint-disable-next-line no-async-promise-executor
36 return new Promise(async function (resolve, reject) {
37 await interaction.deferReply({ ephemeral: true }).catch((e) => console.log(e));
38
39 const reason: string[] = [];
40 let allReasons = "";
41
42 if (typeof reasons === "object") {
43 reasons.forEach(async (r) => {
44 reason.push(r.value);
45 });
46 allReasons = reason.map((r, i) => `Question ${i + 1}: ${r}`).join(", ");
47 }
48 if (typeof reasons === "string") allReasons = reasons;
49
50 let ticketName = "";
51
52 let ticketCount = (await client.prisma.$queryRaw<[{ count: bigint }]>`SELECT COUNT(*) as count FROM tickets`)[0].count;
53
54 if (ticketType.ticketNameOption) {
55 ticketName = ticketType.ticketNameOption
56 .replace("USERNAME", interaction.user.username)
57 .replace("USERID", interaction.user.id)
58 .replace("TICKETCOUNT", ticketCount.toString() ?? "0");
59 } else {
60 ticketName = client.config.ticketNameOption
61 .replace("USERNAME", interaction.user.username)
62 .replace("USERID", interaction.user.id)
63 .replace("TICKETCOUNT", ticketCount.toString() ?? "0");
64 }
65 if (!interaction.guild) return console.error("Interaction createTicket was not executed in a guild");
66
67 const channel = await client.guilds.cache.get(client.config.guildId)?.channels.create({
68 name: ticketName,
69 parent: ticketType.categoryId,
70 permissionOverwrites: [
71 {
72 id: interaction.guild.roles.everyone,
73 deny: [PermissionFlagsBits.ViewChannel]
74 }
75 ]
76 });
77
78 if (!channel) return reject("Couldn't create the ticket channel.");
79 log(
80 {
81 LogType: "ticketCreate",
82 user: interaction.user,
83 reason: allReasons,
84 ticketChannelId: channel.id
85 },

Callers 1

executeMethod · 0.90

Calls 4

logFunction · 0.90
getSubValueMethod · 0.80
getNoErrorSubValueMethod · 0.80
getValueMethod · 0.80

Tested by

no test coverage detected