Files
SupportBot/utils/TicketNumber.js
T

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-06-15 23:58:37 +01:00
// SupportBot Utils
2020-01-29 18:58:58 +00:00
// Ticket Numbers
const discord = require("discord.js")
2020-01-29 18:57:22 +00:00
const fs = require("fs");
2020-01-29 18:58:58 +00:00
const yaml = require('js-yaml');
const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8'));
2020-01-29 19:59:44 +00:00
class TicketNumberID {
2020-01-29 18:55:32 +00: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) {
2020-06-15 23:58:37 +01:00
let ticketnumberID = JSON.parse(fs.readFileSync("./storage/TicketID.json", "utf8"));
2020-01-29 18:55:32 +00:00
2020-01-29 20:05:34 +00:00
if (!ticketnumberID[guildId]) {
ticketnumberID[guildId] = {
2020-01-29 18:55:32 +00:00
id: 0
}
2020-06-15 23:58:37 +01:00
fs.writeFileSync("./storage/TicketID.json", JSON.stringify(ticketnumberID, null, 4), err => {
2020-01-29 18:55:32 +00:00
if (err) console.log(err);
});
return 0;
} else {
2020-01-29 20:05:34 +00:00
return ticketnumberID[guildId].id;
2020-01-29 18:55:32 +00:00
}
}
static set(guildId, value) {
2020-06-15 23:58:37 +01:00
let ticketnumberID = JSON.parse(fs.readFileSync("./storage/TicketID.json", "utf8"));
2020-01-29 18:55:32 +00:00
2020-01-29 20:05:34 +00:00
ticketnumberID[guildId] = {
2020-01-29 18:55:32 +00:00
id: value
}
2020-06-15 23:58:37 +01:00
fs.writeFileSync("./storage/TicketID.json", JSON.stringify(ticketnumberID, null, 4), err => {
2020-01-29 18:55:32 +00:00
if (err) console.log(err);
});
return value;
}
static reset(guildId) {
2020-06-15 23:58:37 +01:00
let ticketnumberID = JSON.parse(fs.readFileSync("./storage/TicketID.json", "utf8"));
2020-01-29 18:55:32 +00:00
2020-01-29 20:05:34 +00:00
ticketnumberID[guildId] = {
2020-01-29 18:55:32 +00:00
id: 0
}
2020-06-15 23:58:37 +01:00
fs.writeFileSync("./storage/TicketID.json", JSON.stringify(ticketnumberID, null, 4), err => {
2020-01-29 18:55:32 +00:00
if (err) console.log(err);
});
return 0;
}
}
2020-06-15 23:58:37 +01:00
module.exports = TicketNumberID;