From 4d7583785ba175d80b7e7ee79256f43f09312b11 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 18 Dec 2021 22:14:11 -0600 Subject: [PATCH] Fixed ticket id --- Commands/close.js | 20 +++++++------- Data/TicketData.json | 1 - Data/ticket-panel-id.json | 5 +++- Structures/TicketID.js | 55 ++++++++++----------------------------- 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/Commands/close.js b/Commands/close.js index 22a251d..7c7d27a 100644 --- a/Commands/close.js +++ b/Commands/close.js @@ -49,18 +49,19 @@ module.exports = new Command({ await interaction.deferReply(); let tickets = await JSON.parse( fs.readFileSync("./Data/TicketData.json", "utf8") - ).tickets.find((t) => t.id === interaction.channel.id); - let TicketData = await tickets.tickets.findIndex( - (t) => t.id == ticketChannel.id ); - if (!TicketData) { + let TicketData = await tickets.tickets.findIndex( + (t) => t.id == interaction.channel.id + ); + let ticket = tickets.tickets[TicketData]; + if (TicketData == -1) { const Exists = new Discord.MessageEmbed() .setTitle("No Ticket Found!") .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); return interaction.followUp({ embeds: [Exists] }); } - let tUser = interaction.client.users.cache.get(TicketData.user); + let tUser = interaction.client.users.cache.get(ticket.user); let transcriptChannel = await getChannel( supportbot.TranscriptLog, interaction.guild @@ -107,10 +108,7 @@ module.exports = new Command({ "Ticket", `${interaction.channel.name} (${interaction.channel.id})` ) - .addField( - "User", - `${tUser.username}#${tUser.discriminator} (${tUser.id})` - ) + .addField("User", `${tUser}#${tUser.discriminator} (${tUser.id})`) .addField("Closed By", interaction.user.tag) .addField("Reason", reason); const logEmbed = new Discord.MessageEmbed() @@ -162,8 +160,8 @@ module.exports = new Command({ .catch(async (err) => { console.error(err); }); - if (TicketData.subUsers) { - TicketData.subUsers.forEach(async (subUser) => { + if (ticket.subUsers) { + ticket.subUsers.forEach(async (subUser) => { interaction.client.users.cache .get(subUser) .send({ embeds: [transcriptEmbed], files: [file] }); diff --git a/Data/TicketData.json b/Data/TicketData.json index f97612b..c47c857 100644 --- a/Data/TicketData.json +++ b/Data/TicketData.json @@ -1,4 +1,3 @@ { - "id": 0, "tickets": [] } diff --git a/Data/ticket-panel-id.json b/Data/ticket-panel-id.json index ad5728f..feb5b04 100644 --- a/Data/ticket-panel-id.json +++ b/Data/ticket-panel-id.json @@ -1 +1,4 @@ -{"TicketPanelID":""} \ No newline at end of file +{ + "id": 0, + "TicketPanelID": "" +} diff --git a/Structures/TicketID.js b/Structures/TicketID.js index 4e5bb24..610a515 100644 --- a/Structures/TicketID.js +++ b/Structures/TicketID.js @@ -5,44 +5,31 @@ const fs = require("fs"); class TicketNumberID { static async pad() { - let n = this.get() + ""; - let z = "0"; - let width = 4; - await this.set(this.get() + 1); - return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; + let num = await this.get(); + let n = num + ""; + await this.set(num + 1); + return n.length >= 4 ? n : new Array(4 - n.length + 1).join("0") + n; } - static get() { - let ticketnumberID = JSON.parse( - fs.readFileSync("./Data/TicketData.json", "utf8") + static async get() { + let ticketnumberID = await JSON.parse( + fs.readFileSync("./Data/ticket-panel-id.json", "utf8") ); - if (!ticketnumberID.id) { - ticketnumberID.id = 0; - - fs.writeFileSync( - "./Data/TicketData.json", - JSON.stringify(ticketnumberID, null, 4), - (err) => { - if (err) console.error(err); - } - ); - - return 0; + return this.set(0); } else { return ticketnumberID.id; } } - static set(value) { - let ticketnumberID = JSON.parse( - fs.readFileSync("./Data/TicketData.json", "utf8") + static async set(value) { + let ticketnumberID = await JSON.parse( + fs.readFileSync("./Data/ticket-panel-id.json", "utf8") ); ticketnumberID.id = value; - fs.writeFileSync( - "./Data/TicketData.json", + "./Data/ticket-panel-id.json", JSON.stringify(ticketnumberID, null, 4), (err) => { if (err) console.error(err); @@ -52,22 +39,8 @@ class TicketNumberID { return value; } - static reset() { - let ticketnumberID = JSON.parse( - fs.readFileSync("./Data/TicketData.json", "utf8") - ); - - ticketnumberID.id = 0; - - fs.writeFileSync( - "./Data/TicketData.json", - JSON.stringify(ticketnumberID, null, 4), - (err) => { - if (err) console.error(err); - } - ); - - return 0; + static async reset() { + return await this.set(0); } }