-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.ts
654 lines (608 loc) · 23.7 KB
/
index.ts
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
import { Interaction, Client, Guild, GatewayIntentBits } from "discord.js";
import { insertCommands } from "./deploy-commands";
import { open, getCollections, getMongoClientObj } from "./mongoDB";
import sphelp from "./Commands/sphelp";
import spsetamount from "./Commands/spsetamount";
import spstatus from "./Commands/spstatus";
import spsettarget from "./Commands/spsettarget";
import spremovetarget from "./Commands/spremovetarget";
import spsetpassword from "./Commands/spsetpassword";
import spsetlogichannel from "./Commands/spsetlogichannel";
import spremovelogichannel from "./Commands/spremovelogichannel";
import NodeCache from "node-cache";
import spremovestockpile from "./Commands/spremovestockpile";
import spaddstockpile from "./Commands/spaddstockpile";
import spnotif from "./Commands/sptimeoutnotif";
import sprole from "./Commands/sprole";
import stockpilerUpdateStockpile from "./Utils/stockpilerUpdateStockpile";
import spitems from "./Commands/spitems";
import spsetorder from "./Commands/spsetorder";
import buttonHandler from "./Utils/buttonHandler";
import checkTimeNotifs from "./Utils/checkTimeNotifs";
import http from "http";
import crypto from "crypto";
import argon2 from "argon2";
import spsettimeleft from "./Commands/spsettimeleft";
import fs from "fs";
import csv from "csv-parser";
import spaddprettyname from "./Commands/spaddprettyname";
import spremoveprettyname from "./Commands/spremoveprettyname";
import sppurgestockpile from "./Commands/sppurgestockpile";
import spaddcode from "./Commands/spaddcode";
import spremovecode from "./Commands/spremovecode";
import spaddloc from "./Commands/spaddloc";
import spremoveloc from "./Commands/spremoveloc";
import splistloc from "./Commands/splistloc";
import spfind from "./Commands/spfind";
import spdisabletime from "./Commands/spdisabletime";
import spgroup from "./Commands/spgroup";
import sprefresh from "./Commands/sprefresh";
import spuser from "./Commands/spuser";
import autoCompleteHandler from "./Utils/autoCompleteHandler";
import { UPDATE_DATE, VERSION } from "./constants";
require("dotenv").config();
const host = process.env.APP_HOST ? process.env.APP_HOST : "0.0.0.0";
const currentVersion = 22;
const commandMapping: any = {
sphelp: { sub: false, vars: 1, handler: sphelp },
spcode: {
sub: true,
handler: {
add: { func: spaddcode, vars: 2 },
remove: { func: spremovecode, vars: 2 },
},
},
sploc: {
sub: true,
handler: {
add: { func: spaddloc, vars: 2 },
remove: { func: spremoveloc, vars: 2 },
list: { func: splistloc, vars: 1 },
},
},
spprettyname: {
sub: true,
handler: {
add: { func: spaddprettyname, vars: 2 },
remove: { func: spremoveprettyname, vars: 2 },
},
},
sptarget: {
sub: true,
handler: {
set: { func: spsettarget, vars: 2 },
remove: { func: spremovetarget, vars: 2 },
},
},
splogichannel: {
sub: true,
handler: {
set: { func: spsetlogichannel, vars: 2 },
remove: { func: spremovelogichannel, vars: 2 },
},
},
sprole: { sub: false, vars: 1, handler: sprole },
spnotif: { sub: false, vars: 1, handler: spnotif },
spstockpile: {
sub: true,
handler: {
add: { func: spaddstockpile, vars: 2 },
remove: { func: spremovestockpile, vars: 2 },
purge: { func: sppurgestockpile, vars: 2 },
},
},
spdisabletime: { sub: false, vars: 2, handler: spdisabletime },
spfind: { sub: false, vars: 1, handler: spfind },
spitems: { sub: false, vars: 1, handler: spitems },
sprefresh: { sub: false, vars: 1, handler: sprefresh },
spsetamount: { sub: false, vars: 2, handler: spsetamount },
spstatus: { sub: false, vars: 1, handler: spstatus },
spsetpassword: { sub: false, vars: 1, handler: spsetpassword },
spsetorder: { sub: false, vars: 2, handler: spsetorder },
spsettimeleft: { sub: false, vars: 2, handler: spsettimeleft },
spgroup: { sub: false, vars: 2, handler: spgroup },
spuser: { sub: false, vars: 1, handler: spuser },
};
const timerBP = [60 * 5, 60 * 10, 60 * 30, 60 * 60, 60 * 60 * 6, 60 * 60 * 12]; // Timer breakpoints in seconds
declare global {
var NodeCacheObj: NodeCache;
}
const updateFirstTimeSetup = async (newInstance: boolean): Promise<void> => {
// Run first-time setup
const collections = getCollections();
insertCommands();
if (newInstance) {
const password = crypto.randomBytes(32).toString("hex");
console.info(
"Generated a random password since none was previously set: " +
password +
". You can change this using /spsetpassword via the bot",
);
await collections.config.insertOne({
version: currentVersion,
password: await argon2.hash(password),
});
console.log("Completed first-time setup");
} else {
await collections.config.updateOne(
{},
{ $set: { version: currentVersion } },
);
console.info("Completed Storeman Bot update");
}
};
const guildCreateEventHandler = async (guild: Guild) => {
const collections = getCollections(guild.id);
const configObj = await collections.config.findOne({});
if (!configObj) {
// The bot has joined a new server
console.log(
"Bot has joined a new server named: " +
guild.name +
" with ID: " +
guild.id,
);
const password = crypto.randomBytes(32).toString("hex");
await collections.config.insertOne({
password: await argon2.hash(password),
});
// Insert commands into that guild
insertCommands(guild.id);
// Add the server record into the global settings list
const globalCollection = getCollections("global-settings");
await globalCollection.config.updateOne(
{},
{ $push: { serverIDList: guild.id } },
);
const stockpileTimes: any = NodeCacheObj.get("stockpileTimes");
const disableTimeNotif: any = NodeCacheObj.get("disableTimeNotif");
const notifRoles: any = NodeCacheObj.get("notifRoles");
const prettyName: any = NodeCacheObj.get("prettyName");
const stockpileGroups: any = NodeCacheObj.get("stockpileGroups");
stockpileTimes[guild.id] = {};
notifRoles[guild.id] = [];
prettyName[guild.id] = {};
disableTimeNotif[guild.id] = false;
stockpileGroups[guild.id] = {};
}
};
const guildDeleteEventHandler = async (guildID: string) => {
console.log(
"Bot has been kicked (or deleted) from the server with ID:" + guildID,
);
const mongoClient = getMongoClientObj();
const db = mongoClient.db("stockpiler-" + guildID);
await db.dropDatabase();
const collections = getCollections("global-settings");
const configObj = await collections.config.findOne({});
let found = false;
for (let i = 0; i < configObj.serverIDList.length; i++) {
if (configObj.serverIDList[i] === guildID) {
found = true;
configObj.serverIDList.splice(i, 1);
break;
}
}
if (found) {
await collections.config.updateOne(
{},
{ $set: { serverIDList: configObj.serverIDList } },
);
const stockpileTimes: any = NodeCacheObj.get("stockpileTimes");
const notifRoles: any = NodeCacheObj.get("notifRoles");
const prettyName: any = NodeCacheObj.get("prettyName");
const disableTimeNotif: any = NodeCacheObj.get("disableTimeNotif");
const stockpileGroups: any = NodeCacheObj.get("stockpileGroups");
delete stockpileTimes[guildID];
delete notifRoles[guildID];
delete prettyName[guildID];
delete disableTimeNotif[guildID];
delete stockpileGroups[guildID];
console.log(
"Deleted the database and config records of the guild successfully",
);
} else
console.log(
"Delete request received but no such guildID exists in Storeman Bot records.",
);
};
const createCacheStartup = async (client: Client) => {
if (process.env.STOCKPILER_MULTI_SERVER === "true") {
console.log("Storeman bot is running in multi-server mode.");
const collections = getCollections("global-settings");
const configObj = await collections.config.findOne();
// Obtain list of guild IDs from Discord API to check if it matches with the one stored in the DB
const guildObjs = client.guilds.cache.toJSON();
let listOfGuildObjs: Guild[] = [];
let listOfGuildIDs: string[] = [];
for (let i = 0; i < guildObjs.length; i++) {
listOfGuildObjs.push(guildObjs[i]);
listOfGuildIDs.push(guildObjs[i].id);
}
if (configObj) {
// Check if the guildID list has changed since the bot was down
for (let i = 0; i < listOfGuildObjs.length; i++) {
const currentID = listOfGuildIDs;
if (configObj.serverIDList.indexOf(currentID) === -1) {
// guildID from discord API not found inside our storage, execute createFunction
guildCreateEventHandler(listOfGuildObjs[i]);
}
}
for (let i = 0; i < configObj.serverIDList.length; i++) {
const currentID = configObj.serverIDList[i];
if (listOfGuildIDs.indexOf(currentID) === -1) {
// guildID from our database no longer exists in discord API, execute destroyFunction
guildDeleteEventHandler(currentID);
}
}
if (configObj.version < currentVersion) {
// Update all the commands since the version has changed
for (let i = 0; i < configObj.serverIDList.length; i++) {
insertCommands(configObj.serverIDList[i]);
await collections.config.updateOne(
{},
{ $set: { version: currentVersion } },
);
}
}
let notifRoles: any = {};
let prettyName: any = {};
let stockpileTimes: any = {};
let disableTimeNotif: any = {};
let stockpileGroups: any = {};
for (let i = 0; i < configObj.serverIDList.length; i++) {
// Create custom notifRoles and prettyNames cache object
const serverCollections = getCollections(configObj.serverIDList[i]);
const serverConfigObj = await serverCollections.config.findOne({});
if ("notifRoles" in serverConfigObj)
notifRoles[configObj.serverIDList[i]] = serverConfigObj.notifRoles;
else notifRoles[configObj.serverIDList[i]] = [];
if ("prettyName" in serverConfigObj)
prettyName[configObj.serverIDList[i]] = serverConfigObj.prettyName;
else prettyName[configObj.serverIDList[i]] = {};
// Create the disable time cache object
if ("disableTimeNotif" in serverConfigObj)
disableTimeNotif[configObj.serverIDList[i]] =
serverConfigObj.disableTimeNotif;
else disableTimeNotif[configObj.serverIDList[i]] = false;
if ("stockpileGroups" in serverConfigObj)
stockpileGroups[configObj.serverIDList[i]] =
serverConfigObj.stockpileGroups;
else stockpileGroups[configObj.serverIDList[i]] = {};
const stockpiles = await serverCollections.stockpiles
.find({})
.toArray();
stockpileTimes[configObj.serverIDList[i]] = {};
for (let y = 0; y < stockpiles.length; y++) {
if ("timeLeft" in stockpiles[y]) {
let timeNotificationLeft = timerBP.length - 1;
for (let x = 0; x < timerBP.length; x++) {
const timeLeftProperty: any = stockpiles[y].timeLeft;
const currentDate: any = new Date();
if ((timeLeftProperty - currentDate) / 1000 <= timerBP[x]) {
timeNotificationLeft = x;
break;
}
}
if (timeNotificationLeft >= 1) timeNotificationLeft -= 1;
stockpileTimes[configObj.serverIDList[i]][stockpiles[y].name] = {
timeLeft: stockpiles[y].timeLeft,
timeNotificationLeft: timeNotificationLeft,
};
}
}
}
NodeCacheObj.set("notifRoles", notifRoles);
NodeCacheObj.set("prettyName", prettyName);
NodeCacheObj.set("stockpileTimes", stockpileTimes);
NodeCacheObj.set("disableTimeNotif", disableTimeNotif);
NodeCacheObj.set("stockpileGroups", stockpileGroups);
} else {
for (let i = 0; i < listOfGuildObjs.length; i++) {
guildCreateEventHandler(listOfGuildObjs[i]);
}
await collections.config.insertOne({
version: currentVersion,
serverIDList: listOfGuildIDs,
});
}
client.on("guildCreate", (guild) => {
guildCreateEventHandler(guild);
});
client.on("guildDelete", (guild) => {
guildDeleteEventHandler(guild.id);
});
} else {
// Create list of timeLefts till the stockpile expires
const collections = getCollections();
const stockpiles = await collections.stockpiles.find({}).toArray();
let stockpileTime: any = {};
for (let i = 0; i < stockpiles.length; i++) {
if ("timeLeft" in stockpiles[i]) {
let timeNotificationLeft = timerBP.length - 1;
for (let x = 0; x < timerBP.length; x++) {
const timeLeftProperty: any = stockpiles[i].timeLeft;
const currentDate: any = new Date();
if ((timeLeftProperty - currentDate) / 1000 <= timerBP[x]) {
timeNotificationLeft = x;
break;
}
}
if (timeNotificationLeft >= 1) timeNotificationLeft -= 1;
stockpileTime[stockpiles[i].name] = {
timeLeft: stockpiles[i].timeLeft,
timeNotificationLeft: timeNotificationLeft,
};
}
}
NodeCacheObj.set("stockpileTimes", stockpileTime);
// Check whether to insert commands and do first-time setup
if (process.env.NODE_ENV === "development") insertCommands();
const configOptions = await collections.config.findOne({}, {});
if (configOptions) {
let notifRoles = [];
if ("notifRoles" in configOptions) notifRoles = configOptions.notifRoles;
NodeCacheObj.set("notifRoles", notifRoles);
let prettyName: any = {};
let disableTimeNotif: any = false;
if ("prettyName" in configOptions) prettyName = configOptions.prettyName;
NodeCacheObj.set("prettyName", prettyName);
if ("disableTimeNotif" in configOptions)
disableTimeNotif = configOptions.disableTimeNotif;
NodeCacheObj.set("disableTimeNotif", disableTimeNotif);
let stockpileGroups: any = {};
if ("stockpileGroups" in configOptions)
stockpileGroups = configOptions.stockpileGroups;
NodeCacheObj.set("stockpileGroups", stockpileGroups);
if (configOptions.version) {
if (configOptions.version < currentVersion) updateFirstTimeSetup(false);
} else updateFirstTimeSetup(true);
} else updateFirstTimeSetup(true);
}
};
const main = async (): Promise<void> => {
let commandCallQueue: Array<Interaction> = [];
let multiServerCommandQueue: any = {};
const handleCommand = async (interaction: Interaction) => {
try {
if (interaction.isChatInputCommand()) {
const commandName = interaction.commandName;
const commandMapResult = commandMapping[commandName];
if (!commandMapResult) {
await interaction.editReply({
content:
"This command has been removed. Discord might not have invalidated this old command ;c",
});
return false;
}
if (commandMapResult.sub) {
const subMapResult =
commandMapResult.handler[interaction.options.getSubcommand()];
if (subMapResult.vars === 2)
await subMapResult.func(interaction, client);
else await subMapResult.func(interaction);
} else {
if (commandMapResult.vars === 2)
await commandMapResult.handler(interaction, client);
else await commandMapResult.handler(interaction);
}
} else if (interaction.isButton()) {
await buttonHandler(interaction);
} else if (interaction.isAutocomplete()) {
await autoCompleteHandler(interaction);
}
} catch (e) {
if (interaction.isChatInputCommand() || interaction.isButton()) {
let errorDump = JSON.stringify(e, Object.getOwnPropertyNames(e));
if (interaction.isChatInputCommand()) {
console.log(
"[!!!]: An error has occured in the command " +
interaction.commandName +
". Please kindly report this to the developer on Discord (Tkai#8276)",
);
interaction.followUp({
content:
"[❗❗❗] An error has occurred in Storeman Bot for the command `" +
interaction.commandName +
"`. Please kindly send the logs below this message to the developer on Discord at Tkai#8276",
ephemeral: true,
});
} else if (interaction.isButton()) {
console.log(
"[!!!]: An error has occured in a button action. Please kindly report this to the developer on Discord (Tkai#8276)",
);
interaction.followUp({
content:
"[❗❗❗] An error has occurred in Storeman Bot button action. Please kindly send logs below this message to the developer on Discord at Tkai#8276.",
ephemeral: true,
});
}
while (errorDump.length > 0) {
if (errorDump.length > 2000) {
const sliced = errorDump.slice(0, 2000);
const lastEnd = sliced.lastIndexOf("\n");
const finalMsg = sliced.slice(0, lastEnd);
await interaction.followUp({
content: finalMsg,
ephemeral: true,
});
errorDump = errorDump.slice(lastEnd, errorDump.length);
} else {
await interaction.followUp({
content: errorDump,
ephemeral: true,
});
errorDump = "";
}
}
}
}
if (process.env.STOCKPILER_MULTI_SERVER === "true") {
multiServerCommandQueue[interaction.guildId!].splice(0, 1);
if (multiServerCommandQueue[interaction.guildId!].length > 0) {
handleCommand(multiServerCommandQueue[interaction.guildId!][0]);
}
console.log(
"[Command Queue:] Finished 1 command for " +
interaction.guildId +
". Remaining length of queue: " +
multiServerCommandQueue[interaction.guildId!].length,
);
} else {
commandCallQueue.splice(0, 1);
if (commandCallQueue.length > 0) {
handleCommand(commandCallQueue[0]);
}
console.log(
"[Command Queue:] Finished 1 command. Remaining length of queue: " +
commandCallQueue.length,
);
}
};
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
global.NodeCacheObj = new NodeCache({ checkperiod: 0, useClones: false });
const csvData: Array<any> = await new Promise(function (resolve, reject) {
let fetchData: any = [];
fs.createReadStream("ItemNumbering.csv")
.pipe(csv())
.on("data", (row) => {
fetchData.push(row);
})
.on("end", () => {
console.log("Item List CSV file successfully processed");
resolve(fetchData);
})
.on("error", reject);
});
let itemList: String[] = [];
let listWithCrates: String[] = [];
let itemListBoth: String[] = [];
let lowerToOriginal: any = {};
let itemListCategoryMapping: any = {};
for (let i = 0; i < csvData.length; i++) {
const loweredName = csvData[i].Name.slice()
.replace(/\./g, "_")
.toLowerCase();
itemList.push(loweredName);
listWithCrates.push(loweredName + " crate");
itemListBoth.push(loweredName);
itemListBoth.push(loweredName + " crate");
lowerToOriginal[loweredName] = csvData[i].Name;
lowerToOriginal[loweredName + " crate"] = csvData[i].Name + " crate";
if (csvData[i].StockpileCategory === "Vehicle") {
itemListCategoryMapping[loweredName] = csvData[i].StockpileCategory;
itemListCategoryMapping[loweredName + " crate"] =
csvData[i].StockpileCategory + " Crate";
} else {
itemListCategoryMapping[loweredName] = csvData[i].StockpileCategory;
itemListCategoryMapping[loweredName + " crate"] =
csvData[i].StockpileCategory;
}
}
const LocationCSV: Array<any> = await new Promise(function (resolve, reject) {
let fetchData: any = [];
fs.createReadStream("Locs.csv")
.pipe(csv())
.on("data", (row) => {
fetchData.push(row);
})
.on("end", () => {
console.log("Location CSV file successfully processed");
resolve(fetchData);
})
.on("error", reject);
});
let locationMappings: any = {};
for (let i = 0; i < LocationCSV.length; i++) {
locationMappings[LocationCSV[i].Code.toLowerCase()] =
LocationCSV[i].Translation;
}
NodeCacheObj.set("itemList", itemList);
NodeCacheObj.set("itemListBoth", itemListBoth);
NodeCacheObj.set("listWithCrates", listWithCrates);
NodeCacheObj.set("lowerToOriginal", lowerToOriginal);
NodeCacheObj.set("itemListCategoryMapping", itemListCategoryMapping);
NodeCacheObj.set("locationMappings", locationMappings);
NodeCacheObj.set("timerBP", timerBP);
// Connect to mongoDB
if (await open()) {
setInterval(checkTimeNotifs, 1000 * 60, client, false, true);
// Start HTTP server
const server = http.createServer((request, response) => {
if (request.method === "POST") {
let body = "";
request.on("data", (data) => {
body += data;
});
request.on("end", async () => {
try {
await stockpilerUpdateStockpile(client, JSON.parse(body), response);
} catch (e) {
response.writeHead(403, { "Content-Type": "application/json" });
response.end(
JSON.stringify({ success: false, error: "invalid-json" }),
);
}
});
} else if (request.method === "GET") {
response.writeHead(200, { "Content-Type": "text/html" });
response.write(`
<html>
<h1>Storeman Bot - ${VERSION} (${UPDATE_DATE})</h1>
<p>If you are seeing this page, it means you have reached the Storeman Bot sanity check web page. Please use the <a href="https://github.com/tehruttiger/Stockpiler">Stockpiler</a> app to communicate with our servers instead!</p>
</html>
`);
response.end();
}
});
server.listen(parseInt(process.env.APP_PORT!), host);
console.log(
`HTTP server now listening at http://${host}:${process.env.APP_PORT}`,
);
// This is called once client(the bot) is ready
client.once("ready", async () => {
await createCacheStartup(client);
console.log("Storeman Bot is ready!");
client.user?.setActivity("/sphelp");
});
client.on("interactionCreate", async (interaction) => {
if (interaction.isChatInputCommand()) {
await interaction.reply({
content: "Working on it...",
ephemeral: true,
});
} else if (interaction.isButton()) {
await interaction.update({
content: "Working on it...",
components: [],
});
}
if (process.env.STOCKPILER_MULTI_SERVER === "true") {
if (!(interaction.guildId! in multiServerCommandQueue)) {
multiServerCommandQueue[interaction.guildId!] = [interaction];
} else {
multiServerCommandQueue[interaction.guildId!].push(interaction);
}
if (multiServerCommandQueue[interaction.guildId!].length === 1) {
console.log(
`[Command Queue:] No queue ahead for ${interaction.guildId}, starting.`,
);
handleCommand(multiServerCommandQueue[interaction.guildId!][0]);
}
} else {
commandCallQueue.push(interaction);
if (commandCallQueue.length === 1) {
console.log("[Command Queue:] No queue ahead, starting.");
handleCommand(commandCallQueue[0]);
// kick start the queue
}
}
});
// Connect by logging into Discord
client.login(process.env.STOCKPILER_TOKEN);
} else {
console.error("Failed to connect to MongoDB. Exiting now");
}
};
main();