apexify.js 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +1117 -0
  2. package/index.js +111 -0
  3. package/lib/ai/apexAI.js +312 -0
  4. package/lib/ai/functions/chunkString.js +8 -0
  5. package/lib/ai/functions/draw.js +347 -0
  6. package/lib/ai/functions/generateVoiceResponse.js +239 -0
  7. package/lib/ai/functions/processImageAttachments.js +93 -0
  8. package/lib/ai/functions/processMessageContent.js +48 -0
  9. package/lib/ai/functions/readFiles.js +95 -0
  10. package/lib/ai/functions/shouldDrawImage.js +12 -0
  11. package/lib/ai/utils.js +18 -0
  12. package/lib/canvas/ApexPainter.js +1194 -0
  13. package/lib/canvas/themes/level ara.ttf +0 -0
  14. package/lib/canvas/themes/levelFont.ttf +0 -0
  15. package/lib/canvas/themes/levels-card.js +872 -0
  16. package/lib/canvas/themes/music-card.js +342 -0
  17. package/lib/canvas/themes/numbers.ttf +0 -0
  18. package/lib/canvas/themes/tajawal.ttf +0 -0
  19. package/lib/database/MongoDB.js +126 -0
  20. package/lib/database/NanoDB.js +1318 -0
  21. package/lib/database/mongoDb/aggregate.js +120 -0
  22. package/lib/database/mongoDb/countDocs.js +115 -0
  23. package/lib/database/mongoDb/createCollection.js +125 -0
  24. package/lib/database/mongoDb/dataSize.js +89 -0
  25. package/lib/database/mongoDb/distinct.js +110 -0
  26. package/lib/database/mongoDb/drop.js +76 -0
  27. package/lib/database/mongoDb/find.js +122 -0
  28. package/lib/database/mongoDb/geoNear.js +91 -0
  29. package/lib/database/mongoDb/index.js +71 -0
  30. package/lib/database/mongoDb/listCollections.js +81 -0
  31. package/lib/database/mongoDb/migrateAndPrune.js +89 -0
  32. package/lib/database/mongoDb/migrateData.js +79 -0
  33. package/lib/database/mongoDb/remove.js +73 -0
  34. package/lib/database/mongoDb/removeMany.js +73 -0
  35. package/lib/database/mongoDb/removeManyExcept.js +91 -0
  36. package/lib/database/mongoDb/removeSpecific.js +93 -0
  37. package/lib/database/mongoDb/save.js +94 -0
  38. package/lib/database/mongoDb/searchMany.js +109 -0
  39. package/lib/database/mongoDb/textSearch.js +88 -0
  40. package/lib/database/mongoDb/updateAll.js +80 -0
  41. package/lib/database/mongoDb/updateAllExcept.js +108 -0
  42. package/lib/database/mongoDb/updateData.js +106 -0
  43. package/lib/database/nanoDb/fetchData.js +39 -0
  44. package/lib/database/nanoDb/removeField.js +46 -0
  45. package/lib/database/nanoDb/saveData.js +68 -0
  46. package/lib/database/nanoDb/updateFilter.js +24 -0
  47. package/lib/database/ready-schemas.js +245 -0
  48. package/lib/database/utils.js +58 -0
  49. package/lib/discord/discord-build/commands-(prefix)/music/functions/buttons.js +361 -0
  50. package/lib/discord/discord-build/commands-(prefix)/music/functions/end.js +58 -0
  51. package/lib/discord/discord-build/commands-(prefix)/music/functions/start.js +115 -0
  52. package/lib/discord/discord-build/commands-(prefix)/music/play.js +152 -0
  53. package/lib/discord/discord-build/commands-(prefix)/music/previous.js +82 -0
  54. package/lib/discord/discord-build/commands-(prefix)/music/resume.js +93 -0
  55. package/lib/discord/discord-build/commands-(prefix)/music/skip.js +82 -0
  56. package/lib/discord/discord-build/commands-(prefix)/music/stop.js +79 -0
  57. package/lib/discord/discord-build/components/buttons.js +75 -0
  58. package/lib/discord/discord-build/components/menus.js +81 -0
  59. package/lib/discord/discord-build/components/paginator.js +156 -0
  60. package/lib/discord/discord-build/components/permsChecker.js +81 -0
  61. package/lib/discord/discord-build/utils.js +21 -0
  62. package/lib/discord/events/eventer.js +100 -0
  63. package/lib/discord/events/handler/drawMenu.js +351 -0
  64. package/lib/discord/events/handler/tools.js +652 -0
  65. package/lib/discord/events/prefixRegister.js +136 -0
  66. package/lib/discord/events/prefixResponder.js +163 -0
  67. package/lib/discord/events/slashRegister.js +199 -0
  68. package/lib/discord/events/slashResponder.js +108 -0
  69. package/lib/discord/events/starter.js +335 -0
  70. package/lib/discord/functions/perms.js +19 -0
  71. package/lib/discord/utils.js +6 -0
  72. package/lib/general-functions/discord/type-writer.js +77 -0
  73. package/lib/general-functions/utils.js +0 -0
  74. package/lib/utils.js +90 -0
  75. package/package.json +118 -0
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.drawCard = void 0;
40
+ var ApexPainter_1 = require("../ApexPainter");
41
+ var canvas_1 = require("@napi-rs/canvas");
42
+ var paintImage = new ApexPainter_1.ApexPainter();
43
+ function formatDurationString(durationString) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ var parts, hours, minutes, seconds, _i, parts_1, part, formattedHours, formattedMinutes, formattedSeconds, formattedDuration;
46
+ return __generator(this, function (_a) {
47
+ parts = durationString.split(", ");
48
+ hours = 0;
49
+ minutes = 0;
50
+ seconds = 0;
51
+ for (_i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
52
+ part = parts_1[_i];
53
+ if (part.includes("hr")) {
54
+ hours = parseInt(part);
55
+ }
56
+ else if (part.includes("min")) {
57
+ minutes = parseInt(part);
58
+ }
59
+ else if (part.includes("sec")) {
60
+ seconds = parseInt(part);
61
+ }
62
+ }
63
+ formattedHours = hours.toString().padStart(2, "0");
64
+ formattedMinutes = minutes.toString().padStart(2, "0");
65
+ formattedSeconds = seconds.toString().padStart(2, "0");
66
+ formattedDuration = "".concat(formattedHours, ":").concat(formattedMinutes, ":").concat(formattedSeconds);
67
+ return [2 /*return*/, formattedDuration];
68
+ });
69
+ });
70
+ }
71
+ function drawCard(options) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ function shuffleArray(array) {
74
+ var _a;
75
+ for (var i = array.length - 1; i > 0; i--) {
76
+ var j = Math.floor(Math.random() * (i + 1));
77
+ _a = [array[j], array[i]], array[i] = _a[0], array[j] = _a[1];
78
+ }
79
+ return array;
80
+ }
81
+ function detectImageColors(imagePath) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var image, canvas, ctx, imageData, data, colors, i, color, shuffledColors, selectedColors;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0: return [4 /*yield*/, (0, canvas_1.loadImage)(imagePath)];
87
+ case 1:
88
+ image = _a.sent();
89
+ canvas = (0, canvas_1.createCanvas)(image.width, image.height);
90
+ ctx = canvas.getContext("2d");
91
+ ctx.drawImage(image, 0, 0, image.width, image.height);
92
+ imageData = ctx.getImageData(0, 0, image.width, image.height);
93
+ data = imageData.data;
94
+ colors = [];
95
+ for (i = 0; i < data.length; i += 4) {
96
+ color = "rgba(".concat(data[i], ", ").concat(data[i + 1], ", ").concat(data[i + 2], ", ").concat(data[i + 3] / 255, ")");
97
+ colors.push(color);
98
+ }
99
+ shuffledColors = shuffleArray(colors);
100
+ selectedColors = shuffledColors.slice(0, 5);
101
+ return [2 /*return*/, selectedColors];
102
+ }
103
+ });
104
+ });
105
+ }
106
+ var gradientColors, gradientType, canvasOption, maxWidth, minWidth, calculatedWidth, images, image, slicedTitle, slicedAuthor, xAdjustment, textOptionsArray, _a, buffer, attachment;
107
+ var _b;
108
+ return __generator(this, function (_c) {
109
+ switch (_c.label) {
110
+ case 0: return [4 /*yield*/, detectImageColors(options.thumbnail)];
111
+ case 1:
112
+ gradientColors = _c.sent();
113
+ if (Math.random() < 0.5) {
114
+ gradientType = "linear";
115
+ }
116
+ else {
117
+ gradientType = "radial";
118
+ }
119
+ canvasOption = {
120
+ width: 1024,
121
+ height: 570,
122
+ backgroundGradient: {
123
+ type: gradientType,
124
+ startX: 1024 / 2,
125
+ startY: 570 / 2,
126
+ endX: 1024 / 2,
127
+ endY: 570 / 2,
128
+ colors: [
129
+ { stop: 0, color: gradientColors[0] },
130
+ { stop: 0.5, color: gradientColors[1] },
131
+ { stop: 1, color: gradientColors[2] },
132
+ ],
133
+ },
134
+ borderRadius: 40,
135
+ };
136
+ maxWidth = 400;
137
+ minWidth = 0;
138
+ calculatedWidth = (options.volume.volume / 1000) * (maxWidth - minWidth) + minWidth;
139
+ images = [
140
+ {
141
+ source: "square",
142
+ x: 30,
143
+ y: 22,
144
+ rotate: 0,
145
+ filled: true,
146
+ width: 965,
147
+ height: 525,
148
+ borderRadius: 35,
149
+ color: "rgba(0, 0, 0, 0.4)",
150
+ stroke: {
151
+ color: "#498afc",
152
+ width: 15,
153
+ borderRadius: 35,
154
+ },
155
+ },
156
+ {
157
+ source: options.thumbnail,
158
+ x: 98,
159
+ y: 166,
160
+ rotate: 0,
161
+ filled: true,
162
+ width: 250,
163
+ height: 250,
164
+ borderRadius: 35,
165
+ color: "rgba(0, 0, 0, 0.4)",
166
+ stroke: {
167
+ color: "#dcbfff",
168
+ width: 2,
169
+ borderRadius: 35,
170
+ },
171
+ shadow: {
172
+ color: "#ffffff",
173
+ offsetX: 2,
174
+ offsetY: 2,
175
+ opacity: 1,
176
+ blur: 20,
177
+ borderRadius: 35,
178
+ },
179
+ },
180
+ {
181
+ source: "square",
182
+ x: 468,
183
+ y: 246,
184
+ rotate: 0,
185
+ filled: true,
186
+ width: 480,
187
+ height: 10,
188
+ color: "#1d2024",
189
+ },
190
+ {
191
+ source: "square",
192
+ x: 468,
193
+ y: 246,
194
+ rotate: 0,
195
+ filled: true,
196
+ width: 40,
197
+ height: 10,
198
+ color: "#c90202",
199
+ },
200
+ {
201
+ source: "circle",
202
+ x: 495,
203
+ y: 243,
204
+ rotate: 0,
205
+ filled: true,
206
+ width: 15,
207
+ height: 15,
208
+ color: "#ffffff",
209
+ },
210
+ {
211
+ source: "https://media.discordapp.net/attachments/1194391661887893544/1205334144175837224/Picsart_24-02-09_06-07-18-715.png?ex=65d7fde5&is=65c588e5&hm=b7a4d576009096de2a3c9ba86ade63f1536023872f796a08251501fd19161eb4&=&format=webp&quality=lossless&width=721&height=116",
212
+ x: 488,
213
+ y: 273,
214
+ rotate: 0,
215
+ filled: true,
216
+ width: 410,
217
+ height: 100,
218
+ },
219
+ {
220
+ source: "https://media.discordapp.net/attachments/1160840589038858330/1205677248481599518/processed-image.png?ex=65d93d70&is=65c6c870&hm=ab73603fd78ac75753329b78576d2166397ae315d24484770bf430ddfc2fb136&=&format=webp&quality=lossless&width=578&height=578",
221
+ x: 428,
222
+ y: 383,
223
+ rotate: 0,
224
+ filled: true,
225
+ width: 45,
226
+ height: 45,
227
+ },
228
+ {
229
+ source: "square",
230
+ x: 476,
231
+ y: 396,
232
+ rotate: 0,
233
+ filled: true,
234
+ width: 400,
235
+ height: 20,
236
+ color: "#1d2024",
237
+ borderRadius: 10,
238
+ },
239
+ {
240
+ source: "square",
241
+ x: 476,
242
+ y: 396,
243
+ rotate: 0,
244
+ filled: true,
245
+ width: calculatedWidth,
246
+ height: 20,
247
+ color: "white",
248
+ borderRadius: 10,
249
+ },
250
+ {
251
+ source: "https://media.discordapp.net/attachments/1160840589038858330/1205677079081783388/processed-image.png?ex=65d93d48&is=65c6c848&hm=b6fd170f8cd357fb75074b00c85eb8b680f43479a54998c54473336017230490&=&format=webp&quality=lossless&width=578&height=578",
252
+ x: 888,
253
+ y: 382,
254
+ rotate: 0,
255
+ filled: true,
256
+ width: 50,
257
+ height: 50,
258
+ },
259
+ ];
260
+ return [4 /*yield*/, paintImage.drawImages(images, canvasOption, __dirname)];
261
+ case 2:
262
+ image = _c.sent();
263
+ slicedTitle = options.title.length > 36 ? options.title.slice(0, 36) + "..." : options.title;
264
+ slicedAuthor = options.author.length > 12 ? options.title.slice(0, 12) + "..." : options.title;
265
+ xAdjustment = 0;
266
+ if (slicedTitle.length > 14) {
267
+ xAdjustment = (slicedTitle.length - 3) * -16.5;
268
+ }
269
+ _a = [{
270
+ text: slicedTitle,
271
+ x: 660 + xAdjustment,
272
+ y: 85,
273
+ fontSize: 55,
274
+ fontName: "tajawal",
275
+ fontPath: "./tajawal.ttf",
276
+ color: "white",
277
+ shadow: {
278
+ offsetX: 1,
279
+ offsetY: 1,
280
+ color: "white",
281
+ blur: 10,
282
+ opacity: 0.4,
283
+ },
284
+ stroke: {
285
+ color: "#deff08",
286
+ width: 1.2,
287
+ },
288
+ },
289
+ {
290
+ text: "Featured By: @".concat(slicedAuthor),
291
+ x: 480,
292
+ y: 180,
293
+ fontName: "tajawal",
294
+ fontPath: "./tajawal.ttf",
295
+ fontSize: 38,
296
+ color: "white",
297
+ stroke: {
298
+ color: "black",
299
+ width: 0.8,
300
+ },
301
+ },
302
+ {
303
+ text: "0:05",
304
+ x: 455,
305
+ y: 265,
306
+ fontName: "tajawal",
307
+ fontPath: "./tajawal.ttf",
308
+ fontSize: 28,
309
+ color: "white",
310
+ stroke: {
311
+ color: "black",
312
+ width: 0.8,
313
+ },
314
+ }];
315
+ _b = {};
316
+ return [4 /*yield*/, formatDurationString(options.durationString)];
317
+ case 3:
318
+ textOptionsArray = _a.concat([
319
+ (_b.text = _c.sent(),
320
+ _b.x = 860,
321
+ _b.y = 265,
322
+ _b.fontName = "tajawal",
323
+ _b.fontPath = "./tajawal.ttf",
324
+ _b.fontSize = 28,
325
+ _b.color = "white",
326
+ _b.stroke = {
327
+ color: "black",
328
+ width: 0.8,
329
+ },
330
+ _b)
331
+ ]);
332
+ return [4 /*yield*/, paintImage.addText(textOptionsArray, image, __dirname)];
333
+ case 4:
334
+ buffer = _c.sent();
335
+ attachment = new options.builder(buffer, { name: "music-theme.png" });
336
+ return [2 /*return*/, attachment];
337
+ }
338
+ });
339
+ });
340
+ }
341
+
342
+ exports.drawCard = drawCard;
Binary file
Binary file
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.initializeDb = exports.getDb = exports.mongoConnect = void 0;
40
+ var mongodb_1 = require("mongodb");
41
+ var _mongoDb;
42
+ var mongoConnect = function (connectionString, dbName) { return __awaiter(void 0, void 0, void 0, function () {
43
+ var client, error_1;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ if (!connectionString.startsWith("mongodb://") && !connectionString.startsWith("mongodb+srv://")) {
48
+ console.error('Invalid MongoDB connection string. Please start with "mongodb://" or "mongodb+srv://');
49
+ return [2 /*return*/, false];
50
+ }
51
+ if (!dbName) {
52
+ console.error("You need to provide a database name");
53
+ return [2 /*return*/, false];
54
+ }
55
+ _a.label = 1;
56
+ case 1:
57
+ _a.trys.push([1, 3, , 4]);
58
+ client = new mongodb_1.MongoClient(connectionString);
59
+ return [4 /*yield*/, client.connect()];
60
+ case 2:
61
+ _a.sent();
62
+ _mongoDb = client.db(dbName);
63
+ console.log("Successfully connected to MongoDB");
64
+ return [2 /*return*/, true];
65
+ case 3:
66
+ error_1 = _a.sent();
67
+ console.error("MongoDB connection error:", {
68
+ message: error_1.message,
69
+ stack: error_1.stack,
70
+ });
71
+ return [2 /*return*/, false];
72
+ case 4: return [2 /*return*/];
73
+ }
74
+ });
75
+ }); };
76
+ exports.mongoConnect = mongoConnect;
77
+ var getDb = function () { return __awaiter(void 0, void 0, void 0, function () {
78
+ return __generator(this, function (_a) {
79
+ return [2 /*return*/, _mongoDb];
80
+ });
81
+ }); };
82
+ exports.getDb = getDb;
83
+ var initializeDb = function (delayTime, maxRetryAttempts) {
84
+ if (maxRetryAttempts === void 0) { maxRetryAttempts = 3; }
85
+ return __awaiter(void 0, void 0, void 0, function () {
86
+ var isInitialized, retryCount, db;
87
+ return __generator(this, function (_a) {
88
+ switch (_a.label) {
89
+ case 0:
90
+ isInitialized = false;
91
+ retryCount = 0;
92
+ _a.label = 1;
93
+ case 1: return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delayTime); })];
94
+ case 2:
95
+ _a.sent();
96
+ return [4 /*yield*/, getDb()];
97
+ case 3:
98
+ db = _a.sent();
99
+ if (!db) {
100
+ console.error("No active MongoDB connection. Initializing connection...");
101
+ retryCount++;
102
+ }
103
+ else {
104
+ isInitialized = true;
105
+ }
106
+ _a.label = 4;
107
+ case 4:
108
+ if (!isInitialized && retryCount < maxRetryAttempts) return [3 /*break*/, 1];
109
+ _a.label = 5;
110
+ case 5:
111
+ if (!isInitialized) {
112
+ console.log("Maximum retry attempts reached (".concat(retryCount, "/").concat(maxRetryAttempts, ")."));
113
+ }
114
+ return [2 /*return*/, isInitialized];
115
+ }
116
+ });
117
+ });
118
+ };
119
+ exports.initializeDb = initializeDb;
120
+
121
+
122
+ module.exports = {
123
+ mongoConnect,
124
+ getDb,
125
+ initializeDb
126
+ };