simply-xp 1.3.5-beta-6 → 1.3.5
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 +56 -56
- package/index.d.ts +1 -0
- package/package.json +54 -50
- package/simplyxp.js +33 -31
- package/src/addLevel.js +66 -66
- package/src/addXP.js +104 -103
- package/src/charts.js +92 -92
- package/src/connect.js +21 -22
- package/src/create.js +28 -28
- package/src/fetch.js +74 -74
- package/src/leaderboard.js +51 -52
- package/src/lvlRole.js +53 -53
- package/src/models/level.js +10 -10
- package/src/models/lvlrole.js +8 -8
- package/src/rank.js +295 -294
- package/src/reset.js +22 -22
- package/src/roleSetup.js +121 -121
- package/src/setLevel.js +42 -70
- package/src/setXP.js +23 -51
- 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/README.md
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
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>Supports Discord.JS<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
|
-
# 🎉 Recent Updates 🎉
|
|
32
|
-
|
|
33
|
-
- Fixed Various Bugs
|
|
34
|
-
- Updated `Chart.js`
|
|
35
|
-
- D.JS v14 Support
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# But Why ?
|
|
39
|
-
|
|
40
|
-
- Easiest XP System in Discord.js
|
|
41
|
-
- Fastest Support ever
|
|
42
|
-
- Rank Card Maker
|
|
43
|
-
- Beginner Friendly
|
|
44
|
-
- Easier than other XP Systems
|
|
45
|
-
- Inbuilt Auto Roles system
|
|
46
|
-
- Flexible and simple at the same time
|
|
47
|
-
|
|
48
|
-
<br>
|
|
49
|
-
|
|
50
|
-
## **Need Help ? Join the [Discord Server](https://discord.gg/3JzDV9T5Fn)**
|
|
51
|
-
|
|
52
|
-
<br>
|
|
53
|
-
|
|
54
|
-
<h1>👥 Contact us | Support</h1>
|
|
55
|
-
<p>
|
|
56
|
-
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
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>Supports Discord.JS<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
|
+
# 🎉 Recent Updates 🎉
|
|
32
|
+
|
|
33
|
+
- Fixed Various Bugs
|
|
34
|
+
- Updated `Chart.js`
|
|
35
|
+
- D.JS v14 Support
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# But Why ?
|
|
39
|
+
|
|
40
|
+
- Easiest XP System in Discord.js
|
|
41
|
+
- Fastest Support ever
|
|
42
|
+
- Rank Card Maker
|
|
43
|
+
- Beginner Friendly
|
|
44
|
+
- Easier than other XP Systems
|
|
45
|
+
- Inbuilt Auto Roles system
|
|
46
|
+
- Flexible and simple at the same time
|
|
47
|
+
|
|
48
|
+
<br>
|
|
49
|
+
|
|
50
|
+
## **Need Help ? Join the [Discord Server](https://discord.gg/3JzDV9T5Fn)**
|
|
51
|
+
|
|
52
|
+
<br>
|
|
53
|
+
|
|
54
|
+
<h1>👥 Contact us | Support</h1>
|
|
55
|
+
<p>
|
|
56
|
+
<a href="https://discord.gg/3JzDV9T5Fn"><img src="https://invidget.switchblade.xyz/3JzDV9T5Fn" /></a>
|
|
57
57
|
</p>
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "simply-xp",
|
|
3
|
-
"version": "1.3.5
|
|
4
|
-
"description": "A Simple, Easy and Beginner Friendly XP System",
|
|
5
|
-
"main": "simplyxp.js",
|
|
6
|
-
"typings": "index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"beta": "npm publish --tag beta"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"system",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"discord
|
|
21
|
-
"discord
|
|
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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "simply-xp",
|
|
3
|
+
"version": "1.3.5",
|
|
4
|
+
"description": "A Simple, Easy and Beginner Friendly XP System",
|
|
5
|
+
"main": "simplyxp.js",
|
|
6
|
+
"typings": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"beta": "eslint . --fix && npm update && npm publish --tag beta",
|
|
10
|
+
"legacy": "eslint . --fix && npm update && npm publish --tag legacy"
|
|
11
|
+
},
|
|
12
|
+
"author": "Rahuletto",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"xp",
|
|
15
|
+
"simply",
|
|
16
|
+
"easy",
|
|
17
|
+
"xp-system",
|
|
18
|
+
"system",
|
|
19
|
+
"mongoose",
|
|
20
|
+
"discord",
|
|
21
|
+
"discord xp",
|
|
22
|
+
"discord-xp",
|
|
23
|
+
"simply-djs",
|
|
24
|
+
"discord.js",
|
|
25
|
+
"simplydjs",
|
|
26
|
+
"weky",
|
|
27
|
+
"nuggies",
|
|
28
|
+
"experience",
|
|
29
|
+
"level role",
|
|
30
|
+
"amari",
|
|
31
|
+
"package",
|
|
32
|
+
"leaderboard",
|
|
33
|
+
"mee6",
|
|
34
|
+
"charts",
|
|
35
|
+
"ChartJS",
|
|
36
|
+
"level up"
|
|
37
|
+
],
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/Rahuletto/simply-xp"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@napi-rs/canvas": "^0.1.41",
|
|
45
|
+
"chart.js": "^3.9.1",
|
|
46
|
+
"mongoose": "^7.4.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"discord.js": ">=13.12.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"eslint": "^8.46.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/simplyxp.js
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
try {
|
|
2
|
-
|
|
3
|
-
} catch (e) {
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module.exports.roleSetup = require(
|
|
8
|
-
|
|
9
|
-
module.exports.addLevel = require(
|
|
10
|
-
|
|
11
|
-
module.exports.addXP = require(
|
|
12
|
-
|
|
13
|
-
module.exports.charts = require(
|
|
14
|
-
|
|
15
|
-
module.exports.connect = require(
|
|
16
|
-
|
|
17
|
-
module.exports.create = require(
|
|
18
|
-
|
|
19
|
-
module.exports.fetch = require(
|
|
20
|
-
|
|
21
|
-
module.exports.leaderboard = require(
|
|
22
|
-
|
|
23
|
-
module.exports.lvlRole = require(
|
|
24
|
-
|
|
25
|
-
module.exports.rank = require(
|
|
26
|
-
|
|
27
|
-
module.exports.setLevel = require(
|
|
28
|
-
|
|
29
|
-
module.exports.setXP = require(
|
|
30
|
-
|
|
31
|
-
module.exports.reset = require(
|
|
1
|
+
try {
|
|
2
|
+
require("discord.js");
|
|
3
|
+
} catch (e) {
|
|
4
|
+
console.warn("[XP] Discord.js is recommended for this package.");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
module.exports.roleSetup = require("./src/roleSetup");
|
|
8
|
+
|
|
9
|
+
module.exports.addLevel = require("./src/addLevel");
|
|
10
|
+
|
|
11
|
+
module.exports.addXP = require("./src/addXP");
|
|
12
|
+
|
|
13
|
+
module.exports.charts = require("./src/charts");
|
|
14
|
+
|
|
15
|
+
module.exports.connect = require("./src/connect");
|
|
16
|
+
|
|
17
|
+
module.exports.create = require("./src/create");
|
|
18
|
+
|
|
19
|
+
module.exports.fetch = require("./src/fetch");
|
|
20
|
+
|
|
21
|
+
module.exports.leaderboard = require("./src/leaderboard");
|
|
22
|
+
|
|
23
|
+
module.exports.lvlRole = require("./src/lvlRole");
|
|
24
|
+
|
|
25
|
+
module.exports.rank = require("./src/rank");
|
|
26
|
+
|
|
27
|
+
module.exports.setLevel = require("./src/setLevel");
|
|
28
|
+
|
|
29
|
+
module.exports.setXP = require("./src/setXP");
|
|
30
|
+
|
|
31
|
+
module.exports.reset = require("./src/reset");
|
|
32
|
+
|
|
33
|
+
module.exports.options = {auto_purge: false};
|
package/src/addLevel.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
const levels = require(
|
|
2
|
-
let {roleSetup} = require(
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
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.save().catch(() => console.log("[XP] Failed to save new user to database"));
|
|
30
|
+
|
|
31
|
+
let xp = (level * 10) ** 2;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
level: level,
|
|
35
|
+
exp: xp
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
let level1 = user.level;
|
|
39
|
+
|
|
40
|
+
user.level += parseFloat(level);
|
|
41
|
+
user.xp = (user.level * 10) ** 2;
|
|
42
|
+
|
|
43
|
+
await user.save().catch((e) =>
|
|
44
|
+
console.log(`[XP] Failed to add Level | User: ${userID} | Err: ${e}`)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (level1 !== level) {
|
|
48
|
+
let data = {
|
|
49
|
+
xp: user.xp,
|
|
50
|
+
level: user.level,
|
|
51
|
+
userID,
|
|
52
|
+
guildID
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
let role = await roleSetup.find(client, guildID, level);
|
|
56
|
+
|
|
57
|
+
client.emit("levelUp", message, data, role);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
level: user.level,
|
|
62
|
+
xp: user.xp
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = addLevel;
|
package/src/addXP.js
CHANGED
|
@@ -1,103 +1,104 @@
|
|
|
1
|
-
const levels = require(
|
|
2
|
-
let {roleSetup} = require(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
xp = Math.floor(Math.random() * (max - min) + min);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const user = await levels.findOne({user: userID, guild: guildID});
|
|
51
|
+
|
|
52
|
+
let lvl = Math.floor(0.1 * Math.sqrt(xp));
|
|
53
|
+
|
|
54
|
+
// TODO: FIX THIS xp = xp & level = lvl
|
|
55
|
+
if (!user) {
|
|
56
|
+
const newUser = new levels({
|
|
57
|
+
user: userID,
|
|
58
|
+
guild: guildID,
|
|
59
|
+
xp: xp,
|
|
60
|
+
level: lvl
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
await newUser.save().catch(() => console.log("[XP] Failed to save new user to database"));
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
level: 0,
|
|
67
|
+
exp: 0
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
let level1 = user.level;
|
|
71
|
+
|
|
72
|
+
user.xp += parseInt(xp, 10);
|
|
73
|
+
user.level = Math.floor(0.1 * Math.sqrt(user.xp));
|
|
74
|
+
|
|
75
|
+
await user.save().catch((e) => console.log(`[XP] Failed to add XP | User: ${userID} | Err: ${e}`));
|
|
76
|
+
|
|
77
|
+
let level = user.level;
|
|
78
|
+
|
|
79
|
+
xp = user.xp;
|
|
80
|
+
|
|
81
|
+
if (user.xp === 0 || Math.sign(user.xp) === -1) {
|
|
82
|
+
xp = 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (level1 !== level) {
|
|
86
|
+
let data = {
|
|
87
|
+
xp,
|
|
88
|
+
level,
|
|
89
|
+
userID,
|
|
90
|
+
guildID
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
let role = await roleSetup.find(client, guildID, level);
|
|
94
|
+
|
|
95
|
+
client.emit("levelUp", message, data, role);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
level,
|
|
100
|
+
xp
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = addXP;
|