simply-xp 1.1.5-beta → 1.1.7

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