Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed TICKETCOUNT #364

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
});
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 @@
.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 @@
client
);

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

await channel.permissionOverwrites
.edit(interaction.user, {
Expand All @@ -84,7 +82,7 @@
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 @@


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 @@
.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 @@
.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 @@
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 @@

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
Loading