simply-xp 1.2.0-test-1 → 1.2.0-test-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simply-xp",
3
- "version": "1.2.0-test-1",
3
+ "version": "1.2.0-test-2",
4
4
  "description": "A Simple, Easy and Beginner Friendly XP System",
5
5
  "main": "simplyxp.js",
6
6
  "typings": "index.d.ts",
package/simplyxp.js CHANGED
@@ -1,31 +1,31 @@
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')
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) 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'), { family: 'Sans Serif' })
53
-
54
- function shortener(count) {
55
- const COUNT_ABBRS = ['', 'k', 'M', 'B', 'T', 'Q', 'Q+', 'S', 'S+', 'O', 'N', 'D', 'U']
56
-
57
- const i =
58
- 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
59
- let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
60
- result += `${COUNT_ABBRS[i]}`
61
- return result
62
- }
63
-
64
- const member = options.member
65
-
66
- const canvas = Canvas.createCanvas(1080, 400),
67
- ctx = canvas.getContext('2d')
68
-
69
- const name = member.tag
70
- const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '')
71
-
72
- let fsiz = '45px'
73
- if (message.guild.name.length >= 23) {
74
- fsiz = '38px'
75
- }
76
- if (message.guild.name.length >= 40) {
77
- fsiz = '28px'
78
- }
79
- if (message.guild.name.length >= 63) {
80
- fsiz = '22px'
81
- }
82
-
83
- let BackgroundRadius = '20',
84
- BackGroundImg =
85
- options.background ||
86
- 'https://pinebanana.files.wordpress.com/2011/04/rainbow.jpg',
87
- AttachmentName = 'rank.png',
88
- Username = noSymbols(name),
89
- AvatarRoundRadius = '50',
90
- DrawLayerColor = '#000000',
91
- DrawLayerOpacity = '0.4',
92
- BoxColor = options.color || '#096DD1',
93
- LevelBarFill = options.lvlbar || '#ffffff',
94
- LevelBarBackground = options.lvlbarBg || '#ffffff',
95
- Rank = options.rank,
96
- TextEXP = shortener(options.currentXP) + ' XP',
97
- LvlText = `Level ${shortener(options.level)}`,
98
- BarRadius = '20',
99
- TextXpNeded = '{current}/{needed}',
100
- CurrentXP = options.currentXP,
101
- NeededXP = options.neededXP
102
-
103
- ctx.beginPath()
104
- ctx.moveTo(0 + Number(BackgroundRadius), 0)
105
- ctx.lineTo(0 + 1080 - Number(BackgroundRadius), 0)
106
- ctx.quadraticCurveTo(0 + 1080, 0, 0 + 1080, 0 + Number(BackgroundRadius))
107
- ctx.lineTo(0 + 1080, 0 + 400 - Number(BackgroundRadius))
108
- ctx.quadraticCurveTo(
109
- 0 + 1080,
110
- 0 + 400,
111
- 0 + 1080 - Number(BackgroundRadius),
112
- 0 + 400
113
- )
114
-
115
- ctx.lineTo(0 + Number(BackgroundRadius), 0 + 400)
116
- ctx.quadraticCurveTo(0, 0 + 400, 0, 0 + 400 - Number(BackgroundRadius))
117
- ctx.lineTo(0, 0 + Number(BackgroundRadius))
118
- ctx.quadraticCurveTo(0, 0, 0 + Number(BackgroundRadius), 0)
119
- ctx.closePath()
120
- ctx.clip()
121
- ctx.fillStyle = '#000000'
122
- ctx.fillRect(0, 0, 1080, 400)
123
- let background = await Canvas.loadImage(BackGroundImg)
124
- ctx.globalAlpha = 0.7
125
- ctx.drawImage(background, 0, 0, 1080, 400)
126
- ctx.restore()
127
-
128
- ctx.fillStyle = DrawLayerColor
129
- ctx.globalAlpha = DrawLayerOpacity
130
- ctx.fillRect(40, 0, 240, canvas.height)
131
- ctx.globalAlpha = 1
132
-
133
- function RoundedBox(ctx, x, y, width, height, radius) {
134
- ctx.beginPath()
135
- ctx.moveTo(x + radius, y)
136
- ctx.lineTo(x + width - radius, y)
137
- ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
138
- ctx.lineTo(x + width, y + height - radius)
139
- ctx.quadraticCurveTo(
140
- x + width,
141
- y + height,
142
- x + width - radius,
143
- y + height
144
- )
145
- ctx.lineTo(x + radius, y + height)
146
- ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
147
- ctx.lineTo(x, y + radius)
148
- ctx.quadraticCurveTo(x, y, x + radius, y)
149
- ctx.closePath()
150
- }
151
-
152
- let avatar = await Canvas.loadImage(
153
- member.displayAvatarURL({ dynamic: true, format: 'png' })
154
- )
155
- ctx.save()
156
- RoundedBox(ctx, 40 + 30, 30, 180, 180, Number(AvatarRoundRadius))
157
- ctx.strokeStyle = BoxColor
158
- ctx.lineWidth = '10'
159
- ctx.stroke()
160
- ctx.clip()
161
- ctx.drawImage(avatar, 40 + 30, 30, 180, 180)
162
- ctx.restore()
163
-
164
- ctx.save()
165
- RoundedBox(ctx, 40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50, 20)
166
- ctx.strokeStyle = '#BFC85A22'
167
- ctx.stroke()
168
- ctx.clip()
169
- ctx.fillStyle = BoxColor
170
- ctx.globalAlpha = '1'
171
- ctx.fillRect(40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50)
172
- ctx.globalAlpha = 1
173
- ctx.fillStyle = '#ffffff'
174
- ctx.font = '32px "Sans Serif"'
175
- ctx.textAlign = 'center'
176
- ctx.fillText(TextEXP, 40 + 30 + 180 / 2, 30 + 180 + 30 + 30 + 50 + 38)
177
- ctx.restore()
178
-
179
- ctx.save()
180
- RoundedBox(ctx, 40 + 30, 30 + 180 + 30, 180, 50, 20)
181
- ctx.strokeStyle = '#BFC85A22'
182
- ctx.stroke()
183
- ctx.clip()
184
- ctx.fillStyle = BoxColor
185
- ctx.globalAlpha = '1'
186
- ctx.fillRect(40 + 30, 30 + 180 + 30, 180, 50, 50)
187
- ctx.globalAlpha = 1
188
- ctx.fillStyle = '#ffffff'
189
- ctx.font = '32px "Sans Serif"'
190
- ctx.textAlign = 'center'
191
- ctx.fillText(LvlText, 40 + 30 + 180 / 2, 30 + 180 + 30 + 38)
192
- ctx.restore()
193
-
194
- ctx.save()
195
- ctx.textAlign = 'left'
196
- ctx.fillStyle = '#ffffff'
197
- ctx.shadowColor = '#000000'
198
- ctx.shadowBlur = 15
199
- ctx.shadowOffsetX = 1
200
- ctx.shadowOffsetY = 1
201
- ctx.font = '39px "Sans Serif"'
202
- ctx.fillText(Username, 390, 80)
203
- ctx.restore()
204
-
205
- ctx.save()
206
- ctx.textAlign = 'right'
207
- ctx.fillStyle = '#ffffff'
208
- ctx.shadowColor = '#000000'
209
- ctx.shadowBlur = 15
210
- ctx.shadowOffsetX = 1
211
- ctx.shadowOffsetY = 1
212
- ctx.font = '55px "Sans Serif"'
213
- ctx.fillText('#' + Rank, canvas.width - 50 - 5, 80)
214
- ctx.restore()
215
-
216
- ctx.save()
217
- RoundedBox(ctx, 390, 305, 660, 70, Number(20))
218
- ctx.strokeStyle = '#BFC85A22'
219
- ctx.stroke()
220
- ctx.clip()
221
- ctx.fillStyle = '#ffffff'
222
- ctx.font = `${fsiz} "Sans Serif"`
223
- ctx.textAlign = 'center'
224
- ctx.fillText(message.guild.name, 60 + 660, 355)
225
- ctx.globalAlpha = '0.2'
226
- ctx.fillRect(390, 305, 660, 70)
227
- ctx.restore()
228
-
229
- ctx.save()
230
- RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius))
231
- ctx.strokeStyle = '#BFC85A22'
232
- ctx.stroke()
233
- ctx.clip()
234
- ctx.fillStyle = LevelBarBackground
235
- ctx.globalAlpha = '0.2'
236
- ctx.fillRect(390, 145, 660, 50, 50)
237
- ctx.restore()
238
-
239
- const percent = (100 * CurrentXP) / NeededXP
240
- const progress = (percent * 660) / 100
241
-
242
- ctx.save()
243
- RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius))
244
- ctx.strokeStyle = '#BFC85A22'
245
- ctx.stroke()
246
- ctx.clip()
247
- ctx.fillStyle = LevelBarFill
248
- ctx.globalAlpha = '0.5'
249
- ctx.fillRect(390, 145, progress, 50, 50)
250
- ctx.restore()
251
-
252
- ctx.save()
253
- ctx.textAlign = 'left'
254
- ctx.fillStyle = '#ffffff'
255
- ctx.globalAlpha = '0.8'
256
- ctx.font = '30px "Sans Serif"'
257
- ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230)
258
- ctx.restore()
259
-
260
- const latestXP = Number(CurrentXP) - Number(NeededXP)
261
- const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP))
262
- .replace(/{current}/g, shortener(CurrentXP))
263
- .replace(/{latest}/g, latestXP)
264
- ctx.textAlign = 'center'
265
- ctx.fillStyle = '#474747'
266
- ctx.globalAlpha = 1
267
- ctx.font = '30px "Sans Serif"'
268
- ctx.fillText(textXPEdited, 730, 180)
269
-
270
- const attachment = new Discord.MessageAttachment(
271
- canvas.toBuffer(),
272
- AttachmentName
273
- )
274
-
275
- return attachment
276
- } catch (err) {
277
- console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
278
- }
279
- }
280
- }
281
-
282
- module.exports = rank
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,22 +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
- 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
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