simply-xp 1.3.5-beta-6 → 2.0.0-dev.0-fix.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/FUNDING.yml +2 -2
- package/README.md +68 -57
- package/lib/src/add.d.ts +35 -0
- package/lib/src/add.js +21 -0
- package/lib/src/cards.d.ts +86 -0
- package/lib/src/cards.js +23 -0
- package/lib/src/charts.d.ts +17 -0
- package/lib/src/charts.js +10 -0
- package/lib/src/connect.d.ts +17 -0
- package/lib/src/connect.js +40 -0
- package/lib/src/create.d.ts +11 -0
- package/lib/src/create.js +11 -0
- package/lib/src/deprecated/rank.d.ts +18 -0
- package/lib/src/deprecated/rank.js +12 -0
- package/lib/src/fetch.d.ts +17 -0
- package/lib/src/fetch.js +10 -0
- package/lib/src/functions/convert.d.ts +10 -0
- package/lib/src/functions/convert.js +10 -0
- package/lib/src/functions/database.d.ts +90 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +18 -0
- package/lib/src/leaderboard.js +10 -0
- package/lib/src/migrate.d.ts +25 -0
- package/lib/src/migrate.js +19 -0
- package/lib/src/reset.d.ts +11 -0
- package/lib/src/reset.js +11 -0
- package/lib/src/roleSetup.d.ts +41 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +32 -0
- package/lib/src/set.js +21 -0
- package/lib/xp.d.ts +24 -0
- package/lib/xp.js +44 -0
- package/package.json +70 -50
- package/.github/CODE_OF_CONDUCT.md +0 -128
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/SECURITY.md +0 -25
- package/.github/pull_request_template.md +0 -8
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.idea/discord.xml +0 -7
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/simply-xp.iml +0 -9
- package/.idea/workspace.xml +0 -55
- package/index.d.ts +0 -107
- package/simplyxp.js +0 -31
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -103
- package/src/charts.js +0 -92
- package/src/connect.js +0 -22
- package/src/create.js +0 -28
- package/src/fetch.js +0 -74
- package/src/leaderboard.js +0 -52
- package/src/lvlRole.js +0 -53
- package/src/models/level.js +0 -10
- package/src/models/lvlrole.js +0 -8
- package/src/rank.js +0 -294
- package/src/reset.js +0 -22
- package/src/roleSetup.js +0 -121
- package/src/setLevel.js +0 -70
- package/src/setXP.js +0 -51
- /package/{src → lib/src}/Fonts/Baloo-Regular.ttf +0 -0
package/src/rank.js
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
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 = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
|
|
73
|
-
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
|
|
74
|
-
result += `${COUNT_ABBRS[i]}`
|
|
75
|
-
return result
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const member = options.member
|
|
79
|
-
|
|
80
|
-
const canvas = Canvas.createCanvas(1080, 400),
|
|
81
|
-
ctx = canvas.getContext('2d')
|
|
82
|
-
|
|
83
|
-
const name = member.tag
|
|
84
|
-
const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '')
|
|
85
|
-
|
|
86
|
-
let fsiz = '45px'
|
|
87
|
-
if (message.guild.name.length >= 23) {
|
|
88
|
-
fsiz = '38px'
|
|
89
|
-
}
|
|
90
|
-
if (message.guild.name.length >= 40) {
|
|
91
|
-
fsiz = '28px'
|
|
92
|
-
}
|
|
93
|
-
if (message.guild.name.length >= 63) {
|
|
94
|
-
fsiz = '22px'
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
let BackgroundRadius = '20',
|
|
98
|
-
BackGroundImg =
|
|
99
|
-
options.background ||
|
|
100
|
-
'https://i.ibb.co/QQvMqf7/gradient.jpg',
|
|
101
|
-
AttachmentName = 'rank.png',
|
|
102
|
-
AttachmentDesc = 'Rank Card',
|
|
103
|
-
Username = noSymbols(name),
|
|
104
|
-
AvatarRoundRadius = '50',
|
|
105
|
-
DrawLayerColor = '#000000',
|
|
106
|
-
DrawLayerOpacity = 0.4,
|
|
107
|
-
BoxColor = options.color || '#096DD1',
|
|
108
|
-
LevelBarFill = options.lvlbar || '#ffffff',
|
|
109
|
-
LevelBarBackground = options.lvlbarBg || '#ffffff',
|
|
110
|
-
Rank = options.rank,
|
|
111
|
-
TextEXP = shortener(options.currentXP) + ' XP',
|
|
112
|
-
LvlText = `Level ${shortener(options.level)}`,
|
|
113
|
-
BarRadius = '20',
|
|
114
|
-
TextXpNeded = '{current}/{needed}',
|
|
115
|
-
CurrentXP = options.currentXP,
|
|
116
|
-
NeededXP = options.neededXP
|
|
117
|
-
|
|
118
|
-
ctx.beginPath()
|
|
119
|
-
ctx.moveTo(Number(BackgroundRadius), 0)
|
|
120
|
-
ctx.lineTo(1080 - Number(BackgroundRadius), 0)
|
|
121
|
-
ctx.quadraticCurveTo(1080, 0, 1080, Number(BackgroundRadius))
|
|
122
|
-
ctx.lineTo(1080, 400 - Number(BackgroundRadius))
|
|
123
|
-
ctx.quadraticCurveTo(
|
|
124
|
-
1080,
|
|
125
|
-
400,
|
|
126
|
-
1080 - Number(BackgroundRadius),
|
|
127
|
-
400
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
ctx.lineTo(Number(BackgroundRadius), 400)
|
|
131
|
-
ctx.quadraticCurveTo(0, 400, 0, 400 - Number(BackgroundRadius))
|
|
132
|
-
ctx.lineTo(0, Number(BackgroundRadius))
|
|
133
|
-
ctx.quadraticCurveTo(0, 0, Number(BackgroundRadius), 0)
|
|
134
|
-
ctx.closePath()
|
|
135
|
-
ctx.clip()
|
|
136
|
-
ctx.fillStyle = '#000000'
|
|
137
|
-
ctx.fillRect(0, 0, 1080, 400)
|
|
138
|
-
let background = await Canvas.loadImage(BackGroundImg)
|
|
139
|
-
ctx.globalAlpha = 0.7
|
|
140
|
-
ctx.drawImage(background, 0, 0, 1080, 400)
|
|
141
|
-
ctx.restore()
|
|
142
|
-
|
|
143
|
-
ctx.fillStyle = DrawLayerColor
|
|
144
|
-
ctx.globalAlpha = DrawLayerOpacity
|
|
145
|
-
ctx.fillRect(40, 0, 240, canvas.height)
|
|
146
|
-
ctx.globalAlpha = 1
|
|
147
|
-
|
|
148
|
-
function RoundedBox(ctx, x, y, width, height, radius) {
|
|
149
|
-
ctx.beginPath()
|
|
150
|
-
ctx.moveTo(x + radius, y)
|
|
151
|
-
ctx.lineTo(x + width - radius, y)
|
|
152
|
-
ctx.quadraticCurveTo(x + width, y, x + width, y + radius)
|
|
153
|
-
ctx.lineTo(x + width, y + height - radius)
|
|
154
|
-
ctx.quadraticCurveTo(
|
|
155
|
-
x + width,
|
|
156
|
-
y + height,
|
|
157
|
-
x + width - radius,
|
|
158
|
-
y + height
|
|
159
|
-
)
|
|
160
|
-
ctx.lineTo(x + radius, y + height)
|
|
161
|
-
ctx.quadraticCurveTo(x, y + height, x, y + height - radius)
|
|
162
|
-
ctx.lineTo(x, y + radius)
|
|
163
|
-
ctx.quadraticCurveTo(x, y, x + radius, y)
|
|
164
|
-
ctx.closePath()
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
let avatar = await Canvas.loadImage(member.displayAvatarURL())
|
|
168
|
-
ctx.save()
|
|
169
|
-
RoundedBox(ctx, 70, 30, 180, 180, Number(AvatarRoundRadius))
|
|
170
|
-
ctx.strokeStyle = BoxColor
|
|
171
|
-
ctx.lineWidth = 15
|
|
172
|
-
ctx.stroke()
|
|
173
|
-
ctx.clip()
|
|
174
|
-
ctx.drawImage(avatar, 70, 30, 180, 180)
|
|
175
|
-
ctx.restore()
|
|
176
|
-
|
|
177
|
-
ctx.save()
|
|
178
|
-
RoundedBox(ctx, 70, 240 + 50 + 30, 180, 50, 20)
|
|
179
|
-
ctx.strokeStyle = '#BFC85A22'
|
|
180
|
-
ctx.stroke()
|
|
181
|
-
ctx.clip()
|
|
182
|
-
ctx.fillStyle = BoxColor
|
|
183
|
-
ctx.globalAlpha = 1
|
|
184
|
-
ctx.fillRect(70, 320, 180, 50)
|
|
185
|
-
ctx.globalAlpha = 1
|
|
186
|
-
ctx.fillStyle = '#ffffff'
|
|
187
|
-
ctx.font = '32px "Sans Serif"'
|
|
188
|
-
ctx.textAlign = 'center'
|
|
189
|
-
ctx.fillText(TextEXP, 160, 358)
|
|
190
|
-
ctx.restore()
|
|
191
|
-
|
|
192
|
-
ctx.save()
|
|
193
|
-
RoundedBox(ctx, 70, 240, 180, 50, 20)
|
|
194
|
-
ctx.strokeStyle = '#BFC85A22'
|
|
195
|
-
ctx.stroke()
|
|
196
|
-
ctx.clip()
|
|
197
|
-
ctx.fillStyle = BoxColor
|
|
198
|
-
ctx.globalAlpha = 1
|
|
199
|
-
ctx.fillRect(70, 240, 180, 50, 50)
|
|
200
|
-
ctx.globalAlpha = 1
|
|
201
|
-
ctx.fillStyle = '#ffffff'
|
|
202
|
-
ctx.font = '32px "Sans Serif"'
|
|
203
|
-
ctx.textAlign = 'center'
|
|
204
|
-
ctx.fillText(LvlText, 70 + 180 / 2, 278)
|
|
205
|
-
ctx.restore()
|
|
206
|
-
|
|
207
|
-
ctx.save()
|
|
208
|
-
ctx.textAlign = 'left'
|
|
209
|
-
ctx.fillStyle = '#ffffff'
|
|
210
|
-
ctx.shadowColor = '#000000'
|
|
211
|
-
ctx.shadowBlur = 15
|
|
212
|
-
ctx.shadowOffsetX = 1
|
|
213
|
-
ctx.shadowOffsetY = 1
|
|
214
|
-
ctx.font = '39px "Sans Serif"'
|
|
215
|
-
ctx.fillText(Username, 390, 80)
|
|
216
|
-
ctx.restore()
|
|
217
|
-
|
|
218
|
-
ctx.save()
|
|
219
|
-
ctx.textAlign = 'right'
|
|
220
|
-
ctx.fillStyle = '#ffffff'
|
|
221
|
-
ctx.shadowColor = '#000000'
|
|
222
|
-
ctx.shadowBlur = 15
|
|
223
|
-
ctx.shadowOffsetX = 1
|
|
224
|
-
ctx.shadowOffsetY = 1
|
|
225
|
-
ctx.font = '55px "Sans Serif"'
|
|
226
|
-
ctx.fillText('#' + Rank, canvas.width - 55, 80)
|
|
227
|
-
ctx.restore()
|
|
228
|
-
|
|
229
|
-
ctx.save()
|
|
230
|
-
RoundedBox(ctx, 390, 305, 660, 70, Number(20))
|
|
231
|
-
ctx.strokeStyle = '#BFC85A22'
|
|
232
|
-
ctx.stroke()
|
|
233
|
-
ctx.clip()
|
|
234
|
-
ctx.fillStyle = '#ffffff'
|
|
235
|
-
ctx.font = `${fsiz} "Sans Serif"`
|
|
236
|
-
ctx.textAlign = 'center'
|
|
237
|
-
ctx.fillText(message.guild.name, 720, 355)
|
|
238
|
-
ctx.globalAlpha = 0.2
|
|
239
|
-
ctx.fillRect(390, 305, 660, 70)
|
|
240
|
-
ctx.restore()
|
|
241
|
-
|
|
242
|
-
ctx.save()
|
|
243
|
-
RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius))
|
|
244
|
-
ctx.strokeStyle = '#BFC85A22'
|
|
245
|
-
ctx.stroke()
|
|
246
|
-
ctx.clip()
|
|
247
|
-
ctx.fillStyle = LevelBarBackground
|
|
248
|
-
ctx.globalAlpha = 0.2
|
|
249
|
-
ctx.fillRect(390, 145, 660, 50, 50)
|
|
250
|
-
ctx.restore()
|
|
251
|
-
|
|
252
|
-
const percent = (100 * CurrentXP) / NeededXP
|
|
253
|
-
const progress = (percent * 660) / 100
|
|
254
|
-
|
|
255
|
-
ctx.save()
|
|
256
|
-
RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius))
|
|
257
|
-
ctx.strokeStyle = '#BFC85A22'
|
|
258
|
-
ctx.stroke()
|
|
259
|
-
ctx.clip()
|
|
260
|
-
ctx.fillStyle = LevelBarFill
|
|
261
|
-
ctx.globalAlpha = 0.5
|
|
262
|
-
ctx.fillRect(390, 145, progress, 50, 50)
|
|
263
|
-
ctx.restore()
|
|
264
|
-
|
|
265
|
-
ctx.save()
|
|
266
|
-
ctx.textAlign = 'left'
|
|
267
|
-
ctx.fillStyle = '#ffffff'
|
|
268
|
-
ctx.globalAlpha = 0.8
|
|
269
|
-
ctx.font = '30px "Sans Serif"'
|
|
270
|
-
ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230)
|
|
271
|
-
ctx.restore()
|
|
272
|
-
|
|
273
|
-
const latestXP = Number(CurrentXP) - Number(NeededXP)
|
|
274
|
-
const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP).toString())
|
|
275
|
-
.replace(/{current}/g, shortener(CurrentXP).toString())
|
|
276
|
-
.replace(/{latest}/g, latestXP.toString())
|
|
277
|
-
ctx.textAlign = 'center'
|
|
278
|
-
ctx.fillStyle = '#474747'
|
|
279
|
-
ctx.globalAlpha = 1
|
|
280
|
-
ctx.font = '30px "Sans Serif"'
|
|
281
|
-
ctx.fillText(textXPEdited, 730, 180)
|
|
282
|
-
|
|
283
|
-
return {
|
|
284
|
-
attachment: canvas.toBuffer('image/webp'),
|
|
285
|
-
description: AttachmentDesc,
|
|
286
|
-
name: AttachmentName
|
|
287
|
-
}
|
|
288
|
-
} catch (err) {
|
|
289
|
-
console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
module.exports = rank
|
package/src/reset.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
package/src/roleSetup.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
const lrole = require('../src/models/lvlrole.js')
|
|
2
|
-
|
|
3
|
-
class roleSetup {
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Client} client
|
|
6
|
-
* @param {string} guildID
|
|
7
|
-
* @param {import('../index').lvladdOptions} options
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
static async add(client, guildID, options = []) {
|
|
11
|
-
let rol = await lrole.findOne({
|
|
12
|
-
gid: guildID,
|
|
13
|
-
lvlrole: {
|
|
14
|
-
lvl: options.level,
|
|
15
|
-
role: options.role
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
let g = client.guilds.cache.get(guildID)
|
|
20
|
-
|
|
21
|
-
let roll = g.roles.cache.find((r) => r.id === options.role)
|
|
22
|
-
|
|
23
|
-
if (roll) {
|
|
24
|
-
if (rol) throw new Error('Level Already Exist. Use delete')
|
|
25
|
-
else if (!rol) {
|
|
26
|
-
let newrol = await lrole.findOne({
|
|
27
|
-
gid: guildID
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
if (!newrol) {
|
|
31
|
-
newrol = new lrole({
|
|
32
|
-
gid: guildID,
|
|
33
|
-
lvlrole: []
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
await newrol.save()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
newrol.lvlrole.push({ lvl: options.level, role: options.role })
|
|
40
|
-
|
|
41
|
-
await newrol
|
|
42
|
-
.save()
|
|
43
|
-
.catch((e) =>
|
|
44
|
-
console.log(`[XP] Failed to add lvlrole to database | ${e}`)
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
return true
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
throw new Error(
|
|
51
|
-
'Role ID is invalid. | ' +
|
|
52
|
-
`Guild ID: ${guildID} | Role ID: ${options.role}`
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @param {Discord.Client} client
|
|
59
|
-
* @param {string} guildID
|
|
60
|
-
* @param {import('../index').lvlremoveOptions} options
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
static async remove(client, guildID, options = []) {
|
|
64
|
-
let rol = await lrole.find({
|
|
65
|
-
gid: guildID
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
if (!rol || rol.length === 0)
|
|
69
|
-
throw new Error('Level role with this level does not exist')
|
|
70
|
-
rol = rol[0].lvlrole.find((item) => item.lvl === options.level) || undefined
|
|
71
|
-
|
|
72
|
-
if (rol) {
|
|
73
|
-
let newrol = await lrole.findOneAndUpdate(
|
|
74
|
-
{
|
|
75
|
-
gid: guildID
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
$pull: { lvlrole: { lvl: options.level } }
|
|
79
|
-
}
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
return true
|
|
83
|
-
} else throw new Error('Level role with this level does not exist')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @param {Discord.Client} client
|
|
88
|
-
* @param {string} guildID
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
static async fetch(client, guildID) {
|
|
92
|
-
let rol = await lrole.find({
|
|
93
|
-
gid: guildID
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
if (!rol || rol.length === 0) return
|
|
97
|
-
|
|
98
|
-
return rol[0].lvlrole
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @param {Discord.Client} client
|
|
103
|
-
* @param {string} guildID
|
|
104
|
-
* @param {string} level
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
static async find(client, guildID, level) {
|
|
108
|
-
let rol = await lrole.find({
|
|
109
|
-
gid: guildID
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
if (!rol || !rol.length) return
|
|
113
|
-
rol = rol[0].lvlrole.filter((i) => i.lvl == level) || undefined
|
|
114
|
-
|
|
115
|
-
if (rol) {
|
|
116
|
-
return rol
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
module.exports = roleSetup
|
package/src/setLevel.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
let { roleSetup } = require('../simplyxp')
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Message} message
|
|
6
|
-
* @param {string} userID
|
|
7
|
-
* @param {string} guildID
|
|
8
|
-
* @param {string} level
|
|
9
|
-
*/
|
|
10
|
-
async function setLevel(message, userID, guildID, level) {
|
|
11
|
-
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
12
|
-
|
|
13
|
-
if (!guildID) throw new Error('[XP] Guild ID was not provided.')
|
|
14
|
-
|
|
15
|
-
if (!level) throw new Error('[XP] Level amount is not provided.')
|
|
16
|
-
|
|
17
|
-
let { client } = message
|
|
18
|
-
|
|
19
|
-
const user = await levels.findOne({ user: userID, guild: guildID })
|
|
20
|
-
|
|
21
|
-
if (!user) {
|
|
22
|
-
const newUser = new levels({
|
|
23
|
-
user: userID,
|
|
24
|
-
guild: guildID,
|
|
25
|
-
xp: 0,
|
|
26
|
-
level: 0
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
await newUser
|
|
30
|
-
.save()
|
|
31
|
-
.catch((e) => console.log(`[XP] Failed to save new user to database`))
|
|
32
|
-
|
|
33
|
-
let xp = (level * 10) ** 2
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
level: level,
|
|
37
|
-
exp: xp
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
let level1 = user.level
|
|
41
|
-
|
|
42
|
-
user.xp = (level * 10) ** 2
|
|
43
|
-
user.level = Math.floor(0.1 * Math.sqrt(user.xp))
|
|
44
|
-
|
|
45
|
-
await user
|
|
46
|
-
.save()
|
|
47
|
-
.catch((e) =>
|
|
48
|
-
console.log(`[XP] Failed to set Level | User: ${userID} | Err: ${e}`)
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
if (level1 !== level) {
|
|
52
|
-
let data = {
|
|
53
|
-
xp: user.xp,
|
|
54
|
-
level: user.level,
|
|
55
|
-
userID,
|
|
56
|
-
guildID
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
let role = await roleSetup.find(client, guildID, level)
|
|
60
|
-
|
|
61
|
-
client.emit('levelUp', message, data, role)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
level: user.level,
|
|
66
|
-
xp: user.xp
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = setLevel
|
package/src/setXP.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} userID
|
|
5
|
-
* @param {string} guildID
|
|
6
|
-
* @param {string} xp
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
async function setXP(userID, guildID, xp) {
|
|
10
|
-
if (!userID) throw new Error('[XP] User ID was not provided.')
|
|
11
|
-
|
|
12
|
-
if (!guildID) throw new Error('[XP] Guild ID was not provided.')
|
|
13
|
-
|
|
14
|
-
if (!xp) throw new Error('[XP] XP amount is not provided.')
|
|
15
|
-
|
|
16
|
-
if (Number(xp).toString() === 'NaN')
|
|
17
|
-
throw new Error('[XP] XP amount is not a number.')
|
|
18
|
-
|
|
19
|
-
const user = await levels.findOne({ user: userID, guild: guildID })
|
|
20
|
-
|
|
21
|
-
let lvl = Math.floor(0.1 * Math.sqrt(xp))
|
|
22
|
-
|
|
23
|
-
if (!user) {
|
|
24
|
-
const newUser = new levels({
|
|
25
|
-
user: userID,
|
|
26
|
-
guild: guildID,
|
|
27
|
-
xp: xp,
|
|
28
|
-
level: lvl
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
await newUser
|
|
32
|
-
.save()
|
|
33
|
-
.catch((e) => console.log(`[XP] Failed to save new use to database`))
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
xp: 0
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
user.xp = xp
|
|
40
|
-
user.level = Math.floor(0.1 * Math.sqrt(user.xp))
|
|
41
|
-
|
|
42
|
-
await user
|
|
43
|
-
.save()
|
|
44
|
-
.catch((e) =>
|
|
45
|
-
console.log(`[XP] Failed to set XP | User: ${userID} | Err: ${e}`)
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
return { xp }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = setXP
|
|
File without changes
|