simply-xp 1.2.0-test-2 → 1.3.0-dev-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/README.md +55 -55
- package/package.json +3 -3
- package/simplyxp.js +1 -1
- package/src/addLevel.js +70 -71
- package/src/addXP.js +111 -112
- package/src/charts.js +88 -83
- package/src/leaderboard.js +69 -70
- package/src/lvlRole.js +53 -54
- package/src/rank.js +4 -6
- package/src/roleSetup.js +121 -122
- package/src/setLevel.js +70 -71
package/src/charts.js
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
1
|
-
let
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
let data = []
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
1
|
+
let leaderboard = require('./leaderboard')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Discord.Message} message
|
|
5
|
+
* @param {import('../index').chartsOptions} options
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function charts(message, options = []) {
|
|
9
|
+
let { client } = message
|
|
10
|
+
const ChartJS = require('chart.js')
|
|
11
|
+
const Canvas = require('canvas')
|
|
12
|
+
|
|
13
|
+
let data = []
|
|
14
|
+
let pos = options?.position || 5
|
|
15
|
+
let uzern = []
|
|
16
|
+
|
|
17
|
+
let ctx = Canvas.createCanvas(950, 526)
|
|
18
|
+
await leaderboard(client, message.guild.id).then((e) => {
|
|
19
|
+
e.forEach((m) => {
|
|
20
|
+
if (m.position <= pos) {
|
|
21
|
+
data.push(m.xp)
|
|
22
|
+
uzern.push(m.tag)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
new ChartJS(ctx, {
|
|
28
|
+
type: options.type || 'bar',
|
|
29
|
+
data: {
|
|
30
|
+
labels: uzern,
|
|
31
|
+
datasets: [
|
|
32
|
+
{
|
|
33
|
+
label: 'Leaderboards',
|
|
34
|
+
data: data,
|
|
35
|
+
backgroundColor: [
|
|
36
|
+
'rgba(255, 99, 132, 0.5)',
|
|
37
|
+
'rgba(255, 159, 64, 0.5)',
|
|
38
|
+
'rgba(255, 205, 86, 0.5)',
|
|
39
|
+
'rgba(75, 192, 192, 0.5)',
|
|
40
|
+
'rgba(54, 162, 235, 0.5)',
|
|
41
|
+
'rgba(153, 102, 255, 0.5)',
|
|
42
|
+
'rgb(201, 203, 207, 0.5)'
|
|
43
|
+
],
|
|
44
|
+
borderColor: [
|
|
45
|
+
'rgb(255, 99, 132)',
|
|
46
|
+
'rgb(255, 159, 64)',
|
|
47
|
+
'rgb(255, 205, 86)',
|
|
48
|
+
'rgb(75, 192, 192)',
|
|
49
|
+
'rgb(54, 162, 235)',
|
|
50
|
+
'rgb(153, 102, 255)',
|
|
51
|
+
'rgb(201, 203, 207)'
|
|
52
|
+
],
|
|
53
|
+
borderWidth: 2
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
options: {
|
|
58
|
+
animation: false,
|
|
59
|
+
plugins: {
|
|
60
|
+
title: {
|
|
61
|
+
display: true,
|
|
62
|
+
text: 'XP Datasheet'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
plugins: [
|
|
67
|
+
{
|
|
68
|
+
id: 'simply-xp',
|
|
69
|
+
beforeDraw: (chart) => {
|
|
70
|
+
const ctx = chart.canvas.getContext('2d')
|
|
71
|
+
ctx.save()
|
|
72
|
+
ctx.globalCompositeOperation = 'destination-over'
|
|
73
|
+
ctx.fillStyle = options.background || '#2F3136'
|
|
74
|
+
ctx.fillRect(0, 0, chart.width, chart.height)
|
|
75
|
+
ctx.restore()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}).update()
|
|
80
|
+
|
|
81
|
+
const attachment = {
|
|
82
|
+
attachment: ctx.toBuffer(),
|
|
83
|
+
name: 'chart.png'
|
|
84
|
+
}
|
|
85
|
+
return attachment
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = charts
|
package/src/leaderboard.js
CHANGED
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
result
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
module.exports = leaderboard
|
|
1
|
+
const levels = require('../src/models/level.js')
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Discord.Client} client
|
|
5
|
+
* @param {string} guildID
|
|
6
|
+
* @param {number} limit
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
async function leaderboard(client, guildID, limit) {
|
|
10
|
+
if (!guildID) throw new Error('[XP] Guild ID was not provided.')
|
|
11
|
+
|
|
12
|
+
let g = client.guilds.cache.get(guildID)
|
|
13
|
+
|
|
14
|
+
let leaderboard = await levels
|
|
15
|
+
.find({
|
|
16
|
+
guild: guildID
|
|
17
|
+
})
|
|
18
|
+
.sort([['xp', 'descending']])
|
|
19
|
+
.exec()
|
|
20
|
+
|
|
21
|
+
let led = []
|
|
22
|
+
|
|
23
|
+
function shortener(count) {
|
|
24
|
+
const COUNT_ABBRS = ['', 'k', 'M', 'T']
|
|
25
|
+
|
|
26
|
+
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000))
|
|
27
|
+
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2))
|
|
28
|
+
result += `${COUNT_ABBRS[i]}`
|
|
29
|
+
return result
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
leaderboard.map((key) => {
|
|
33
|
+
let user = g.members.cache.get(key.user)
|
|
34
|
+
if (key.xp === 0) return
|
|
35
|
+
|
|
36
|
+
let pos =
|
|
37
|
+
leaderboard.findIndex(
|
|
38
|
+
(i) => i.guild === key.guild && i.user === key.user
|
|
39
|
+
) + 1
|
|
40
|
+
|
|
41
|
+
if (limit) {
|
|
42
|
+
if (pos > Number(limit)) return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let shortXP = shortener(key.xp)
|
|
46
|
+
|
|
47
|
+
if (!user) return
|
|
48
|
+
|
|
49
|
+
led.push({
|
|
50
|
+
guildID: key.guild,
|
|
51
|
+
userID: key.user,
|
|
52
|
+
xp: key.xp,
|
|
53
|
+
shortxp: shortXP,
|
|
54
|
+
level: key.level,
|
|
55
|
+
position: pos,
|
|
56
|
+
username: user.user.username,
|
|
57
|
+
tag: user.user.tag
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
led = led.filter(
|
|
62
|
+
(thing, index, self) =>
|
|
63
|
+
index === self.findIndex((t) => t.userID === thing.userID)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return led
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = leaderboard
|
package/src/lvlRole.js
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
module.exports = lvlRole
|
|
1
|
+
const levels = require('../src/models/level.js')
|
|
2
|
+
const lrole = require('../src/models/lvlrole.js')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {Discord.Message} message
|
|
6
|
+
* @param {string} userID
|
|
7
|
+
* @param {string} guildID
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
async function lvlRole(message, userID, guildID) {
|
|
11
|
+
let e = await lrole.find({
|
|
12
|
+
gid: guildID
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
if (!e) return
|
|
16
|
+
|
|
17
|
+
let user = await levels.findOne({
|
|
18
|
+
user: userID,
|
|
19
|
+
guild: guildID
|
|
20
|
+
})
|
|
21
|
+
if (!user) {
|
|
22
|
+
const newuser = new levels({
|
|
23
|
+
user: userID,
|
|
24
|
+
guild: guildID
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
await newuser
|
|
28
|
+
.save()
|
|
29
|
+
.catch((e) => console.log(`[XP] Failed to save new user to database`))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
e.forEach((ee) => {
|
|
33
|
+
ee = ee.lvlrole
|
|
34
|
+
|
|
35
|
+
ee.forEach((xd) => {
|
|
36
|
+
if (user && user.level >= Number(xd.lvl)) {
|
|
37
|
+
let u = message.guild.members.cache.get(userID)
|
|
38
|
+
|
|
39
|
+
let real = message.guild.roles.cache.find((r) => r.id === xd.role)
|
|
40
|
+
if (!real) return
|
|
41
|
+
else {
|
|
42
|
+
u.roles.add(real).catch((err) => {
|
|
43
|
+
message.channel.send(
|
|
44
|
+
'[XP] ERROR: Role is higher than me. `MISSING_PERMISSIONS`'
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = lvlRole
|
package/src/rank.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
let Discord = require('discord.js')
|
|
2
1
|
const levels = require('../src/models/level.js')
|
|
3
2
|
const { join } = require('path')
|
|
4
3
|
|
|
@@ -283,11 +282,10 @@ async function rank(message, userID, guildID, options = []) {
|
|
|
283
282
|
ctx.font = '30px "Sans Serif"'
|
|
284
283
|
ctx.fillText(textXPEdited, 730, 180)
|
|
285
284
|
|
|
286
|
-
const attachment =
|
|
287
|
-
canvas.toBuffer(),
|
|
288
|
-
AttachmentName
|
|
289
|
-
|
|
290
|
-
|
|
285
|
+
const attachment = {
|
|
286
|
+
attachment: canvas.toBuffer(),
|
|
287
|
+
name: AttachmentName
|
|
288
|
+
}
|
|
291
289
|
return attachment
|
|
292
290
|
} catch (err) {
|
|
293
291
|
console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`)
|