Skip to content

Commit

Permalink
Fixed TICKETCOUNT
Browse files Browse the repository at this point in the history
  • Loading branch information
Uo1428 committed Jun 11, 2024
1 parent dd3bb86 commit 5ed8bdc
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/utils/createTicket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Collection, EmbedBuilder, ModalSubmitInteraction, PermissionFlagsBits, StringSelectMenuInteraction, TextInputComponent } from "discord.js";
import { log } from "./logs";
import {ExtendedClient, TicketType} from "../structure";
import { ExtendedClient, TicketType } from "../structure";

/*
Copyright 2023 Sayrix (github.com/Sayrix)
Expand Down Expand Up @@ -30,12 +30,12 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
});
allReasons = reason.map((r, i) => `Question ${i + 1}: ${r}`).join(", ");
}
if(typeof reasons === "string") allReasons = reasons;
if (typeof reasons === "string") allReasons = reasons;

let ticketName = "";

let ticketCount = (await client.prisma.$queryRaw<[{count: bigint}]>
`SELECT COUNT(*) as count FROM tickets`)[0].count;
let ticketCount = (await client.prisma.$queryRaw<[{ count: bigint }]>
`SELECT COUNT(*) as count FROM tickets`)[0].count;

Check failure on line 38 in src/utils/createTicket.ts

View workflow job for this annotation

GitHub Actions / main (ubuntu-latest, 18)

Expected indentation of 2 tabs but found 3

Check failure on line 38 in src/utils/createTicket.ts

View workflow job for this annotation

GitHub Actions / main (ubuntu-latest, 18)

Expected indentation of 2 tabs but found 3

if (ticketType.ticketNameOption) {
ticketName = ticketType.ticketNameOption
Expand All @@ -48,8 +48,8 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
.replace("USERID", interaction.user.id)
.replace("TICKETCOUNT", ticketCount.toString() ?? "0");
}
if(!interaction.guild) return console.error("Interaction createTicket was not executed in a guild");
if (!interaction.guild) return console.error("Interaction createTicket was not executed in a guild");

const channel = await client.guilds.cache.get(client.config.guildId)?.channels.create({
name: ticketName,
parent: ticketType.categoryId,
Expand All @@ -72,8 +72,6 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
client
);

// Client.db is set here and incremented ticket count
ticketCount++;

await channel.permissionOverwrites
.edit(interaction.user, {
Expand All @@ -84,7 +82,7 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
ViewChannel: true,
})
.catch((e) => console.log(e));

// Role Access Stuff
if (client.config.rolesWhoHaveAccessToTheTickets.length > 0 || (ticketType.staffRoles?.length ?? 0) > 0) {
for (const role of [...client.config.rolesWhoHaveAccessToTheTickets, ...(ticketType.staffRoles ?? [])])
Expand All @@ -100,7 +98,7 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo


const footer = locale.getSubValue("embeds", "ticketOpened", "footer", "text").replace("ticket.pm", "");
if(ticketType.color?.toString().trim() === "") ticketType.color = undefined;
if (ticketType.color?.toString().trim() === "") ticketType.color = undefined;
const ticketOpenedEmbed = new EmbedBuilder({
color: 0,
})
Expand All @@ -112,7 +110,7 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
.replace("CATEGORYNAME", ticketType.name)
.replace("USERNAME", interaction.user.username)
.replace("USERID", interaction.user.id)
.replace("TICKETCOUNT", ticketCount.toString() || "0")
.replace("TICKETCOUNT", ticketCount.toString() ?? "0")
.replace("REASON1", reason[0])
.replace("REASON2", reason[1])
.replace("REASON3", reason[2])
Expand All @@ -126,7 +124,7 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
.replace("CATEGORYNAME", ticketType.name)
.replace("USERNAME", interaction.user.username)
.replace("USERID", interaction.user.id)
.replace("TICKETCOUNT", ticketCount.toString() || "0")
.replace("TICKETCOUNT", ticketCount.toString() ?? "0")
.replace("REASON1", reason[0])
.replace("REASON2", reason[1])
.replace("REASON3", reason[2])
Expand All @@ -144,6 +142,9 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo
iconURL: locale.getNoErrorSubValue("embeds", "ticketOpened", "footer", "iconUrl")
});

// Client.db is set here and incremented ticket count
ticketCount++;

const row = new ActionRowBuilder<ButtonBuilder>();

if (client.config.closeOption?.closeButton) {
Expand Down Expand Up @@ -178,9 +179,8 @@ export const createTicket = async (interaction: StringSelectMenuInteraction | Mo

const body = {
embeds: [ticketOpenedEmbed],
content: `<@${interaction.user.id}> ${
client.config.pingRoleWhenOpened ? client.config.roleToPingWhenOpenedId.map((x) => `<@&${x}>`).join(", ") : ""
}`,
content: `<@${interaction.user.id}> ${client.config.pingRoleWhenOpened ? client.config.roleToPingWhenOpenedId.map((x) => `<@&${x}>`).join(", ") : ""
}`,

Check failure on line 183 in src/utils/createTicket.ts

View workflow job for this annotation

GitHub Actions / main (ubuntu-latest, 18)

Expected indentation of 3 tabs but found 4

Check failure on line 183 in src/utils/createTicket.ts

View workflow job for this annotation

GitHub Actions / main (ubuntu-latest, 18)

Expected indentation of 3 tabs but found 4
components: [] as ActionRowBuilder<ButtonBuilder>[],
};

Expand Down

0 comments on commit 5ed8bdc

Please sign in to comment.