2021-10-04 20:41:05 +01:00
|
|
|
// SupportBot | Emerald Services
|
|
|
|
|
// Ticket ID Structure
|
|
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
|
|
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const Command = require("./Command.js");
|
|
|
|
|
const Client = require("./Client.js");
|
|
|
|
|
const Event = require("./Event.js");
|
|
|
|
|
|
2021-10-24 22:41:46 +01:00
|
|
|
const yaml = require("js-yaml");
|
2021-10-27 19:30:10 -05:00
|
|
|
const supportbot = yaml.load(
|
|
|
|
|
fs.readFileSync("./Configs/supportbot.yml", "utf8")
|
|
|
|
|
);
|
2021-10-04 20:41:05 +01:00
|
|
|
|
|
|
|
|
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;
|