Files
SupportBot/Structures/TicketID.js
T

74 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2021-10-04 20:41:05 +01:00
// SupportBot | Emerald Services
// Ticket ID Structure
const fs = require("fs");
class TicketNumberID {
2021-11-23 15:48:45 -06:00
static async pad() {
let n = this.get() + "";
2021-10-24 22:41:46 +01:00
let z = "0";
let width = 4;
2021-11-23 15:48:45 -06:00
await this.set(this.get() + 1);
2021-10-24 22:41:46 +01:00
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
2021-11-23 15:48:45 -06:00
static get() {
2021-10-24 22:41:46 +01:00
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
2021-11-23 15:48:45 -06:00
if (!ticketnumberID.id) {
ticketnumberID.id = 0;
2021-10-24 22:41:46 +01:00
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4),
(err) => {
2021-11-23 15:48:45 -06:00
if (err) console.error(err);
2021-10-04 20:41:05 +01:00
}
2021-10-24 22:41:46 +01:00
);
2021-10-04 20:41:05 +01:00
2021-10-24 22:41:46 +01:00
return 0;
2021-10-04 20:41:05 +01:00
} else {
2021-11-23 15:48:45 -06:00
return ticketnumberID.id;
2021-10-04 20:41:05 +01:00
}
2021-10-24 22:41:46 +01:00
}
2021-11-23 15:48:45 -06:00
static set(value) {
2021-10-24 22:41:46 +01:00
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
2021-11-23 15:48:45 -06:00
ticketnumberID.id = value;
2021-10-04 20:41:05 +01:00
2021-10-24 22:41:46 +01:00
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4),
(err) => {
2021-11-23 15:48:45 -06:00
if (err) console.error(err);
2021-10-24 22:41:46 +01:00
}
);
2021-10-04 20:41:05 +01:00
return value;
2021-10-24 22:41:46 +01:00
}
2021-11-23 15:48:45 -06:00
static reset() {
2021-10-24 22:41:46 +01:00
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
2021-11-23 15:48:45 -06:00
ticketnumberID.id = 0;
2021-10-04 20:41:05 +01:00
2021-10-24 22:41:46 +01:00
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4),
(err) => {
2021-11-23 15:48:45 -06:00
if (err) console.error(err);
2021-10-24 22:41:46 +01:00
}
);
2021-10-04 20:41:05 +01:00
return 0;
2021-10-24 22:41:46 +01:00
}
2021-10-04 20:41:05 +01:00
}
2021-10-24 22:41:46 +01:00
module.exports = TicketNumberID;