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,872 @@
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.xpRank = exports.leaderBoard = exports.levelCard = void 0;
40
+ var ApexPainter_1 = require("../ApexPainter");
41
+ var painter = new ApexPainter_1.ApexPainter();
42
+ function levelCard(message, userRecord) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var guild, member, user, canvasOptions, images, image, prev, current, getDynamicPrev, getDynamicCurrent, textOptionsArray, card;
45
+ return __generator(this, function (_a) {
46
+ switch (_a.label) {
47
+ case 0: return [4 /*yield*/, message.client.guilds.fetch(userRecord.guildId)];
48
+ case 1:
49
+ guild = _a.sent();
50
+ return [4 /*yield*/, guild.members.fetch(userRecord.userId)];
51
+ case 2:
52
+ member = _a.sent();
53
+ user = {
54
+ userId: userRecord.userId,
55
+ xpCount: userRecord.xpCount,
56
+ level: userRecord.level,
57
+ guildId: userRecord.guildId,
58
+ displayAvatarURL: member.user.displayAvatarURL(),
59
+ };
60
+ if (!member) {
61
+ throw new Error("Error: Couldn't find the user in this server.");
62
+ }
63
+ if (!(userRecord === null || userRecord === void 0 ? void 0 : userRecord.userId)) {
64
+ user.level = 0;
65
+ throw new Error("Error: Couldn't find data for this user.");
66
+ }
67
+ canvasOptions = {
68
+ width: 1228,
69
+ height: 300,
70
+ customBg: 'https://media.discordapp.net/attachments/1173043530873188402/1211708088462213161/levelup.png?ex=65ef2e18&is=65dcb918&hm=0a84fe70628678a740414ccf624b416826ffc06c4a595206a1da4fbe24d25848&=&format=webp&quality=lossless&width=1228&height=300',
71
+ borderRadius: 20,
72
+ };
73
+ images = [
74
+ {
75
+ source: user.displayAvatarURL,
76
+ borderRadius: 'circular',
77
+ x: 76,
78
+ y: 33,
79
+ width: 183,
80
+ height: 183,
81
+ },
82
+ ];
83
+ return [4 /*yield*/, painter.drawImages(images, canvasOptions)];
84
+ case 3:
85
+ image = _a.sent();
86
+ prev = user.level - 1;
87
+ current = user.level;
88
+ getDynamicPrev = function (text) {
89
+ var textLength = text.toString().length;
90
+ if (textLength === 1)
91
+ return 433;
92
+ else if (textLength === 2)
93
+ return 417;
94
+ else if (textLength === 3)
95
+ return 399;
96
+ else
97
+ return 384;
98
+ };
99
+ getDynamicCurrent = function (text) {
100
+ var textLength = text.toString().length;
101
+ if (textLength === 1)
102
+ return 798;
103
+ else if (textLength === 2)
104
+ return 783;
105
+ else if (textLength === 3)
106
+ return 766;
107
+ else
108
+ return 752;
109
+ };
110
+ textOptionsArray = [
111
+ {
112
+ text: "".concat(prev),
113
+ x: getDynamicPrev(prev),
114
+ y: 103,
115
+ fontSize: 50,
116
+ color: '#14cee7',
117
+ stroke: {
118
+ color: 'black',
119
+ width: 0.5,
120
+ },
121
+ },
122
+ {
123
+ text: "".concat(current),
124
+ x: getDynamicCurrent(current),
125
+ y: 103,
126
+ fontSize: 50,
127
+ color: '#14cee7',
128
+ stroke: {
129
+ color: 'black',
130
+ width: 0.5,
131
+ },
132
+ },
133
+ ];
134
+ return [4 /*yield*/, painter.addText(textOptionsArray, image, __dirname)];
135
+ case 4:
136
+ card = _a.sent();
137
+ return [2 /*return*/, card];
138
+ }
139
+ });
140
+ });
141
+ }
142
+ exports.levelCard = levelCard;
143
+ function xpRank(message, guildId, userId, level, rank, currentXp, nextXp, levelsArray, version, userBanner) {
144
+ var _a, _b, _c;
145
+ return __awaiter(this, void 0, void 0, function () {
146
+ var guild, member, user, resizedBanner, canvasOptions, loadingBarWidth, userCount, currentLevel, progress, dynamicRank, images, image, englishRegex, arabicRegex, username, guildName, fontName, fontPath, fontSize, nameX, fontname, fontpath, fontsize, namex, textAlign, textOptionsArray, card;
147
+ return __generator(this, function (_d) {
148
+ switch (_d.label) {
149
+ case 0: return [4 /*yield*/, message.client.guilds.fetch(guildId)];
150
+ case 1:
151
+ guild = _d.sent();
152
+ return [4 /*yield*/, guild.members.fetch(userId)];
153
+ case 2:
154
+ member = _d.sent();
155
+ user = {
156
+ displayAvatarURL: member.user.displayAvatarURL(),
157
+ };
158
+ if (!member) {
159
+ throw new Error("Error: Couldn't find the user in this server.");
160
+ }
161
+ if (userBanner && userBanner.startsWith('http')) {
162
+ resizedBanner = userBanner;
163
+ }
164
+ else {
165
+ resizedBanner = 'https://t4.ftcdn.net/jpg/02/97/79/83/360_F_297798377_VB9egqGnRKcZxU53wybEHLRnnTrcvlAH.jpg';
166
+ }
167
+ canvasOptions = {
168
+ width: 588,
169
+ height: 578,
170
+ color: 'transparent',
171
+ borderRadius: 0,
172
+ };
173
+ loadingBarWidth = 293;
174
+ userCount = currentXp;
175
+ currentLevel = ((_a = levelsArray.find(function (levelData) { return userCount < levelData.xpCount; })) === null || _a === void 0 ? void 0 : _a.level) || levelsArray.length - 1;
176
+ progress = (userCount - ((_b = levelsArray[currentLevel - 1]) === null || _b === void 0 ? void 0 : _b.xpCount)) /
177
+ (levelsArray[currentLevel].xpCount - ((_c = levelsArray[currentLevel - 1]) === null || _c === void 0 ? void 0 : _c.xpCount)) *
178
+ loadingBarWidth;
179
+ dynamicRank = function (text) {
180
+ var textLength = text.toString().length;
181
+ if (textLength === 1)
182
+ return 482;
183
+ else if (textLength === 2)
184
+ return 455;
185
+ else if (textLength === 3)
186
+ return 445;
187
+ else
188
+ return 390;
189
+ };
190
+ images = [
191
+ {
192
+ source: 'square',
193
+ borderRadius: 12,
194
+ x: 56,
195
+ y: 406,
196
+ filled: true,
197
+ color: 'white',
198
+ width: 500,
199
+ height: 180,
200
+ },
201
+ {
202
+ source: resizedBanner,
203
+ borderRadius: 5,
204
+ x: 18,
205
+ y: 38,
206
+ width: 552,
207
+ height: 360,
208
+ },
209
+ {
210
+ source: 'https://media.discordapp.net/attachments/1173043530873188402/1212577172988891187/image2.png?ex=65f2577e&is=65dfe27e&hm=3bd99759d7ea9b86f01a5a754be6f44a74b12e3e9edb9babc6a0c3d84405ff2b&=&format=webp&quality=lossless&width=588&height=578',
211
+ borderRadius: 5,
212
+ x: 0,
213
+ y: 0,
214
+ width: 588,
215
+ height: 578,
216
+ },
217
+ {
218
+ source: user.displayAvatarURL,
219
+ borderRadius: 'circular',
220
+ x: 208,
221
+ y: 123,
222
+ width: 163,
223
+ height: 163,
224
+ stroke: {
225
+ color: randomHex(),
226
+ width: 5,
227
+ borderRadius: 'circular',
228
+ },
229
+ },
230
+ {
231
+ source: guild.iconURL(),
232
+ borderRadius: 'circular',
233
+ x: 165,
234
+ y: 43,
235
+ width: 47,
236
+ height: 47,
237
+ },
238
+ {
239
+ source: 'square',
240
+ borderRadius: 12,
241
+ x: 56,
242
+ y: 446,
243
+ filled: true,
244
+ color: '#5aa3ff',
245
+ width: progress,
246
+ height: 22,
247
+ },
248
+ {
249
+ source: 'square',
250
+ borderRadius: 12,
251
+ x: 56,
252
+ y: 518,
253
+ filled: true,
254
+ color: '#5aa3ff',
255
+ width: 263,
256
+ height: 22,
257
+ },
258
+ ];
259
+ return [4 /*yield*/, painter.drawImages(images, canvasOptions)];
260
+ case 3:
261
+ image = _d.sent();
262
+ englishRegex = /[a-zA-Z]/;
263
+ arabicRegex = /[\u0600-\u06FF]/;
264
+ username = (member.user.globalName || member.user.username).substring(0, 12);
265
+ guildName = (guild.name).substring(0, 18);
266
+ fontName = '';
267
+ fontPath = '';
268
+ if (englishRegex.test(username)) {
269
+ fontName = 'LevelFont eng';
270
+ fontSize = 65;
271
+ nameX = 200;
272
+ fontPath = './levelFont.ttf';
273
+ }
274
+ else if (arabicRegex.test(username)) {
275
+ fontName = 'LevelFont ara';
276
+ fontSize = 65;
277
+ nameX = 200 + 80;
278
+ fontPath = 'level ara.ttf';
279
+ }
280
+ else {
281
+ fontName = 'LevelFont eng';
282
+ fontSize = 65;
283
+ nameX = 200;
284
+ fontPath = './levelFont.ttf';
285
+ }
286
+ fontname = '';
287
+ fontpath = '';
288
+ if (englishRegex.test(guildName)) {
289
+ fontname = 'LevelFont eng';
290
+ fontsize = 25;
291
+ namex = 220;
292
+ textAlign = "left";
293
+ fontpath = './levelFont.ttf';
294
+ }
295
+ else if (arabicRegex.test(guildName)) {
296
+ fontname = 'LevelFont ara';
297
+ fontsize = 25;
298
+ namex = 200 + 55;
299
+ textAlign = "right",
300
+ fontpath = 'level ara.ttf';
301
+ }
302
+ else {
303
+ fontname = 'LevelFont eng';
304
+ fontsize = 25;
305
+ namex = 220;
306
+ textAlign = "left";
307
+ fontpath = './levelFont.ttf';
308
+ }
309
+ textOptionsArray = [
310
+ {
311
+ text: "".concat(level),
312
+ x: 185,
313
+ y: 418,
314
+ fontSize: 30,
315
+ fontName: 'numbers',
316
+ fontPath: './numbers.ttf',
317
+ color: 'white',
318
+ stroke: {
319
+ color: 'black',
320
+ width: 0.6,
321
+ },
322
+ },
323
+ {
324
+ text: "".concat(currentXp, "/").concat(nextXp),
325
+ x: 142,
326
+ y: 450,
327
+ fontSize: 22,
328
+ fontName: 'numbers',
329
+ fontPath: './numbers.ttf',
330
+ color: 'black',
331
+ stroke: {
332
+ color: 'black',
333
+ width: 0.5,
334
+ },
335
+ shadow: {
336
+ offsetX: 2,
337
+ offsetY: 2,
338
+ color: 'white',
339
+ opacity: 0.3,
340
+ blur: 5,
341
+ },
342
+ },
343
+ {
344
+ text: "".concat(rank),
345
+ x: dynamicRank(rank),
346
+ y: 460,
347
+ fontSize: 70,
348
+ fontName: 'numbers',
349
+ fontPath: './numbers.ttf',
350
+ color: '#ffffff',
351
+ stroke: {
352
+ color: 'black',
353
+ width: 0.6,
354
+ },
355
+ shadow: {
356
+ offsetX: 2,
357
+ offsetY: 2,
358
+ color: 'black',
359
+ opacity: 0.5,
360
+ blur: 10,
361
+ },
362
+ },
363
+ {
364
+ text: "Coming Soon...",
365
+ x: 202,
366
+ y: 490,
367
+ fontSize: 23,
368
+ fontName: 'levelFont eng',
369
+ fontPath: './levelFont.ttf',
370
+ color: '#ffffff',
371
+ stroke: {
372
+ color: 'black',
373
+ width: 0.5,
374
+ },
375
+ shadow: {
376
+ offsetX: 2,
377
+ offsetY: 2,
378
+ color: 'black',
379
+ opacity: 0.5,
380
+ blur: 10,
381
+ },
382
+ },
383
+ {
384
+ text: "Coming Soon...",
385
+ x: 135,
386
+ y: 522,
387
+ fontSize: 23,
388
+ fontName: 'nubers',
389
+ fontPath: './numbers.ttf',
390
+ color: '#706f6f',
391
+ stroke: {
392
+ color: 'black',
393
+ width: 0.5,
394
+ },
395
+ },
396
+ {
397
+ text: "".concat(username),
398
+ x: nameX,
399
+ y: 320,
400
+ fontSize: fontSize,
401
+ fontName: fontName,
402
+ fontPath: fontPath,
403
+ color: 'white',
404
+ stroke: {
405
+ color: 'black',
406
+ width: 0.5,
407
+ },
408
+ },
409
+ {
410
+ text: "".concat(guildName),
411
+ x: namex,
412
+ y: 52,
413
+ fontSize: fontsize,
414
+ fontName: fontname,
415
+ fontPath: fontpath,
416
+ textAlign: textAlign,
417
+ color: 'white',
418
+ stroke: {
419
+ color: 'black',
420
+ width: 0.5,
421
+ },
422
+ },
423
+ ];
424
+ return [4 /*yield*/, painter.addText(textOptionsArray, image, __dirname)];
425
+ case 4:
426
+ card = _d.sent();
427
+ return [2 /*return*/, card];
428
+ }
429
+ });
430
+ });
431
+ }
432
+ exports.xpRank = xpRank;
433
+ function leaderBoard(message, results, version, colorHex) {
434
+ return __awaiter(this, void 0, void 0, function () {
435
+ var canvasOptions, images, textOptionsArray, _i, results_1, userRecord, guild, member, user, image, card, canvasOptions, images, textOptionsArray, _a, results_2, userRecord, guild, member, user, englishRegex, arabicRegex, username, fontName, fontPath, fontSize, dynamicLevel, colorText, image, card, resizeOptions, resizedImageBuffer;
436
+ return __generator(this, function (_b) {
437
+ switch (_b.label) {
438
+ case 0:
439
+ if (!(version === 1)) return [3 /*break*/, 11];
440
+ canvasOptions = {
441
+ width: 959,
442
+ height: 706,
443
+ x: 0,
444
+ y: 0,
445
+ customBg: 'https://media.discordapp.net/attachments/1173043530873188402/1211708088197976188/lb.png?ex=65ef2e18&is=65dcb918&hm=b332b70f43babb0640c5d40d9b6fd41a348a0e4381eadb60cda5cb3d9eac3cb6&=&format=webp&quality=lossless&width=759&height=506',
446
+ borderRadius: 10,
447
+ };
448
+ images = [];
449
+ textOptionsArray = [];
450
+ _i = 0, results_1 = results;
451
+ _b.label = 1;
452
+ case 1:
453
+ if (!(_i < results_1.length)) return [3 /*break*/, 8];
454
+ userRecord = results_1[_i];
455
+ guild = void 0;
456
+ if (!message.client) return [3 /*break*/, 3];
457
+ return [4 /*yield*/, message.client.guilds.fetch(userRecord.guildId)];
458
+ case 2:
459
+ guild = _b.sent();
460
+ return [3 /*break*/, 5];
461
+ case 3: return [4 /*yield*/, message.guilds.fetch(results[0].guildId)];
462
+ case 4:
463
+ guild = _b.sent();
464
+ _b.label = 5;
465
+ case 5: return [4 /*yield*/, guild.members.fetch(userRecord.userId)];
466
+ case 6:
467
+ member = _b.sent();
468
+ user = {
469
+ userId: userRecord.userId,
470
+ xpCount: userRecord.xpCount,
471
+ level: userRecord.level,
472
+ guildId: userRecord.guildId,
473
+ displayAvatarURL: member.user.displayAvatarURL(),
474
+ username: member.user.globalName || member.user.username,
475
+ };
476
+ images.push({
477
+ source: user.displayAvatarURL,
478
+ borderRadius: 'circular',
479
+ x: 97,
480
+ y: 90 + (53 + 10) * images.length,
481
+ width: 53,
482
+ height: 53,
483
+ });
484
+ textOptionsArray.push({
485
+ text: "".concat(user.username.slice(0, 7).trim()),
486
+ x: 170,
487
+ y: 38 + (53 + 10) * images.length,
488
+ fontSize: 30,
489
+ color: '#14cee7',
490
+ stroke: {
491
+ color: 'black',
492
+ width: 0.5,
493
+ },
494
+ shadow: {
495
+ offsetX: 3,
496
+ offsetY: 3,
497
+ color: "rgba(0, 0, 0, 0.8)",
498
+ opacity: 0.4,
499
+ blur: 5
500
+ },
501
+ }, {
502
+ text: "Level: ".concat(user.level),
503
+ x: 300,
504
+ y: 43 + (53 + 10) * images.length,
505
+ fontSize: 25,
506
+ color: '#14cee7',
507
+ stroke: {
508
+ color: 'black',
509
+ width: 0.5,
510
+ },
511
+ shadow: {
512
+ offsetX: 3,
513
+ offsetY: 3,
514
+ color: "rgba(0, 0, 0, 0.8)",
515
+ opacity: 0.3,
516
+ blur: 5
517
+ },
518
+ }, {
519
+ text: "Xp: ".concat(user.xpCount),
520
+ x: 425,
521
+ y: 46 + (53 + 10) * images.length,
522
+ fontSize: 18,
523
+ color: '#14cee7',
524
+ stroke: {
525
+ color: 'black',
526
+ width: 0.5,
527
+ },
528
+ shadow: {
529
+ offsetX: 3,
530
+ offsetY: 3,
531
+ color: "rgba(0, 0, 0, 0.8)",
532
+ opacity: 0.3,
533
+ blur: 5
534
+ },
535
+ });
536
+ _b.label = 7;
537
+ case 7:
538
+ _i++;
539
+ return [3 /*break*/, 1];
540
+ case 8: return [4 /*yield*/, painter.drawImages(images, canvasOptions)];
541
+ case 9:
542
+ image = _b.sent();
543
+ return [4 /*yield*/, painter.addText(textOptionsArray, image, __dirname)];
544
+ case 10:
545
+ card = _b.sent();
546
+ return [2 /*return*/, card];
547
+ case 11:
548
+ if (!(version === 2)) return [3 /*break*/, 23];
549
+ canvasOptions = {
550
+ width: 600,
551
+ height: 600,
552
+ x: 0,
553
+ y: 0,
554
+ customBg: 'https://media.discordapp.net/attachments/1131285544740061266/1212243800496275546/leaderboard.webp?ex=65f12104&is=65deac04&hm=6eebaa7febc64bca70ad7f45f87da868045007bf5d75b3261c16fed930901a4c&=&format=webp&width=578&height=578',
555
+ borderRadius: 10,
556
+ };
557
+ images = [];
558
+ textOptionsArray = [];
559
+ _a = 0, results_2 = results;
560
+ _b.label = 12;
561
+ case 12:
562
+ if (!(_a < results_2.length)) return [3 /*break*/, 19];
563
+ userRecord = results_2[_a];
564
+ guild = void 0;
565
+ if (!message.client) return [3 /*break*/, 14];
566
+ return [4 /*yield*/, message.client.guilds.fetch(userRecord.guildId)];
567
+ case 13:
568
+ guild = _b.sent();
569
+ return [3 /*break*/, 16];
570
+ case 14: return [4 /*yield*/, message.guilds.fetch(results[0].guildId)];
571
+ case 15:
572
+ guild = _b.sent();
573
+ _b.label = 16;
574
+ case 16: return [4 /*yield*/, guild.members.fetch(userRecord.userId)];
575
+ case 17:
576
+ member = _b.sent();
577
+ user = {
578
+ userId: userRecord.userId,
579
+ xpCount: userRecord.xpCount,
580
+ level: userRecord.level,
581
+ guildId: userRecord.guildId,
582
+ displayAvatarURL: member.user.displayAvatarURL(),
583
+ username: member.user.globalName || member.user.username,
584
+ };
585
+ englishRegex = /[a-zA-Z]/;
586
+ arabicRegex = /[\u0600-\u06FF]/;
587
+ username = user.username;
588
+ fontName = '';
589
+ fontPath = '';
590
+ fontSize = void 0;
591
+ if (englishRegex.test(username)) {
592
+ fontName = 'LevelFont eng';
593
+ fontSize = 28;
594
+ fontPath = './levelFont.ttf';
595
+ }
596
+ else if (arabicRegex.test(username)) {
597
+ fontName = 'LevelFont ara';
598
+ fontSize = 28;
599
+ fontPath = 'level ara.ttf';
600
+ }
601
+ else {
602
+ fontName = 'LevelFont eng';
603
+ fontSize = 28;
604
+ fontPath = './levelFont.ttf';
605
+ }
606
+ dynamicLevel = function (text) {
607
+ var textLength = text.toString().length;
608
+ if (textLength === 1)
609
+ return 417;
610
+ else if (textLength === 2)
611
+ return 411;
612
+ else if (textLength === 3)
613
+ return 398;
614
+ else
615
+ return 390;
616
+ };
617
+ colorText = void 0;
618
+ if (colorHex !== 'random') {
619
+ colorText = colorHex;
620
+ }
621
+ else if (colorHex === 'random') {
622
+ colorText = randomHex();
623
+ }
624
+ else {
625
+ colorText = randomHex();
626
+ }
627
+ images.push({
628
+ source: user.displayAvatarURL,
629
+ borderRadius: 'circular',
630
+ x: 38,
631
+ y: 138.5 + (60 + 10.5) * images.length,
632
+ width: 61,
633
+ height: 61,
634
+ stroke: {
635
+ color: randomHex(),
636
+ width: 3,
637
+ borderRadius: 'circular',
638
+ }
639
+ });
640
+ textOptionsArray.push({
641
+ text: "SERVER LEADERBOARD",
642
+ x: 55,
643
+ y: 16,
644
+ fontSize: 55,
645
+ fontName: 'LevelFont eng',
646
+ fontPath: './levelFont.ttf',
647
+ color: '#14cee7',
648
+ stroke: {
649
+ color: 'black',
650
+ width: 0.5,
651
+ },
652
+ shadow: {
653
+ offsetX: 3,
654
+ offsetY: 3,
655
+ color: "rgba(0, 0, 0, 0.8)",
656
+ opacity: 0.4,
657
+ blur: 5
658
+ },
659
+ }, {
660
+ text: "pfp",
661
+ x: 52,
662
+ y: 87,
663
+ fontSize: 25,
664
+ fontName: 'LevelFont eng',
665
+ fontPath: './levelFont.ttf',
666
+ color: 'white',
667
+ stroke: {
668
+ color: 'black',
669
+ width: 0.5,
670
+ },
671
+ }, {
672
+ text: "USERNAME",
673
+ x: 185,
674
+ y: 87,
675
+ fontSize: 30,
676
+ fontName: 'LevelFont eng',
677
+ fontPath: './levelFont.ttf',
678
+ color: 'white',
679
+ stroke: {
680
+ color: 'black',
681
+ width: 0.5,
682
+ },
683
+ }, {
684
+ text: "LEVEL",
685
+ x: 395,
686
+ y: 92,
687
+ fontSize: 25,
688
+ fontName: 'LevelFont eng',
689
+ fontPath: './levelFont.ttf',
690
+ color: 'white',
691
+ stroke: {
692
+ color: 'black',
693
+ width: 0.5,
694
+ },
695
+ }, {
696
+ text: "RANK",
697
+ x: 472,
698
+ y: 92,
699
+ fontSize: 25,
700
+ fontName: 'LevelFont eng',
701
+ fontPath: './levelFont.ttf',
702
+ color: 'white',
703
+ stroke: {
704
+ color: 'black',
705
+ width: 0.5,
706
+ },
707
+ }, {
708
+ text: "".concat(user.username.slice(0, 7).trim()),
709
+ x: 145,
710
+ y: 83 + (32 + 38) * images.length,
711
+ fontSize: fontSize + 6,
712
+ fontName: fontName,
713
+ fontPath: fontPath,
714
+ color: colorText,
715
+ stroke: {
716
+ color: 'black',
717
+ width: 0.5,
718
+ },
719
+ shadow: {
720
+ offsetX: 3,
721
+ offsetY: 3,
722
+ color: "rgba(0, 0, 0, 0.8)",
723
+ opacity: 0.4,
724
+ blur: 5
725
+ },
726
+ }, {
727
+ text: "".concat(user.level),
728
+ x: dynamicLevel(user.level.toString()),
729
+ y: 85 + (32 + 38) * images.length,
730
+ fontSize: 35,
731
+ fontName: 'LevelFont eng',
732
+ fontPath: './levelFont.ttf',
733
+ color: colorText,
734
+ stroke: {
735
+ color: 'black',
736
+ width: 0.5,
737
+ },
738
+ shadow: {
739
+ offsetX: 3,
740
+ offsetY: 3,
741
+ color: "rgba(0, 0, 0, 0.8)",
742
+ opacity: 0.3,
743
+ blur: 5
744
+ },
745
+ }, {
746
+ text: "#1",
747
+ x: 475,
748
+ y: 157,
749
+ fontSize: 32,
750
+ fontName: 'LevelFont eng',
751
+ fontPath: './levelFont.ttf',
752
+ color: '#ffd700',
753
+ stroke: {
754
+ color: 'black',
755
+ width: 0.6,
756
+ },
757
+ shadow: {
758
+ offsetX: 3,
759
+ offsetY: 3,
760
+ color: "rgba(0, 0, 0, 0.6)",
761
+ opacity: 0.3,
762
+ blur: 5
763
+ },
764
+ }, {
765
+ text: "#2",
766
+ x: 475,
767
+ y: 225,
768
+ fontSize: 32,
769
+ fontName: 'LevelFont eng',
770
+ fontPath: './levelFont.ttf',
771
+ color: '#bababa',
772
+ stroke: {
773
+ color: 'black',
774
+ width: 0.4,
775
+ },
776
+ shadow: {
777
+ offsetX: 3,
778
+ offsetY: 3,
779
+ color: "rgba(0, 0, 0, 0.6)",
780
+ opacity: 0.3,
781
+ blur: 5
782
+ },
783
+ }, {
784
+ text: "#3",
785
+ x: 475,
786
+ y: 297,
787
+ fontSize: 32,
788
+ fontName: 'LevelFont eng',
789
+ fontPath: './levelFont.ttf',
790
+ color: '#cd7f32',
791
+ stroke: {
792
+ color: 'black',
793
+ width: 0.6,
794
+ },
795
+ shadow: {
796
+ offsetX: 3,
797
+ offsetY: 3,
798
+ color: "rgba(0, 0, 0, 0.6)",
799
+ opacity: 0.3,
800
+ blur: 5
801
+ },
802
+ }, {
803
+ text: "#4",
804
+ x: 475,
805
+ y: 275 + 92,
806
+ fontSize: 32,
807
+ fontName: 'LevelFont eng',
808
+ fontPath: './levelFont.ttf',
809
+ color: 'white',
810
+ stroke: {
811
+ color: 'black',
812
+ width: 0.6,
813
+ },
814
+ shadow: {
815
+ offsetX: 3,
816
+ offsetY: 3,
817
+ color: "rgba(0, 0, 0, 0.6)",
818
+ opacity: 0.3,
819
+ blur: 5
820
+ },
821
+ }, {
822
+ text: "#5",
823
+ x: 475,
824
+ y: 275 + 75 + 87,
825
+ fontSize: 32,
826
+ fontName: 'LevelFont eng',
827
+ fontPath: './levelFont.ttf',
828
+ color: 'white',
829
+ stroke: {
830
+ color: 'black',
831
+ width: 0.6,
832
+ },
833
+ shadow: {
834
+ offsetX: 3,
835
+ offsetY: 3,
836
+ color: "rgba(0, 0, 0, 0.6)",
837
+ opacity: 0.3,
838
+ blur: 5
839
+ },
840
+ });
841
+ _b.label = 18;
842
+ case 18:
843
+ _a++;
844
+ return [3 /*break*/, 12];
845
+ case 19: return [4 /*yield*/, painter.drawImages(images, canvasOptions)];
846
+ case 20:
847
+ image = _b.sent();
848
+ return [4 /*yield*/, painter.addText(textOptionsArray, image, __dirname)];
849
+ case 21:
850
+ card = _b.sent();
851
+ resizeOptions = {
852
+ imagePath: card,
853
+ size: { width: 1200, height: 1200 },
854
+ };
855
+ return [4 /*yield*/, painter.resize(resizeOptions)];
856
+ case 22:
857
+ resizedImageBuffer = _b.sent();
858
+ return [2 /*return*/, resizedImageBuffer];
859
+ case 23: return [2 /*return*/];
860
+ }
861
+ });
862
+ });
863
+ }
864
+ exports.leaderBoard = leaderBoard;
865
+ function randomHex() {
866
+ var letters = "0123456789ABCDEF";
867
+ var color = "#";
868
+ for (var i = 0; i < 6; i++) {
869
+ color += letters[Math.floor(Math.random() * 16)];
870
+ }
871
+ return color;
872
+ }