simply-xp 1.3.3 → 1.3.5-beta-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.
package/src/rank.js CHANGED
@@ -1,296 +1,296 @@
1
- const levels = require('../src/models/level.js')
2
- const { join } = require('path')
3
-
4
- /**
5
- * @param {Discord.Message} message
6
- * @param {string} userID
7
- * @param {string} guildID
8
- * @param {import('../index').rankOptions} options
9
- */
10
-
11
- async function rank(message, userID, guildID, options = []) {
12
- if (!userID) throw new Error('[XP] User ID was not provided.')
13
-
14
- if (!guildID) throw new Error('[XP] Guild ID was not provided.')
15
-
16
- const user = await levels.findOne({
17
- user: userID,
18
- guild: guildID
19
- })
20
- if (!user) throw new Error('[XP] NO_DATA | User has no XP data.')
21
-
22
- const leaderboard = await levels
23
- .find({
24
- guild: guildID
25
- })
26
- .sort([['xp', 'descending']])
27
- .exec()
28
-
29
- user.position = leaderboard.findIndex((i) => i.user === userID) + 1
30
-
31
- let targetxp = user.level + 1
32
-
33
- let target = targetxp * targetxp * 100
34
-
35
- return rankCard(message, {
36
- level: user.level,
37
- currentXP: user.xp,
38
- neededXP: target,
39
- rank: user.position,
40
- background: options.background,
41
- color: options.color,
42
- lvlbar: options.lvlbar,
43
- lvlbarBg: options.lvlbarBg,
44
- member: message.guild.members.cache.get(userID)?.user
45
- })
46
-
47
- async function rankCard(message, options = []) {
48
- try {
49
- const Canvas = require('@napi-rs/canvas')
50
- Canvas.GlobalFonts.registerFromPath(
51
- join(__dirname, 'Fonts', 'Baloo-Regular.ttf'),
52
- 'Sans Serif'
53
- )
54
-
55
- function shortener(count) {
56
- const COUNT_ABBRS = [
57
- '',
58
- 'k',
59
- 'M',
60
- 'B',
61
- 'T',
62
- 'Q',
63
- 'Q+',
64
- 'S',
65
- 'S+',
66
- 'O',
67
- 'N',
68
- 'D',
69
- 'U'
70
- ]
71
-
72
- const i =
73
- 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
74
- let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
75
- result += `${COUNT_ABBRS[i]}`
76
- return result
77
- }
78
-
79
- const member = options.member
80
-
81
- const canvas = Canvas.createCanvas(1080, 400),
82
- ctx = canvas.getContext('2d')
83
-
84
- const name = member.tag
85
- const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '')
86
-
87
- let fsiz = '45px'
88
- if (message.guild.name.length >= 23) {
89
- fsiz = '38px'
90
- }
91
- if (message.guild.name.length >= 40) {
92
- fsiz = '28px'
93
- }
94
- if (message.guild.name.length >= 63) {
95
- fsiz = '22px'
96
- }
97
-
98
- let BackgroundRadius = '20',
99
- BackGroundImg =
100
- options.background ||
101
- 'https://pinebanana.files.wordpress.com/2011/04/rainbow.jpg',
102
- AttachmentName = 'rank.png',
103
- AttachmentDesc = 'Rank Card',
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(member.displayAvatarURL())
169
- ctx.save()
170
- RoundedBox(ctx, 40 + 30, 30, 180, 180, Number(AvatarRoundRadius))
171
- ctx.strokeStyle = BoxColor
172
- ctx.lineWidth = 10
173
- ctx.stroke()
174
- ctx.clip()
175
- ctx.drawImage(avatar, 40 + 30, 30, 180, 180)
176
- ctx.restore()
177
-
178
- ctx.save()
179
- RoundedBox(ctx, 40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50, 20)
180
- ctx.strokeStyle = '#BFC85A22'
181
- ctx.stroke()
182
- ctx.clip()
183
- ctx.fillStyle = BoxColor
184
- ctx.globalAlpha = 1
185
- ctx.fillRect(40 + 30, 30 + 180 + 30 + 50 + 30, 180, 50)
186
- ctx.globalAlpha = 1
187
- ctx.fillStyle = '#ffffff'
188
- ctx.font = '32px "Sans Serif"'
189
- ctx.textAlign = 'center'
190
- ctx.fillText(TextEXP, 40 + 30 + 180 / 2, 30 + 180 + 30 + 30 + 50 + 38)
191
- ctx.restore()
192
-
193
- ctx.save()
194
- RoundedBox(ctx, 40 + 30, 30 + 180 + 30, 180, 50, 20)
195
- ctx.strokeStyle = '#BFC85A22'
196
- ctx.stroke()
197
- ctx.clip()
198
- ctx.fillStyle = BoxColor
199
- ctx.globalAlpha = 1
200
- ctx.fillRect(40 + 30, 30 + 180 + 30, 180, 50, 50)
201
- ctx.globalAlpha = 1
202
- ctx.fillStyle = '#ffffff'
203
- ctx.font = '32px "Sans Serif"'
204
- ctx.textAlign = 'center'
205
- ctx.fillText(LvlText, 40 + 30 + 180 / 2, 30 + 180 + 30 + 38)
206
- ctx.restore()
207
-
208
- ctx.save()
209
- ctx.textAlign = 'left'
210
- ctx.fillStyle = '#ffffff'
211
- ctx.shadowColor = '#000000'
212
- ctx.shadowBlur = 15
213
- ctx.shadowOffsetX = 1
214
- ctx.shadowOffsetY = 1
215
- ctx.font = '39px "Sans Serif"'
216
- ctx.fillText(Username, 390, 80)
217
- ctx.restore()
218
-
219
- ctx.save()
220
- ctx.textAlign = 'right'
221
- ctx.fillStyle = '#ffffff'
222
- ctx.shadowColor = '#000000'
223
- ctx.shadowBlur = 15
224
- ctx.shadowOffsetX = 1
225
- ctx.shadowOffsetY = 1
226
- ctx.font = '55px "Sans Serif"'
227
- ctx.fillText('#' + Rank, canvas.width - 50 - 5, 80)
228
- ctx.restore()
229
-
230
- ctx.save()
231
- RoundedBox(ctx, 390, 305, 660, 70, Number(20))
232
- ctx.strokeStyle = '#BFC85A22'
233
- ctx.stroke()
234
- ctx.clip()
235
- ctx.fillStyle = '#ffffff'
236
- ctx.font = `${fsiz} "Sans Serif"`
237
- ctx.textAlign = 'center'
238
- ctx.fillText(message.guild.name, 60 + 660, 355)
239
- ctx.globalAlpha = 0.2
240
- ctx.fillRect(390, 305, 660, 70)
241
- ctx.restore()
242
-
243
- ctx.save()
244
- RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius))
245
- ctx.strokeStyle = '#BFC85A22'
246
- ctx.stroke()
247
- ctx.clip()
248
- ctx.fillStyle = LevelBarBackground
249
- ctx.globalAlpha = 0.2
250
- ctx.fillRect(390, 145, 660, 50, 50)
251
- ctx.restore()
252
-
253
- const percent = (100 * CurrentXP) / NeededXP
254
- const progress = (percent * 660) / 100
255
-
256
- ctx.save()
257
- RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius))
258
- ctx.strokeStyle = '#BFC85A22'
259
- ctx.stroke()
260
- ctx.clip()
261
- ctx.fillStyle = LevelBarFill
262
- ctx.globalAlpha = 0.5
263
- ctx.fillRect(390, 145, progress, 50, 50)
264
- ctx.restore()
265
-
266
- ctx.save()
267
- ctx.textAlign = 'left'
268
- ctx.fillStyle = '#ffffff'
269
- ctx.globalAlpha = 0.8
270
- ctx.font = '30px "Sans Serif"'
271
- ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230)
272
- ctx.restore()
273
-
274
- const latestXP = Number(CurrentXP) - Number(NeededXP)
275
- const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP))
276
- .replace(/{current}/g, shortener(CurrentXP))
277
- .replace(/{latest}/g, latestXP)
278
- ctx.textAlign = 'center'
279
- ctx.fillStyle = '#474747'
280
- ctx.globalAlpha = 1
281
- ctx.font = '30px "Sans Serif"'
282
- ctx.fillText(textXPEdited, 730, 180)
283
-
284
- const attachment = {
285
- attachment: canvas.toBuffer(),
286
- description: AttachmentDesc,
287
- name: AttachmentName
288
- }
289
- return attachment
290
- } catch (err) {
291
- console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
292
- }
293
- }
294
- }
295
-
296
- module.exports = rank
1
+ const levels = require('../src/models/level.js')
2
+ const { join } = require('path')
3
+
4
+ /**
5
+ * @param {Discord.Message} message
6
+ * @param {string} userID
7
+ * @param {string} guildID
8
+ * @param {import('../index').rankOptions} options
9
+ */
10
+
11
+ async function rank(message, userID, guildID, options = []) {
12
+ if (!userID) throw new Error('[XP] User ID was not provided.')
13
+
14
+ if (!guildID) throw new Error('[XP] Guild ID was not provided.')
15
+
16
+ const user = await levels.findOne({
17
+ user: userID,
18
+ guild: guildID
19
+ })
20
+ if (!user) throw new Error('[XP] NO_DATA | User has no XP data.')
21
+
22
+ const leaderboard = await levels
23
+ .find({
24
+ guild: guildID
25
+ })
26
+ .sort([['xp', 'descending']])
27
+ .exec()
28
+
29
+ user.position = leaderboard.findIndex((i) => i.user === userID) + 1
30
+
31
+ let targetxp = user.level + 1
32
+
33
+ let target = targetxp * targetxp * 100
34
+
35
+ return rankCard(message, {
36
+ level: user.level,
37
+ currentXP: user.xp,
38
+ neededXP: target,
39
+ rank: user.position,
40
+ background: options.background,
41
+ color: options.color,
42
+ lvlbar: options.lvlbar,
43
+ lvlbarBg: options.lvlbarBg,
44
+ member: message.guild.members.cache.get(userID)?.user
45
+ })
46
+
47
+ async function rankCard(message, options = []) {
48
+ try {
49
+ const Canvas = require('@napi-rs/canvas')
50
+ Canvas.GlobalFonts.registerFromPath(
51
+ join(__dirname, 'Fonts', 'Baloo-Regular.ttf'),
52
+ 'Sans Serif'
53
+ )
54
+
55
+ function shortener(count) {
56
+ const COUNT_ABBRS = [
57
+ '',
58
+ 'k',
59
+ 'M',
60
+ 'B',
61
+ 'T',
62
+ 'Q',
63
+ 'Q+',
64
+ 'S',
65
+ 'S+',
66
+ 'O',
67
+ 'N',
68
+ 'D',
69
+ 'U'
70
+ ]
71
+
72
+ const i =
73
+ 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
74
+ let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
75
+ result += `${COUNT_ABBRS[i]}`
76
+ return result
77
+ }
78
+
79
+ const member = options.member
80
+
81
+ const canvas = Canvas.createCanvas(1080, 400),
82
+ ctx = canvas.getContext('2d')
83
+
84
+ const name = member.tag
85
+ const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '')
86
+
87
+ let fsiz = '45px'
88
+ if (message.guild.name.length >= 23) {
89
+ fsiz = '38px'
90
+ }
91
+ if (message.guild.name.length >= 40) {
92
+ fsiz = '28px'
93
+ }
94
+ if (message.guild.name.length >= 63) {
95
+ fsiz = '22px'
96
+ }
97
+
98
+ let BackgroundRadius = '20',
99
+ BackGroundImg =
100
+ options.background ||
101
+ 'https://i.ibb.co/QQvMqf7/gradient.jpg',
102
+ AttachmentName = 'rank.png',
103
+ AttachmentDesc = 'Rank Card',
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(member.displayAvatarURL())
169
+ ctx.save()
170
+ RoundedBox(ctx, 70, 30, 180, 180, Number(AvatarRoundRadius))
171
+ ctx.strokeStyle = BoxColor
172
+ ctx.lineWidth = 15
173
+ ctx.stroke()
174
+ ctx.clip()
175
+ ctx.drawImage(avatar, 70, 30, 180, 180)
176
+ ctx.restore()
177
+
178
+ ctx.save()
179
+ RoundedBox(ctx, 70, 240 + 50 + 30, 180, 50, 20)
180
+ ctx.strokeStyle = '#BFC85A22'
181
+ ctx.stroke()
182
+ ctx.clip()
183
+ ctx.fillStyle = BoxColor
184
+ ctx.globalAlpha = 1
185
+ ctx.fillRect(70, 320, 180, 50)
186
+ ctx.globalAlpha = 1
187
+ ctx.fillStyle = '#ffffff'
188
+ ctx.font = '32px "Sans Serif"'
189
+ ctx.textAlign = 'center'
190
+ ctx.fillText(TextEXP, 160, 358)
191
+ ctx.restore()
192
+
193
+ ctx.save()
194
+ RoundedBox(ctx, 70, 240, 180, 50, 20)
195
+ ctx.strokeStyle = '#BFC85A22'
196
+ ctx.stroke()
197
+ ctx.clip()
198
+ ctx.fillStyle = BoxColor
199
+ ctx.globalAlpha = 1
200
+ ctx.fillRect(70, 240, 180, 50, 50)
201
+ ctx.globalAlpha = 1
202
+ ctx.fillStyle = '#ffffff'
203
+ ctx.font = '32px "Sans Serif"'
204
+ ctx.textAlign = 'center'
205
+ ctx.fillText(LvlText, 70 + 180 / 2, 278)
206
+ ctx.restore()
207
+
208
+ ctx.save()
209
+ ctx.textAlign = 'left'
210
+ ctx.fillStyle = '#ffffff'
211
+ ctx.shadowColor = '#000000'
212
+ ctx.shadowBlur = 15
213
+ ctx.shadowOffsetX = 1
214
+ ctx.shadowOffsetY = 1
215
+ ctx.font = '39px "Sans Serif"'
216
+ ctx.fillText(Username, 390, 80)
217
+ ctx.restore()
218
+
219
+ ctx.save()
220
+ ctx.textAlign = 'right'
221
+ ctx.fillStyle = '#ffffff'
222
+ ctx.shadowColor = '#000000'
223
+ ctx.shadowBlur = 15
224
+ ctx.shadowOffsetX = 1
225
+ ctx.shadowOffsetY = 1
226
+ ctx.font = '55px "Sans Serif"'
227
+ ctx.fillText('#' + Rank, canvas.width - 55, 80)
228
+ ctx.restore()
229
+
230
+ ctx.save()
231
+ RoundedBox(ctx, 390, 305, 660, 70, Number(20))
232
+ ctx.strokeStyle = '#BFC85A22'
233
+ ctx.stroke()
234
+ ctx.clip()
235
+ ctx.fillStyle = '#ffffff'
236
+ ctx.font = `${fsiz} "Sans Serif"`
237
+ ctx.textAlign = 'center'
238
+ ctx.fillText(message.guild.name, 720, 355)
239
+ ctx.globalAlpha = 0.2
240
+ ctx.fillRect(390, 305, 660, 70)
241
+ ctx.restore()
242
+
243
+ ctx.save()
244
+ RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius))
245
+ ctx.strokeStyle = '#BFC85A22'
246
+ ctx.stroke()
247
+ ctx.clip()
248
+ ctx.fillStyle = LevelBarBackground
249
+ ctx.globalAlpha = 0.2
250
+ ctx.fillRect(390, 145, 660, 50, 50)
251
+ ctx.restore()
252
+
253
+ const percent = (100 * CurrentXP) / NeededXP
254
+ const progress = (percent * 660) / 100
255
+
256
+ ctx.save()
257
+ RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius))
258
+ ctx.strokeStyle = '#BFC85A22'
259
+ ctx.stroke()
260
+ ctx.clip()
261
+ ctx.fillStyle = LevelBarFill
262
+ ctx.globalAlpha = 0.5
263
+ ctx.fillRect(390, 145, progress, 50, 50)
264
+ ctx.restore()
265
+
266
+ ctx.save()
267
+ ctx.textAlign = 'left'
268
+ ctx.fillStyle = '#ffffff'
269
+ ctx.globalAlpha = 0.8
270
+ ctx.font = '30px "Sans Serif"'
271
+ ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230)
272
+ ctx.restore()
273
+
274
+ const latestXP = Number(CurrentXP) - Number(NeededXP)
275
+ const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP))
276
+ .replace(/{current}/g, shortener(CurrentXP))
277
+ .replace(/{latest}/g, latestXP)
278
+ ctx.textAlign = 'center'
279
+ ctx.fillStyle = '#474747'
280
+ ctx.globalAlpha = 1
281
+ ctx.font = '30px "Sans Serif"'
282
+ ctx.fillText(textXPEdited, 730, 180)
283
+
284
+ const attachment = {
285
+ attachment: canvas.toBuffer('image/webp'),
286
+ description: AttachmentDesc,
287
+ name: AttachmentName
288
+ }
289
+ return attachment
290
+ } catch (err) {
291
+ console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
292
+ }
293
+ }
294
+ }
295
+
296
+ 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