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