From b6a0016f5f3fb3ede85c757c60724ae1c61da7f5 Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 23 Nov 2021 15:48:45 -0600 Subject: [PATCH] Changed TicketData Structure --- Commands/ticket.js | 20 +++++++++++++++++++- Data/TicketData.json | 5 ++++- Data/ticket-panel-id.json | 4 +--- Structures/TicketID.js | 36 ++++++++++++++---------------------- 4 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Commands/ticket.js b/Commands/ticket.js index 4c62663..b19134d 100644 --- a/Commands/ticket.js +++ b/Commands/ticket.js @@ -51,7 +51,11 @@ module.exports = new Command({ } // Ticket ID - let ticketNumberID = TicketNumberID.pad(interaction.guild.id); + let ticketNumberID = await TicketNumberID.pad(); + + let TicketData = await JSON.parse( + fs.readFileSync("./Data/TicketData.json", "utf8") + ); // Ticket Subject const TicketSubject = @@ -105,6 +109,20 @@ module.exports = new Command({ type: "GUILD_TEXT", } ); + await TicketData.tickets.push({ + id: ticketChannel.id, + name: ticketChannel.name, + user: Author.id, + number: ticketNumberID, + reason: TicketSubject, + }); + fs.writeFileSync( + "./Data/TicketData.json", + JSON.stringify(TicketData, null, 4), + (err) => { + if (err) console.error(err); + } + ); if ( interaction.channel.name === supportbot.ReactionChannel || diff --git a/Data/TicketData.json b/Data/TicketData.json index 0967ef4..6201053 100644 --- a/Data/TicketData.json +++ b/Data/TicketData.json @@ -1 +1,4 @@ -{} +{ + "id": 10, + "tickets": [] +} diff --git a/Data/ticket-panel-id.json b/Data/ticket-panel-id.json index b2367c6..ad5728f 100644 --- a/Data/ticket-panel-id.json +++ b/Data/ticket-panel-id.json @@ -1,3 +1 @@ -{ - "TicketPanelID": "" -} +{"TicketPanelID":""} \ No newline at end of file diff --git a/Structures/TicketID.js b/Structures/TicketID.js index 11c9d9f..6725b8c 100644 --- a/Structures/TicketID.js +++ b/Structures/TicketID.js @@ -14,74 +14,66 @@ const supportbot = yaml.load( ); class TicketNumberID { - static pad(guildId) { - let n = this.get(guildId) + ""; + static async pad() { + let n = this.get() + ""; let z = "0"; let width = 4; - setTimeout(() => { - this.set(guildId, this.get(guildId) + 1); - }, 50); + await this.set(this.get() + 1); return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; } - static get(guildId) { + static get() { let ticketnumberID = JSON.parse( fs.readFileSync("./Data/TicketData.json", "utf8") ); - if (!ticketnumberID[guildId]) { - ticketnumberID[guildId] = { - id: 0, - }; + if (!ticketnumberID.id) { + ticketnumberID.id = 0; fs.writeFileSync( "./Data/TicketData.json", JSON.stringify(ticketnumberID, null, 4), (err) => { - if (err) console.log(err); + if (err) console.error(err); } ); return 0; } else { - return ticketnumberID[guildId].id; + return ticketnumberID.id; } } - static set(guildId, value) { + static set(value) { let ticketnumberID = JSON.parse( fs.readFileSync("./Data/TicketData.json", "utf8") ); - ticketnumberID[guildId] = { - id: value, - }; + ticketnumberID.id = value; fs.writeFileSync( "./Data/TicketData.json", JSON.stringify(ticketnumberID, null, 4), (err) => { - if (err) console.log(err); + if (err) console.error(err); } ); return value; } - static reset(guildId) { + static reset() { let ticketnumberID = JSON.parse( fs.readFileSync("./Data/TicketData.json", "utf8") ); - ticketnumberID[guildId] = { - id: 0, - }; + ticketnumberID.id = 0; fs.writeFileSync( "./Data/TicketData.json", JSON.stringify(ticketnumberID, null, 4), (err) => { - if (err) console.log(err); + if (err) console.error(err); } );