Changed TicketData Structure

This commit is contained in:
Noah committed 2021-11-23 15:48:45 -06:00
1 parent e740c17837
commit b6a0016f5f
4 files changed
+38 -27

No files matched your search

+19 -1
View File
@@ -51,7 +51,11 @@ module.exports = new Command({
} }
// Ticket ID // 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 // Ticket Subject
const TicketSubject = const TicketSubject =
@@ -105,6 +109,20 @@ module.exports = new Command({
type: "GUILD_TEXT", 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 ( if (
interaction.channel.name === supportbot.ReactionChannel || interaction.channel.name === supportbot.ReactionChannel ||
+4 -1
View File
@@ -1 +1,4 @@
{} {
"id": 10,
"tickets": []
}
+1 -3
View File
@@ -1,3 +1 @@
{ {"TicketPanelID":""}
"TicketPanelID": ""
}
+14 -22
View File
@@ -14,74 +14,66 @@ const supportbot = yaml.load(
); );
class TicketNumberID { class TicketNumberID {
static pad(guildId) { static async pad() {
let n = this.get(guildId) + ""; let n = this.get() + "";
let z = "0"; let z = "0";
let width = 4; let width = 4;
setTimeout(() => { await this.set(this.get() + 1);
this.set(guildId, this.get(guildId) + 1);
}, 50);
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
} }
static get(guildId) { static get() {
let ticketnumberID = JSON.parse( let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8") fs.readFileSync("./Data/TicketData.json", "utf8")
); );
if (!ticketnumberID[guildId]) { if (!ticketnumberID.id) {
ticketnumberID[guildId] = { ticketnumberID.id = 0;
id: 0,
};
fs.writeFileSync( fs.writeFileSync(
"./Data/TicketData.json", "./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4), JSON.stringify(ticketnumberID, null, 4),
(err) => { (err) => {
if (err) console.log(err); if (err) console.error(err);
} }
); );
return 0; return 0;
} else { } else {
return ticketnumberID[guildId].id; return ticketnumberID.id;
} }
} }
static set(guildId, value) { static set(value) {
let ticketnumberID = JSON.parse( let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8") fs.readFileSync("./Data/TicketData.json", "utf8")
); );
ticketnumberID[guildId] = { ticketnumberID.id = value;
id: value,
};
fs.writeFileSync( fs.writeFileSync(
"./Data/TicketData.json", "./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4), JSON.stringify(ticketnumberID, null, 4),
(err) => { (err) => {
if (err) console.log(err); if (err) console.error(err);
} }
); );
return value; return value;
} }
static reset(guildId) { static reset() {
let ticketnumberID = JSON.parse( let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8") fs.readFileSync("./Data/TicketData.json", "utf8")
); );
ticketnumberID[guildId] = { ticketnumberID.id = 0;
id: 0,
};
fs.writeFileSync( fs.writeFileSync(
"./Data/TicketData.json", "./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4), JSON.stringify(ticketnumberID, null, 4),
(err) => { (err) => {
if (err) console.log(err); if (err) console.error(err);
} }
); );