simply-xp 1.1.8 → 1.2.0
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 +2 -9
- package/package.json +6 -4
- package/simplyxp.js +31 -31
- package/src/rank.js +298 -282
- package/src/reset.js +22 -28
package/README.md
CHANGED
|
@@ -30,13 +30,8 @@ yarn add simply-xp
|
|
|
30
30
|
|
|
31
31
|
# 🎉 What's New 🎉
|
|
32
32
|
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
- roleSetup redefined.. Redid whole system.
|
|
36
|
-
- New everything.. Everything is now tidy and compact.
|
|
37
|
-
- levelUp event returns role id too !
|
|
38
|
-
- Re-coded to squeeze bugs
|
|
39
|
-
- Bug Fixes
|
|
33
|
+
- We have patched known issues, and we continue to monitor changes!
|
|
34
|
+
- Our rank card has a new font applied
|
|
40
35
|
|
|
41
36
|
# But Why ?
|
|
42
37
|
|
|
@@ -48,8 +43,6 @@ yarn add simply-xp
|
|
|
48
43
|
- Inbuilt Auto Roles system
|
|
49
44
|
- Flexible and simple at the same time
|
|
50
45
|
|
|
51
|
-
`Reconstructed discord-xp to give you things simpler ;)`
|
|
52
|
-
|
|
53
46
|
<br>
|
|
54
47
|
|
|
55
48
|
## **Need Help ? Join the [Discord Server](https://discord.gg/3JzDV9T5Fn)**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A Simple, Easy and Beginner Friendly XP System",
|
|
5
5
|
"main": "simplyxp.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -40,13 +40,15 @@
|
|
|
40
40
|
"url": "https://github.com/Rahuletto/simply-xp"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"canvas": "^2.
|
|
44
|
-
"chart.js-image": "^
|
|
45
|
-
"discord.js": "^13.8.0",
|
|
43
|
+
"canvas": "^2.9.3",
|
|
44
|
+
"chart.js-image": "^6.0.3",
|
|
46
45
|
"mongoose": "^6.0.15"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"husky": "^7.0.0",
|
|
50
49
|
"pretty-quick": "^3.1.1"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"discord.js": "^13.x.x"
|
|
51
53
|
}
|
|
52
54
|
}
|
package/simplyxp.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
try {
|
|
2
|
-
require('discord.js')
|
|
3
|
-
} catch (e) {
|
|
4
|
-
throw new Error('Discord.
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module.exports.roleSetup = require('./src/roleSetup')
|
|
8
|
-
|
|
9
|
-
module.exports.addLevel = require('./src/addLevel')
|
|
10
|
-
|
|
11
|
-
module.exports.addXP = require('./src/addXP')
|
|
12
|
-
|
|
13
|
-
module.exports.charts = require('./src/charts')
|
|
14
|
-
|
|
15
|
-
module.exports.connect = require('./src/connect')
|
|
16
|
-
|
|
17
|
-
module.exports.create = require('./src/create')
|
|
18
|
-
|
|
19
|
-
module.exports.fetch = require('./src/fetch')
|
|
20
|
-
|
|
21
|
-
module.exports.leaderboard = require('./src/leaderboard')
|
|
22
|
-
|
|
23
|
-
module.exports.lvlRole = require('./src/lvlRole')
|
|
24
|
-
|
|
25
|
-
module.exports.rank = require('./src/rank')
|
|
26
|
-
|
|
27
|
-
module.exports.setLevel = require('./src/setLevel')
|
|
28
|
-
|
|
29
|
-
module.exports.setXP = require('./src/setXP')
|
|
30
|
-
|
|
31
|
-
module.exports.reset = require('./src/reset')
|
|
1
|
+
try {
|
|
2
|
+
require('discord.js')
|
|
3
|
+
} catch (e) {
|
|
4
|
+
throw new Error('Discord.js v13 is required for this package to run')
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports.roleSetup = require('./src/roleSetup')
|
|
8
|
+
|
|
9
|
+
module.exports.addLevel = require('./src/addLevel')
|
|
10
|
+
|
|
11
|
+
module.exports.addXP = require('./src/addXP')
|
|
12
|
+
|
|
13
|
+
module.exports.charts = require('./src/charts')
|
|
14
|
+
|
|
15
|
+
module.exports.connect = require('./src/connect')
|
|
16
|
+
|
|
17
|
+
module.exports.create = require('./src/create')
|
|
18
|
+
|
|
19
|
+
module.exports.fetch = require('./src/fetch')
|
|
20
|
+
|
|
21
|
+
module.exports.leaderboard = require('./src/leaderboard')
|
|
22
|
+
|
|
23
|
+
module.exports.lvlRole = require('./src/lvlRole')
|
|
24
|
+
|
|
25
|
+
module.exports.rank = require('./src/rank')
|
|
26
|
+
|
|
27
|
+
module.exports.setLevel = require('./src/setLevel')
|
|
28
|
+
|
|
29
|
+
module.exports.setXP = require('./src/setXP')
|
|
30
|
+
|
|
31
|
+
module.exports.reset = require('./src/reset')
|
package/src/rank.js
CHANGED
|
@@ -1,282 +1,298 @@
|
|
|
1
|
-
let Discord = require('discord.js')
|
|
2
|
-
const levels = require('../src/models/level.js')
|
|
3
|
-
const { join } = require('path')
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @param {Discord.Message} message
|
|
7
|
-
* @param {string} userID
|
|
8
|
-
* @param {string} guildID
|
|
9
|
-
* @param {import('../index').rankOptions} options
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
async function rank(message, userID, guildID, options = []) {
|
|
13
|
-
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
14
|
-
|
|
15
|
-
if (!guildID) throw new Error('[XP] Guild ID was not provided.')
|
|
16
|
-
|
|
17
|
-
const user = await levels.findOne({
|
|
18
|
-
user: userID,
|
|
19
|
-
guild: guildID
|
|
20
|
-
})
|
|
21
|
-
if (!user)
|
|
22
|
-
|
|
23
|
-
const leaderboard = await levels
|
|
24
|
-
.find({
|
|
25
|
-
guild: guildID
|
|
26
|
-
})
|
|
27
|
-
.sort([['xp', 'descending']])
|
|
28
|
-
.exec()
|
|
29
|
-
|
|
30
|
-
user.position = leaderboard.findIndex((i) => i.user === userID) + 1
|
|
31
|
-
|
|
32
|
-
let targetxp = user.level + 1
|
|
33
|
-
|
|
34
|
-
let target = targetxp * targetxp * 100
|
|
35
|
-
|
|
36
|
-
return rankCard(message, {
|
|
37
|
-
level: user.level,
|
|
38
|
-
currentXP: user.xp,
|
|
39
|
-
neededXP: target,
|
|
40
|
-
rank: user.position,
|
|
41
|
-
background: options.background,
|
|
42
|
-
color: options.color,
|
|
43
|
-
lvlbar: options.lvlbar,
|
|
44
|
-
lvlbarBg: options.lvlbarBg,
|
|
45
|
-
member: message.guild.members.cache.get(userID)?.user
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
async function rankCard(message, options = []) {
|
|
49
|
-
try {
|
|
50
|
-
const Canvas = require('canvas')
|
|
51
|
-
const { registerFont } = require('canvas')
|
|
52
|
-
registerFont(join(__dirname, 'Fonts', 'Baloo-Regular.ttf'), {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
ctx.
|
|
120
|
-
ctx.
|
|
121
|
-
ctx.
|
|
122
|
-
ctx.
|
|
123
|
-
|
|
124
|
-
ctx.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
ctx.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
ctx.
|
|
172
|
-
ctx
|
|
173
|
-
ctx.
|
|
174
|
-
ctx.
|
|
175
|
-
ctx.
|
|
176
|
-
ctx.
|
|
177
|
-
ctx.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
ctx
|
|
182
|
-
ctx.
|
|
183
|
-
ctx.
|
|
184
|
-
ctx.
|
|
185
|
-
ctx.
|
|
186
|
-
ctx.
|
|
187
|
-
ctx.
|
|
188
|
-
ctx.
|
|
189
|
-
ctx.
|
|
190
|
-
ctx.
|
|
191
|
-
ctx.
|
|
192
|
-
ctx.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
ctx.
|
|
196
|
-
ctx
|
|
197
|
-
ctx.
|
|
198
|
-
ctx.
|
|
199
|
-
ctx.
|
|
200
|
-
ctx.
|
|
201
|
-
ctx.
|
|
202
|
-
ctx.
|
|
203
|
-
ctx.
|
|
204
|
-
|
|
205
|
-
ctx.
|
|
206
|
-
ctx.textAlign = '
|
|
207
|
-
ctx.
|
|
208
|
-
ctx.
|
|
209
|
-
|
|
210
|
-
ctx.
|
|
211
|
-
ctx.
|
|
212
|
-
ctx.
|
|
213
|
-
ctx.
|
|
214
|
-
ctx.
|
|
215
|
-
|
|
216
|
-
ctx.
|
|
217
|
-
|
|
218
|
-
ctx.
|
|
219
|
-
ctx.
|
|
220
|
-
|
|
221
|
-
ctx.
|
|
222
|
-
ctx.
|
|
223
|
-
ctx.
|
|
224
|
-
ctx.
|
|
225
|
-
ctx.
|
|
226
|
-
ctx.
|
|
227
|
-
ctx.
|
|
228
|
-
|
|
229
|
-
ctx.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
ctx.
|
|
233
|
-
ctx
|
|
234
|
-
ctx.
|
|
235
|
-
ctx.
|
|
236
|
-
ctx.
|
|
237
|
-
ctx.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
ctx.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
ctx.
|
|
246
|
-
ctx
|
|
247
|
-
ctx.
|
|
248
|
-
ctx.
|
|
249
|
-
ctx.
|
|
250
|
-
ctx.
|
|
251
|
-
|
|
252
|
-
ctx.
|
|
253
|
-
ctx.
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
ctx.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
ctx.
|
|
265
|
-
ctx.
|
|
266
|
-
ctx.
|
|
267
|
-
|
|
268
|
-
ctx.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
1
|
+
let Discord = require('discord.js')
|
|
2
|
+
const levels = require('../src/models/level.js')
|
|
3
|
+
const { join } = require('path')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Discord.Message} message
|
|
7
|
+
* @param {string} userID
|
|
8
|
+
* @param {string} guildID
|
|
9
|
+
* @param {import('../index').rankOptions} options
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
async function rank(message, userID, guildID, options = []) {
|
|
13
|
+
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
14
|
+
|
|
15
|
+
if (!guildID) throw new Error('[XP] Guild ID was not provided.')
|
|
16
|
+
|
|
17
|
+
const user = await levels.findOne({
|
|
18
|
+
user: userID,
|
|
19
|
+
guild: guildID
|
|
20
|
+
})
|
|
21
|
+
if (!user) throw new Error('[XP] NO_DATA | User has no XP data.')
|
|
22
|
+
|
|
23
|
+
const leaderboard = await levels
|
|
24
|
+
.find({
|
|
25
|
+
guild: guildID
|
|
26
|
+
})
|
|
27
|
+
.sort([['xp', 'descending']])
|
|
28
|
+
.exec()
|
|
29
|
+
|
|
30
|
+
user.position = leaderboard.findIndex((i) => i.user === userID) + 1
|
|
31
|
+
|
|
32
|
+
let targetxp = user.level + 1
|
|
33
|
+
|
|
34
|
+
let target = targetxp * targetxp * 100
|
|
35
|
+
|
|
36
|
+
return rankCard(message, {
|
|
37
|
+
level: user.level,
|
|
38
|
+
currentXP: user.xp,
|
|
39
|
+
neededXP: target,
|
|
40
|
+
rank: user.position,
|
|
41
|
+
background: options.background,
|
|
42
|
+
color: options.color,
|
|
43
|
+
lvlbar: options.lvlbar,
|
|
44
|
+
lvlbarBg: options.lvlbarBg,
|
|
45
|
+
member: message.guild.members.cache.get(userID)?.user
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
async function rankCard(message, options = []) {
|
|
49
|
+
try {
|
|
50
|
+
const Canvas = require('canvas')
|
|
51
|
+
const { registerFont } = require('canvas')
|
|
52
|
+
registerFont(join(__dirname, 'Fonts', 'Baloo-Regular.ttf'), {
|
|
53
|
+
family: 'Sans Serif'
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
function shortener(count) {
|
|
57
|
+
const COUNT_ABBRS = [
|
|
58
|
+
'',
|
|
59
|
+
'k',
|
|
60
|
+
'M',
|
|
61
|
+
'B',
|
|
62
|
+
'T',
|
|
63
|
+
'Q',
|
|
64
|
+
'Q+',
|
|
65
|
+
'S',
|
|
66
|
+
'S+',
|
|
67
|
+
'O',
|
|
68
|
+
'N',
|
|
69
|
+
'D',
|
|
70
|
+
'U'
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
const i =
|
|
74
|
+
0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
|
|
75
|
+
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
|
|
76
|
+
result += `${COUNT_ABBRS[i]}`
|
|
77
|
+
return result
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const member = options.member
|
|
81
|
+
|
|
82
|
+
const canvas = Canvas.createCanvas(1080, 400),
|
|
83
|
+
ctx = canvas.getContext('2d')
|
|
84
|
+
|
|
85
|
+
const name = member.tag
|
|
86
|
+
const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '')
|
|
87
|
+
|
|
88
|
+
let fsiz = '45px'
|
|
89
|
+
if (message.guild.name.length >= 23) {
|
|
90
|
+
fsiz = '38px'
|
|
91
|
+
}
|
|
92
|
+
if (message.guild.name.length >= 40) {
|
|
93
|
+
fsiz = '28px'
|
|
94
|
+
}
|
|
95
|
+
if (message.guild.name.length >= 63) {
|
|
96
|
+
fsiz = '22px'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let BackgroundRadius = '20',
|
|
100
|
+
BackGroundImg =
|
|
101
|
+
options.background ||
|
|
102
|
+
'https://pinebanana.files.wordpress.com/2011/04/rainbow.jpg',
|
|
103
|
+
AttachmentName = 'rank.png',
|
|
104
|
+
Username = noSymbols(name),
|
|
105
|
+
AvatarRoundRadius = '50',
|
|
106
|
+
DrawLayerColor = '#000000',
|
|
107
|
+
DrawLayerOpacity = '0.4',
|
|
108
|
+
BoxColor = options.color || '#096DD1',
|
|
109
|
+
LevelBarFill = options.lvlbar || '#ffffff',
|
|
110
|
+
LevelBarBackground = options.lvlbarBg || '#ffffff',
|
|
111
|
+
Rank = options.rank,
|
|
112
|
+
TextEXP = shortener(options.currentXP) + ' XP',
|
|
113
|
+
LvlText = `Level ${shortener(options.level)}`,
|
|
114
|
+
BarRadius = '20',
|
|
115
|
+
TextXpNeded = '{current}/{needed}',
|
|
116
|
+
CurrentXP = options.currentXP,
|
|
117
|
+
NeededXP = options.neededXP
|
|
118
|
+
|
|
119
|
+
ctx.beginPath()
|
|
120
|
+
ctx.moveTo(0 + Number(BackgroundRadius), 0)
|
|
121
|
+
ctx.lineTo(0 + 1080 - Number(BackgroundRadius), 0)
|
|
122
|
+
ctx.quadraticCurveTo(0 + 1080, 0, 0 + 1080, 0 + Number(BackgroundRadius))
|
|
123
|
+
ctx.lineTo(0 + 1080, 0 + 400 - Number(BackgroundRadius))
|
|
124
|
+
ctx.quadraticCurveTo(
|
|
125
|
+
0 + 1080,
|
|
126
|
+
0 + 400,
|
|
127
|
+
0 + 1080 - Number(BackgroundRadius),
|
|
128
|
+
0 + 400
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
ctx.lineTo(0 + Number(BackgroundRadius), 0 + 400)
|
|
132
|
+
ctx.quadraticCurveTo(0, 0 + 400, 0, 0 + 400 - Number(BackgroundRadius))
|
|
133
|
+
ctx.lineTo(0, 0 + Number(BackgroundRadius))
|
|
134
|
+
ctx.quadraticCurveTo(0, 0, 0 + Number(BackgroundRadius), 0)
|
|
135
|
+
ctx.closePath()
|
|
136
|
+
ctx.clip()
|
|
137
|
+
ctx.fillStyle = '#000000'
|
|
138
|
+
ctx.fillRect(0, 0, 1080, 400)
|
|
139
|
+
let background = await Canvas.loadImage(BackGroundImg)
|
|
140
|
+
ctx.globalAlpha = 0.7
|
|
141
|
+
ctx.drawImage(background, 0, 0, 1080, 400)
|
|
142
|
+
ctx.restore()
|
|
143
|
+
|
|
144
|
+
ctx.fillStyle = DrawLayerColor
|
|
145
|
+
ctx.globalAlpha = DrawLayerOpacity
|
|
146
|
+
ctx.fillRect(40, 0, 240, canvas.height)
|
|
147
|
+
ctx.globalAlpha = 1
|
|
148
|
+
|
|
149
|
+
function RoundedBox(ctx, x, y, width, height, radius) {
|
|
150
|
+
ctx.beginPath()
|
|
151
|
+
ctx.moveTo(x + radius, y)
|
|
152
|
+
ctx.lineTo(x + width - radius, y)
|
|
153
|
+
ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
|
|
154
|
+
ctx.lineTo(x + width, y + height - radius)
|
|
155
|
+
ctx.quadraticCurveTo(
|
|
156
|
+
x + width,
|
|
157
|
+
y + height,
|
|
158
|
+
x + width - radius,
|
|
159
|
+
y + height
|
|
160
|
+
)
|
|
161
|
+
ctx.lineTo(x + radius, y + height)
|
|
162
|
+
ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
|
|
163
|
+
ctx.lineTo(x, y + radius)
|
|
164
|
+
ctx.quadraticCurveTo(x, y, x + radius, y)
|
|
165
|
+
ctx.closePath()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let avatar = await Canvas.loadImage(
|
|
169
|
+
member.displayAvatarURL({ dynamic: true, format: 'png' })
|
|
170
|
+
)
|
|
171
|
+
ctx.save()
|
|
172
|
+
RoundedBox(ctx, 40 + 30, 30, 180, 180, Number(AvatarRoundRadius))
|
|
173
|
+
ctx.strokeStyle = BoxColor
|
|
174
|
+
ctx.lineWidth = '10'
|
|
175
|
+
ctx.stroke()
|
|
176
|
+
ctx.clip()
|
|
177
|
+
ctx.drawImage(avatar, 40 + 30, 30, 180, 180)
|
|
178
|
+
ctx.restore()
|
|
179
|
+
|
|
180
|
+
ctx.save()
|
|
181
|
+
RoundedBox(ctx, 40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50, 20)
|
|
182
|
+
ctx.strokeStyle = '#BFC85A22'
|
|
183
|
+
ctx.stroke()
|
|
184
|
+
ctx.clip()
|
|
185
|
+
ctx.fillStyle = BoxColor
|
|
186
|
+
ctx.globalAlpha = '1'
|
|
187
|
+
ctx.fillRect(40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50)
|
|
188
|
+
ctx.globalAlpha = 1
|
|
189
|
+
ctx.fillStyle = '#ffffff'
|
|
190
|
+
ctx.font = '32px "Sans Serif"'
|
|
191
|
+
ctx.textAlign = 'center'
|
|
192
|
+
ctx.fillText(TextEXP, 40 + 30 + 180 / 2, 30 + 180 + 30 + 30 + 50 + 38)
|
|
193
|
+
ctx.restore()
|
|
194
|
+
|
|
195
|
+
ctx.save()
|
|
196
|
+
RoundedBox(ctx, 40 + 30, 30 + 180 + 30, 180, 50, 20)
|
|
197
|
+
ctx.strokeStyle = '#BFC85A22'
|
|
198
|
+
ctx.stroke()
|
|
199
|
+
ctx.clip()
|
|
200
|
+
ctx.fillStyle = BoxColor
|
|
201
|
+
ctx.globalAlpha = '1'
|
|
202
|
+
ctx.fillRect(40 + 30, 30 + 180 + 30, 180, 50, 50)
|
|
203
|
+
ctx.globalAlpha = 1
|
|
204
|
+
ctx.fillStyle = '#ffffff'
|
|
205
|
+
ctx.font = '32px "Sans Serif"'
|
|
206
|
+
ctx.textAlign = 'center'
|
|
207
|
+
ctx.fillText(LvlText, 40 + 30 + 180 / 2, 30 + 180 + 30 + 38)
|
|
208
|
+
ctx.restore()
|
|
209
|
+
|
|
210
|
+
ctx.save()
|
|
211
|
+
ctx.textAlign = 'left'
|
|
212
|
+
ctx.fillStyle = '#ffffff'
|
|
213
|
+
ctx.shadowColor = '#000000'
|
|
214
|
+
ctx.shadowBlur = 15
|
|
215
|
+
ctx.shadowOffsetX = 1
|
|
216
|
+
ctx.shadowOffsetY = 1
|
|
217
|
+
ctx.font = '39px "Sans Serif"'
|
|
218
|
+
ctx.fillText(Username, 390, 80)
|
|
219
|
+
ctx.restore()
|
|
220
|
+
|
|
221
|
+
ctx.save()
|
|
222
|
+
ctx.textAlign = 'right'
|
|
223
|
+
ctx.fillStyle = '#ffffff'
|
|
224
|
+
ctx.shadowColor = '#000000'
|
|
225
|
+
ctx.shadowBlur = 15
|
|
226
|
+
ctx.shadowOffsetX = 1
|
|
227
|
+
ctx.shadowOffsetY = 1
|
|
228
|
+
ctx.font = '55px "Sans Serif"'
|
|
229
|
+
ctx.fillText('#' + Rank, canvas.width - 50 - 5, 80)
|
|
230
|
+
ctx.restore()
|
|
231
|
+
|
|
232
|
+
ctx.save()
|
|
233
|
+
RoundedBox(ctx, 390, 305, 660, 70, Number(20))
|
|
234
|
+
ctx.strokeStyle = '#BFC85A22'
|
|
235
|
+
ctx.stroke()
|
|
236
|
+
ctx.clip()
|
|
237
|
+
ctx.fillStyle = '#ffffff'
|
|
238
|
+
ctx.font = `${fsiz} "Sans Serif"`
|
|
239
|
+
ctx.textAlign = 'center'
|
|
240
|
+
ctx.fillText(message.guild.name, 60 + 660, 355)
|
|
241
|
+
ctx.globalAlpha = '0.2'
|
|
242
|
+
ctx.fillRect(390, 305, 660, 70)
|
|
243
|
+
ctx.restore()
|
|
244
|
+
|
|
245
|
+
ctx.save()
|
|
246
|
+
RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius))
|
|
247
|
+
ctx.strokeStyle = '#BFC85A22'
|
|
248
|
+
ctx.stroke()
|
|
249
|
+
ctx.clip()
|
|
250
|
+
ctx.fillStyle = LevelBarBackground
|
|
251
|
+
ctx.globalAlpha = '0.2'
|
|
252
|
+
ctx.fillRect(390, 145, 660, 50, 50)
|
|
253
|
+
ctx.restore()
|
|
254
|
+
|
|
255
|
+
const percent = (100 * CurrentXP) / NeededXP
|
|
256
|
+
const progress = (percent * 660) / 100
|
|
257
|
+
|
|
258
|
+
ctx.save()
|
|
259
|
+
RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius))
|
|
260
|
+
ctx.strokeStyle = '#BFC85A22'
|
|
261
|
+
ctx.stroke()
|
|
262
|
+
ctx.clip()
|
|
263
|
+
ctx.fillStyle = LevelBarFill
|
|
264
|
+
ctx.globalAlpha = '0.5'
|
|
265
|
+
ctx.fillRect(390, 145, progress, 50, 50)
|
|
266
|
+
ctx.restore()
|
|
267
|
+
|
|
268
|
+
ctx.save()
|
|
269
|
+
ctx.textAlign = 'left'
|
|
270
|
+
ctx.fillStyle = '#ffffff'
|
|
271
|
+
ctx.globalAlpha = '0.8'
|
|
272
|
+
ctx.font = '30px "Sans Serif"'
|
|
273
|
+
ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230)
|
|
274
|
+
ctx.restore()
|
|
275
|
+
|
|
276
|
+
const latestXP = Number(CurrentXP) - Number(NeededXP)
|
|
277
|
+
const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP))
|
|
278
|
+
.replace(/{current}/g, shortener(CurrentXP))
|
|
279
|
+
.replace(/{latest}/g, latestXP)
|
|
280
|
+
ctx.textAlign = 'center'
|
|
281
|
+
ctx.fillStyle = '#474747'
|
|
282
|
+
ctx.globalAlpha = 1
|
|
283
|
+
ctx.font = '30px "Sans Serif"'
|
|
284
|
+
ctx.fillText(textXPEdited, 730, 180)
|
|
285
|
+
|
|
286
|
+
const attachment = new Discord.MessageAttachment(
|
|
287
|
+
canvas.toBuffer(),
|
|
288
|
+
AttachmentName
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
return attachment
|
|
292
|
+
} catch (err) {
|
|
293
|
+
console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
module.exports = rank
|
package/src/reset.js
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} userID
|
|
5
|
-
* @param {string} guildID
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function reset(userID, guildID) {
|
|
9
|
-
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
10
|
-
|
|
11
|
-
if (!guildID) throw new Error('[XP] User ID was not provided.')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.catch((e) => console.log(`[XP] Failed to save new use to database`))
|
|
24
|
-
|
|
25
|
-
return true
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = reset
|
|
1
|
+
const levels = require('../src/models/level.js')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} userID
|
|
5
|
+
* @param {string} guildID
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function reset(userID, guildID) {
|
|
9
|
+
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
10
|
+
|
|
11
|
+
if (!guildID) throw new Error('[XP] User ID was not provided.')
|
|
12
|
+
|
|
13
|
+
await levels
|
|
14
|
+
.findOneAndUpdate({ user: userID, guild: guildID }, { xp: 0, level: 0 })
|
|
15
|
+
.catch((err) => {
|
|
16
|
+
throw new Error(err)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
return { user: userID, guild: guildID, xp: 0, level: 0 }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = reset
|