Files
SupportBot/Structures/TicketID.js
T

92 lines
1.9 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");
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-29 19:12:11 +01:00
const supportbot = yaml.load(
fs.readFileSync("./Configs/supportbot.yml", "utf8")
);
2021-10-04 20:41:05 +01:00
class TicketNumberID {
2021-10-24 22:41:46 +01:00
static pad(guildId) {
let n = this.get(guildId) + "";
let z = "0";
let width = 4;
setTimeout(() => {
this.set(guildId, this.get(guildId) + 1);
}, 50);
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
static get(guildId) {
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
if (!ticketnumberID[guildId]) {
2021-10-24 22:41:46 +01:00
ticketnumberID[guildId] = {
id: 0,
};
fs.writeFileSync(
"./Data/TicketData.json",
JSON.stringify(ticketnumberID, null, 4),
(err) => {
if (err) console.log(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-10-24 22:41:46 +01:00
return ticketnumberID[guildId].id;
2021-10-04 20:41:05 +01:00
}
2021-10-24 22:41:46 +01:00
}
static set(guildId, value) {
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
ticketnumberID[guildId] = {
2021-10-24 22:41:46 +01:00
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-10-04 20:41:05 +01:00
if (err) console.log(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
}
static reset(guildId) {
let ticketnumberID = JSON.parse(
fs.readFileSync("./Data/TicketData.json", "utf8")
);
2021-10-04 20:41:05 +01:00
ticketnumberID[guildId] = {
2021-10-24 22:41:46 +01:00
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-10-04 20:41:05 +01:00
if (err) console.log(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;