simply-xp 1.3.5-beta-5 → 1.3.5-beta-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/.eslintrc.json +29 -0
- package/.idea/discord.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/simply-xp.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/index.d.ts +1 -1
- package/package.json +7 -4
- package/simplyxp.js +31 -31
- package/src/addLevel.js +66 -70
- package/src/addXP.js +104 -111
- package/src/charts.js +92 -89
- package/src/connect.js +22 -22
- package/src/create.js +28 -28
- package/src/fetch.js +74 -74
- package/src/leaderboard.js +52 -56
- 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 -296
- package/src/reset.js +22 -22
- package/src/roleSetup.js +121 -121
- package/src/setLevel.js +70 -70
- package/src/setXP.js +51 -51
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"commonjs": true,
|
|
4
|
+
"es2021": true,
|
|
5
|
+
"node": true
|
|
6
|
+
},
|
|
7
|
+
"extends": "eslint:recommended",
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"ecmaVersion": "latest"
|
|
10
|
+
},
|
|
11
|
+
"rules": {
|
|
12
|
+
"indent": [
|
|
13
|
+
"error",
|
|
14
|
+
"tab"
|
|
15
|
+
],
|
|
16
|
+
"linebreak-style": [
|
|
17
|
+
"error",
|
|
18
|
+
"unix"
|
|
19
|
+
],
|
|
20
|
+
"quotes": [
|
|
21
|
+
"error",
|
|
22
|
+
"single"
|
|
23
|
+
],
|
|
24
|
+
"semi": [
|
|
25
|
+
"error",
|
|
26
|
+
"always"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/simply-xp.iml" filepath="$PROJECT_DIR$/.idea/simply-xp.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "1.3.5-beta-
|
|
3
|
+
"version": "1.3.5-beta-7",
|
|
4
4
|
"description": "A Simple, Easy and Beginner Friendly XP System",
|
|
5
5
|
"main": "simplyxp.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"beta": "npm publish --tag beta"
|
|
9
|
+
"beta": "eslint . --fix && npm update && npm publish --tag beta"
|
|
10
10
|
},
|
|
11
11
|
"author": "Rahuletto",
|
|
12
12
|
"keywords": [
|
|
@@ -40,11 +40,14 @@
|
|
|
40
40
|
"url": "https://github.com/Rahuletto/simply-xp"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@napi-rs/canvas": "^0.1.
|
|
43
|
+
"@napi-rs/canvas": "^0.1.41",
|
|
44
44
|
"chart.js": "^3.9.1",
|
|
45
|
-
"mongoose": "^6.
|
|
45
|
+
"mongoose": "^6.11.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"discord.js": ">=13.12.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"eslint": "^8.43.0"
|
|
49
52
|
}
|
|
50
53
|
}
|
package/simplyxp.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
try {
|
|
2
|
-
|
|
3
|
-
} catch (e) {
|
|
4
|
-
|
|
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')
|
|
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');
|
package/src/addLevel.js
CHANGED
|
@@ -1,70 +1,66 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
let {
|
|
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
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
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,111 +1,104 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
let {
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
level,
|
|
107
|
-
xp
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
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
|
+
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;
|