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/README.md
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
<p align="center"><img align="center" style="margin-bottom:-6px" src="https://i.imgur.com/BiaHJA7.png?maxwidth=128&fidelity=grand"></p>
|
|
2
|
-
|
|
3
|
-
<h2 style="font-size:2.5rem;" align="center">Simply-XP</h2>
|
|
4
|
-
|
|
5
|
-
<h2 align="center">A Simple, Easy and Beginner friendly XP System. <br>Uses Discord.js v13<br><br>Developed by Rahuletto#0243 & Maintained by Abadima#6356</h2>
|
|
6
|
-
|
|
7
|
-
<br>
|
|
8
|
-
<p align="center">
|
|
9
|
-
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://img.shields.io/npm/v/simply-xp.svg?style=flat-square" /></a>
|
|
10
|
-
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://img.shields.io/npm/dt/simply-xp?style=flat-square" /></a><br>
|
|
11
|
-
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://nodei.co/npm/simply-xp.png?downloadRank=true&downloads=true&downloadRank=true&stars=true" /></a><br>
|
|
12
|
-
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
<br>
|
|
16
|
-
|
|
17
|
-
## 🖥️ <b>How to install ?
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
npm install simply-xp
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
(or)
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
yarn add simply-xp
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
<br>
|
|
30
|
-
|
|
31
|
-
# 🎉 What's New 🎉
|
|
32
|
-
|
|
33
|
-
- We have patched known issues, and we continue to monitor changes!
|
|
34
|
-
- Our rank card has a new font applied
|
|
35
|
-
|
|
36
|
-
# But Why ?
|
|
37
|
-
|
|
38
|
-
- Easiest XP System in Discord.js
|
|
39
|
-
- Fastest Support ever
|
|
40
|
-
- Rank Card Maker
|
|
41
|
-
- Beginner Friendly
|
|
42
|
-
- Easier than other XP Systems
|
|
43
|
-
- Inbuilt Auto Roles system
|
|
44
|
-
- Flexible and simple at the same time
|
|
45
|
-
|
|
46
|
-
<br>
|
|
47
|
-
|
|
48
|
-
## **Need Help ? Join the [Discord Server](https://discord.gg/3JzDV9T5Fn)**
|
|
49
|
-
|
|
50
|
-
<br>
|
|
51
|
-
|
|
52
|
-
<h1>👥 Contact us | Support</h1>
|
|
53
|
-
<p>
|
|
54
|
-
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
55
|
-
</p>
|
|
1
|
+
<p align="center"><img align="center" style="margin-bottom:-6px" src="https://i.imgur.com/BiaHJA7.png?maxwidth=128&fidelity=grand"></p>
|
|
2
|
+
|
|
3
|
+
<h2 style="font-size:2.5rem;" align="center">Simply-XP</h2>
|
|
4
|
+
|
|
5
|
+
<h2 align="center">A Simple, Easy and Beginner friendly XP System. <br>Uses Discord.js v13<br><br>Developed by Rahuletto#0243 & Maintained by Abadima#6356</h2>
|
|
6
|
+
|
|
7
|
+
<br>
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://img.shields.io/npm/v/simply-xp.svg?style=flat-square" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://img.shields.io/npm/dt/simply-xp?style=flat-square" /></a><br>
|
|
11
|
+
<a href="https://www.npmjs.com/package/simply-xp"><img src="https://nodei.co/npm/simply-xp.png?downloadRank=true&downloads=true&downloadRank=true&stars=true" /></a><br>
|
|
12
|
+
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<br>
|
|
16
|
+
|
|
17
|
+
## 🖥️ <b>How to install ?
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm install simply-xp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
(or)
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
yarn add simply-xp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
<br>
|
|
30
|
+
|
|
31
|
+
# 🎉 What's New 🎉
|
|
32
|
+
|
|
33
|
+
- We have patched known issues, and we continue to monitor changes!
|
|
34
|
+
- Our rank card has a new font applied
|
|
35
|
+
|
|
36
|
+
# But Why ?
|
|
37
|
+
|
|
38
|
+
- Easiest XP System in Discord.js
|
|
39
|
+
- Fastest Support ever
|
|
40
|
+
- Rank Card Maker
|
|
41
|
+
- Beginner Friendly
|
|
42
|
+
- Easier than other XP Systems
|
|
43
|
+
- Inbuilt Auto Roles system
|
|
44
|
+
- Flexible and simple at the same time
|
|
45
|
+
|
|
46
|
+
<br>
|
|
47
|
+
|
|
48
|
+
## **Need Help ? Join the [Discord Server](https://discord.gg/3JzDV9T5Fn)**
|
|
49
|
+
|
|
50
|
+
<br>
|
|
51
|
+
|
|
52
|
+
<h1>👥 Contact us | Support</h1>
|
|
53
|
+
<p>
|
|
54
|
+
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
55
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-dev-2",
|
|
4
4
|
"description": "A Simple, Easy and Beginner Friendly XP System",
|
|
5
5
|
"main": "simplyxp.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"canvas": "^2.9.3",
|
|
44
|
-
"chart.js
|
|
44
|
+
"chart.js": "^3.8.0",
|
|
45
45
|
"mongoose": "^6.0.15"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"pretty-quick": "^3.1.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"discord.js": "
|
|
52
|
+
"discord.js": "*"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/simplyxp.js
CHANGED
package/src/addLevel.js
CHANGED
|
@@ -1,71 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string}
|
|
8
|
-
* @param {
|
|
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
|
-
user.
|
|
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
|
-
module.exports = addLevel
|
|
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 {number} level
|
|
9
|
+
*/
|
|
10
|
+
async function addLevel(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 add 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 = addLevel
|
package/src/addXP.js
CHANGED
|
@@ -1,112 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {string}
|
|
8
|
-
* @param {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let
|
|
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
|
-
user.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
module.exports = addXP
|
|
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 {number} xp
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
async function addXP(message, userID, guildID, xp) {
|
|
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
|
+
if (!xp) throw new Error('[XP] XP amount is not provided.')
|
|
17
|
+
|
|
18
|
+
let { client } = message
|
|
19
|
+
|
|
20
|
+
let min
|
|
21
|
+
let max
|
|
22
|
+
if (xp.min) {
|
|
23
|
+
if (!xp.max)
|
|
24
|
+
throw new Error(
|
|
25
|
+
'[XP] XP min amount is provided but max amount is not provided.'
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
min = Number(xp.min)
|
|
29
|
+
|
|
30
|
+
if (Number(xp.min).toString() === 'NaN')
|
|
31
|
+
throw new Error('[XP] XP amount (min) is not a number.')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (xp.max) {
|
|
35
|
+
if (!xp.min)
|
|
36
|
+
throw new Error(
|
|
37
|
+
'[XP] XP max amount is provided but min amount is not provided.'
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
max = Number(xp.max)
|
|
41
|
+
|
|
42
|
+
if (Number(xp.max).toString() === 'NaN')
|
|
43
|
+
throw new Error('[XP] XP amount (max) is not a number.')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (xp.min && xp.max) {
|
|
47
|
+
let randomNumber = Math.floor(Math.random() * (max - min) + min)
|
|
48
|
+
|
|
49
|
+
xp = randomNumber
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const user = await levels.findOne({ user: userID, guild: guildID })
|
|
53
|
+
|
|
54
|
+
let lvl = Math.floor(0.1 * Math.sqrt(xp))
|
|
55
|
+
|
|
56
|
+
if (!user) {
|
|
57
|
+
const newUser = new levels({
|
|
58
|
+
user: userID,
|
|
59
|
+
guild: guildID,
|
|
60
|
+
xp: xp,
|
|
61
|
+
level: lvl
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
await newUser
|
|
65
|
+
.save()
|
|
66
|
+
.catch((e) => console.log(`[XP] Failed to save new user to database`))
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
level: 0,
|
|
70
|
+
exp: 0
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
let level1 = user.level
|
|
74
|
+
|
|
75
|
+
user.xp += parseInt(xp, 10)
|
|
76
|
+
user.level = Math.floor(0.1 * Math.sqrt(user.xp))
|
|
77
|
+
|
|
78
|
+
await user
|
|
79
|
+
.save()
|
|
80
|
+
.catch((e) =>
|
|
81
|
+
console.log(`[XP] Failed to add XP | User: ${userID} | Err: ${e}`)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
let level = user.level
|
|
85
|
+
|
|
86
|
+
xp = user.xp
|
|
87
|
+
|
|
88
|
+
if (user.xp === 0 || Math.sign(user.xp) === -1) {
|
|
89
|
+
xp = 0
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (level1 !== level) {
|
|
93
|
+
let data = {
|
|
94
|
+
xp,
|
|
95
|
+
level,
|
|
96
|
+
userID,
|
|
97
|
+
guildID
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let role = await roleSetup.find(client, guildID, level)
|
|
101
|
+
|
|
102
|
+
client.emit('levelUp', message, data, role)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
level,
|
|
107
|
+
xp
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = addXP
|