-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinit.js
149 lines (133 loc) · 3.34 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const { Client, GatewayIntentBits } = require("discord.js");
const fs = require("fs");
const path = require("path");
const yaml = require("yaml");
const configFile = fs.readFileSync("./config.yml", "utf8");
const config = yaml.parse(configFile);
const { QuickDB } = require("quick.db");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
// Check if the data directory exists, and if not, create it
const dataDir = path.join(__dirname, "data");
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}
const mainDB = new QuickDB({ filePath: "data/main.sqlite" });
const ticketsDB = new QuickDB({ filePath: "data/tickets.sqlite" });
const blacklistDB = new QuickDB({ filePath: "data/blacklist.sqlite" });
(async function () {
// Initialize totalTickets to 1 if it doesn't exist
if (!(await mainDB.has("totalTickets"))) {
await mainDB.set("totalTickets", 1);
}
// Initialize openTickets to an empty array if it doesn't exist
if (!(await mainDB.has("openTickets"))) {
await mainDB.set("openTickets", 0);
}
// Initialize totalClaims to 0 if it doesn't exist
if (!(await mainDB.has("totalClaims"))) {
await mainDB.set("totalClaims", 0);
}
// Initialize totalReviews to 0 if it doesn't exist
if (!(await mainDB.has("totalReviews"))) {
await mainDB.set("totalReviews", 0);
}
// Initialize ratings to an empty array if it doesn't exist
if (!(await mainDB.has("ratings"))) {
await mainDB.set("ratings", []);
}
// Initialize totalMessages to 0 if it doesn't exist
if (!(await mainDB.has("totalMessages"))) {
await mainDB.set("totalMessages", 0);
}
// Initialize ticketCreators to an empty array if it doesn't exist
if (!(await mainDB.has("ticketCreators"))) {
await mainDB.set("ticketCreators", []);
}
})();
// Extract information from the config.yml to properly setup the ticket categories
const ticketCategories = [];
config.TicketCategories.forEach((category) => {
const {
id,
name,
nameEmoji,
categoryID,
closedCategoryID,
support_role_ids,
permissions,
pingRoles,
ping_role_ids,
ghostPingRoles,
textContent,
creatorRoles,
buttonEmoji,
buttonLabel,
buttonStyle,
menuEmoji,
menuLabel,
menuDescription,
embedTitle,
color,
description,
ticketName,
ticketTopic,
slowmode,
useCodeBlocks,
modalTitle,
questions,
} = category;
const extractedQuestions = questions.map((question) => {
const { label, placeholder, style, required, minLength, maxLength } =
question;
return {
label,
placeholder,
style,
required,
minLength,
maxLength,
};
});
ticketCategories[id] = {
name,
nameEmoji,
categoryID,
closedCategoryID,
support_role_ids,
permissions,
pingRoles,
ping_role_ids,
ghostPingRoles,
textContent,
creatorRoles,
buttonEmoji,
buttonLabel,
buttonStyle,
menuEmoji,
menuLabel,
menuDescription,
embedTitle,
color,
description,
ticketName,
ticketTopic,
slowmode,
useCodeBlocks,
modalTitle,
questions: extractedQuestions,
};
});
module.exports = {
client,
ticketCategories,
mainDB,
ticketsDB,
blacklistDB,
};