simply-xp 1.3.5-beta-7 → 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 -53
- package/simplyxp.js +17 -15
- package/src/addLevel.js +7 -7
- package/src/addXP.js +13 -13
- package/src/charts.js +29 -29
- package/src/connect.js +6 -7
- package/src/create.js +5 -5
- package/src/fetch.js +5 -5
- package/src/leaderboard.js +9 -10
- package/src/lvlRole.js +4 -4
- package/src/models/level.js +6 -6
- package/src/models/lvlrole.js +4 -4
- package/src/rank.js +73 -73
- package/src/reset.js +5 -5
- package/src/roleSetup.js +23 -23
- package/src/setLevel.js +14 -42
- package/src/setXP.js +17 -45
- package/.eslintrc.json +0 -29
- 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/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/simply-xp.iml +0 -9
- package/.idea/vcs.xml +0 -6
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,53 +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": "eslint . --fix && npm update && 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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
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
1
|
try {
|
|
2
|
-
require(
|
|
2
|
+
require("discord.js");
|
|
3
3
|
} catch (e) {
|
|
4
|
-
console.warn(
|
|
4
|
+
console.warn("[XP] Discord.js is recommended for this package.");
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
module.exports.roleSetup = require(
|
|
7
|
+
module.exports.roleSetup = require("./src/roleSetup");
|
|
8
8
|
|
|
9
|
-
module.exports.addLevel = require(
|
|
9
|
+
module.exports.addLevel = require("./src/addLevel");
|
|
10
10
|
|
|
11
|
-
module.exports.addXP = require(
|
|
11
|
+
module.exports.addXP = require("./src/addXP");
|
|
12
12
|
|
|
13
|
-
module.exports.charts = require(
|
|
13
|
+
module.exports.charts = require("./src/charts");
|
|
14
14
|
|
|
15
|
-
module.exports.connect = require(
|
|
15
|
+
module.exports.connect = require("./src/connect");
|
|
16
16
|
|
|
17
|
-
module.exports.create = require(
|
|
17
|
+
module.exports.create = require("./src/create");
|
|
18
18
|
|
|
19
|
-
module.exports.fetch = require(
|
|
19
|
+
module.exports.fetch = require("./src/fetch");
|
|
20
20
|
|
|
21
|
-
module.exports.leaderboard = require(
|
|
21
|
+
module.exports.leaderboard = require("./src/leaderboard");
|
|
22
22
|
|
|
23
|
-
module.exports.lvlRole = require(
|
|
23
|
+
module.exports.lvlRole = require("./src/lvlRole");
|
|
24
24
|
|
|
25
|
-
module.exports.rank = require(
|
|
25
|
+
module.exports.rank = require("./src/rank");
|
|
26
26
|
|
|
27
|
-
module.exports.setLevel = require(
|
|
27
|
+
module.exports.setLevel = require("./src/setLevel");
|
|
28
28
|
|
|
29
|
-
module.exports.setXP = require(
|
|
29
|
+
module.exports.setXP = require("./src/setXP");
|
|
30
30
|
|
|
31
|
-
module.exports.reset = require(
|
|
31
|
+
module.exports.reset = require("./src/reset");
|
|
32
|
+
|
|
33
|
+
module.exports.options = {auto_purge: false};
|
package/src/addLevel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const levels = require(
|
|
2
|
-
let {roleSetup} = require(
|
|
1
|
+
const levels = require("../src/models/level.js");
|
|
2
|
+
let {roleSetup} = require("../simplyxp");
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {Discord.Message} message
|
|
@@ -8,11 +8,11 @@ let {roleSetup} = require('../simplyxp');
|
|
|
8
8
|
* @param {number} level
|
|
9
9
|
*/
|
|
10
10
|
async function addLevel(message, userID, guildID, level) {
|
|
11
|
-
if (!userID) throw new Error(
|
|
11
|
+
if (!userID) throw new Error("[XP] User ID was not provided.");
|
|
12
12
|
|
|
13
|
-
if (!guildID) throw new Error(
|
|
13
|
+
if (!guildID) throw new Error("[XP] Guild ID was not provided.");
|
|
14
14
|
|
|
15
|
-
if (!level) throw new Error(
|
|
15
|
+
if (!level) throw new Error("[XP] Level amount is not provided.");
|
|
16
16
|
|
|
17
17
|
let {client} = message;
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ async function addLevel(message, userID, guildID, level) {
|
|
|
26
26
|
level: 0
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
await newUser.save().catch(() => console.log(
|
|
29
|
+
await newUser.save().catch(() => console.log("[XP] Failed to save new user to database"));
|
|
30
30
|
|
|
31
31
|
let xp = (level * 10) ** 2;
|
|
32
32
|
|
|
@@ -54,7 +54,7 @@ async function addLevel(message, userID, guildID, level) {
|
|
|
54
54
|
|
|
55
55
|
let role = await roleSetup.find(client, guildID, level);
|
|
56
56
|
|
|
57
|
-
client.emit(
|
|
57
|
+
client.emit("levelUp", message, data, role);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
return {
|
package/src/addXP.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const levels = require(
|
|
2
|
-
let {roleSetup} = require(
|
|
1
|
+
const levels = require("../src/models/level.js");
|
|
2
|
+
let {roleSetup} = require("../simplyxp");
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {Discord.Message} message
|
|
@@ -9,11 +9,11 @@ let {roleSetup} = require('../simplyxp');
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
async function addXP(message, userID, guildID, xp) {
|
|
12
|
-
if (!userID) throw new Error(
|
|
12
|
+
if (!userID) throw new Error("[XP] User ID was not provided.");
|
|
13
13
|
|
|
14
|
-
if (!guildID) throw new Error(
|
|
14
|
+
if (!guildID) throw new Error("[XP] Guild ID was not provided.");
|
|
15
15
|
|
|
16
|
-
if (!xp) throw new Error(
|
|
16
|
+
if (!xp) throw new Error("[XP] XP amount is not provided.");
|
|
17
17
|
|
|
18
18
|
let {client} = message;
|
|
19
19
|
|
|
@@ -22,25 +22,25 @@ async function addXP(message, userID, guildID, xp) {
|
|
|
22
22
|
if (xp.min) {
|
|
23
23
|
if (!xp.max)
|
|
24
24
|
throw new Error(
|
|
25
|
-
|
|
25
|
+
"[XP] XP min amount is provided but max amount is not provided."
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
min = Number(xp.min);
|
|
29
29
|
|
|
30
|
-
if (Number(xp.min).toString() ===
|
|
31
|
-
throw new Error(
|
|
30
|
+
if (Number(xp.min).toString() === "NaN")
|
|
31
|
+
throw new Error("[XP] XP amount (min) is not a number.");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (xp.max) {
|
|
35
35
|
if (!xp.min)
|
|
36
36
|
throw new Error(
|
|
37
|
-
|
|
37
|
+
"[XP] XP max amount is provided but min amount is not provided."
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
max = Number(xp.max);
|
|
41
41
|
|
|
42
|
-
if (Number(xp.max).toString() ===
|
|
43
|
-
throw new Error(
|
|
42
|
+
if (Number(xp.max).toString() === "NaN")
|
|
43
|
+
throw new Error("[XP] XP amount (max) is not a number.");
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (xp.min && xp.max) {
|
|
@@ -60,7 +60,7 @@ async function addXP(message, userID, guildID, xp) {
|
|
|
60
60
|
level: lvl
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
await newUser.save().catch(() => console.log(
|
|
63
|
+
await newUser.save().catch(() => console.log("[XP] Failed to save new user to database"));
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
66
|
level: 0,
|
|
@@ -92,7 +92,7 @@ async function addXP(message, userID, guildID, xp) {
|
|
|
92
92
|
|
|
93
93
|
let role = await roleSetup.find(client, guildID, level);
|
|
94
94
|
|
|
95
|
-
client.emit(
|
|
95
|
+
client.emit("levelUp", message, data, role);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
return {
|
package/src/charts.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
let leaderboard = require(
|
|
1
|
+
let leaderboard = require("./leaderboard");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {Discord.Message} message
|
|
5
|
-
* @param {import(
|
|
5
|
+
* @param {import("../index").chartsOptions} options
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
async function charts(message, options) {
|
|
9
9
|
try {
|
|
10
|
-
require(
|
|
10
|
+
require("canvas");
|
|
11
11
|
} catch {
|
|
12
|
-
throw
|
|
12
|
+
throw "[XP] This requires canvas to be installed. \n\"npm install canvas\"";
|
|
13
13
|
}
|
|
14
|
-
const ChartJS = require(
|
|
15
|
-
const Canvas = require(
|
|
14
|
+
const ChartJS = require("chart.js");
|
|
15
|
+
const Canvas = require("canvas");
|
|
16
16
|
let {client} = message;
|
|
17
17
|
|
|
18
18
|
let data = [];
|
|
@@ -30,30 +30,30 @@ async function charts(message, options) {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
new ChartJS(ctx, {
|
|
33
|
-
type: options.type ||
|
|
33
|
+
type: options.type || "bar",
|
|
34
34
|
data: {
|
|
35
35
|
labels: uzern,
|
|
36
36
|
datasets: [
|
|
37
37
|
{
|
|
38
|
-
label:
|
|
38
|
+
label: "Leaderboards",
|
|
39
39
|
data: data,
|
|
40
40
|
backgroundColor: [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
"rgba(255, 99, 132, 0.5)",
|
|
42
|
+
"rgba(255, 159, 64, 0.5)",
|
|
43
|
+
"rgba(255, 205, 86, 0.5)",
|
|
44
|
+
"rgba(75, 192, 192, 0.5)",
|
|
45
|
+
"rgba(54, 162, 235, 0.5)",
|
|
46
|
+
"rgba(153, 102, 255, 0.5)",
|
|
47
|
+
"rgb(201, 203, 207, 0.5)"
|
|
48
48
|
],
|
|
49
49
|
borderColor: [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
"rgb(255, 99, 132)",
|
|
51
|
+
"rgb(255, 159, 64)",
|
|
52
|
+
"rgb(255, 205, 86)",
|
|
53
|
+
"rgb(75, 192, 192)",
|
|
54
|
+
"rgb(54, 162, 235)",
|
|
55
|
+
"rgb(153, 102, 255)",
|
|
56
|
+
"rgb(201, 203, 207)"
|
|
57
57
|
],
|
|
58
58
|
borderWidth: 2
|
|
59
59
|
}
|
|
@@ -64,18 +64,18 @@ async function charts(message, options) {
|
|
|
64
64
|
plugins: {
|
|
65
65
|
title: {
|
|
66
66
|
display: true,
|
|
67
|
-
text:
|
|
67
|
+
text: "XP Datasheet"
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
plugins: [
|
|
72
72
|
{
|
|
73
|
-
id:
|
|
73
|
+
id: "simply-xp",
|
|
74
74
|
beforeDraw: (chart) => {
|
|
75
|
-
const ctx = chart.canvas.getContext(
|
|
75
|
+
const ctx = chart.canvas.getContext("2d");
|
|
76
76
|
ctx.save();
|
|
77
|
-
ctx.globalCompositeOperation =
|
|
78
|
-
ctx.fillStyle = options.background ||
|
|
77
|
+
ctx.globalCompositeOperation = "destination-over";
|
|
78
|
+
ctx.fillStyle = options.background || "#2F3136";
|
|
79
79
|
ctx.fillRect(0, 0, chart.width, chart.height);
|
|
80
80
|
ctx.restore();
|
|
81
81
|
}
|
|
@@ -84,8 +84,8 @@ async function charts(message, options) {
|
|
|
84
84
|
}).update();
|
|
85
85
|
|
|
86
86
|
return {
|
|
87
|
-
attachment: ctx.toBuffer(
|
|
88
|
-
name:
|
|
87
|
+
attachment: ctx.toBuffer("image/png"),
|
|
88
|
+
name: "chart.png"
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
|
package/src/connect.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
const mongoose = require(
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} db
|
|
5
|
-
* @param {import(
|
|
5
|
+
* @param {import("../index").connectOptions} options
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
async function connect(db, options = []) {
|
|
9
|
-
if (!db) throw new Error(
|
|
10
|
-
mongoose.set(
|
|
11
|
-
|
|
9
|
+
if (!db) throw new Error("[XP] Database URL was not provided");
|
|
10
|
+
mongoose.set("strictQuery", true);
|
|
11
|
+
|
|
12
12
|
mongoose.connect(db, {
|
|
13
13
|
useNewUrlParser: true,
|
|
14
14
|
useUnifiedTopology: true
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
if (options.notify
|
|
19
|
-
else return console.log('{ XP } Database Connected');
|
|
18
|
+
if (options.notify) return console.log("{ XP } Database Connected");
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
module.exports = connect;
|
package/src/create.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const levels = require(
|
|
1
|
+
const levels = require("../src/models/level.js");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} userID
|
|
@@ -6,11 +6,11 @@ const levels = require('../src/models/level.js');
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
async function create(userID, guildID) {
|
|
9
|
-
if (!userID) throw new Error(
|
|
9
|
+
if (!userID) throw new Error("[XP] User ID was not provided.");
|
|
10
10
|
|
|
11
|
-
if (!guildID) throw new Error(
|
|
11
|
+
if (!guildID) throw new Error("[XP] User ID was not provided.");
|
|
12
12
|
|
|
13
|
-
let uzer = await levels.findOne({
|
|
13
|
+
let uzer = await levels.findOne({user: userID, guild: guildID});
|
|
14
14
|
|
|
15
15
|
if (uzer) return;
|
|
16
16
|
|
|
@@ -20,7 +20,7 @@ async function create(userID, guildID) {
|
|
|
20
20
|
});
|
|
21
21
|
await newuser
|
|
22
22
|
.save()
|
|
23
|
-
.catch(() => console.log(
|
|
23
|
+
.catch(() => console.log("[XP] Failed to save new use to database"));
|
|
24
24
|
|
|
25
25
|
return true;
|
|
26
26
|
}
|
package/src/fetch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const levels = require(
|
|
1
|
+
const levels = require("../src/models/level.js");
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {string} userID
|
|
@@ -6,9 +6,9 @@ const levels = require('../src/models/level.js');
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
async function fetch(userID, guildID) {
|
|
9
|
-
if (!userID) throw new Error(
|
|
9
|
+
if (!userID) throw new Error("[XP] User ID was not provided.");
|
|
10
10
|
|
|
11
|
-
if (!guildID) throw new Error(
|
|
11
|
+
if (!guildID) throw new Error("[XP] Guild ID was not provided.");
|
|
12
12
|
|
|
13
13
|
let user = await levels.findOne({
|
|
14
14
|
user: userID,
|
|
@@ -29,7 +29,7 @@ async function fetch(userID, guildID) {
|
|
|
29
29
|
.find({
|
|
30
30
|
guild: guildID
|
|
31
31
|
})
|
|
32
|
-
.sort([[
|
|
32
|
+
.sort([["xp", "descending"]])
|
|
33
33
|
.exec();
|
|
34
34
|
|
|
35
35
|
if (user === null)
|
|
@@ -49,7 +49,7 @@ async function fetch(userID, guildID) {
|
|
|
49
49
|
let target = targetxp * targetxp * 100;
|
|
50
50
|
|
|
51
51
|
function shortener(count) {
|
|
52
|
-
const COUNT_ABBRS = [
|
|
52
|
+
const COUNT_ABBRS = ["", "k", "M", "T"];
|
|
53
53
|
|
|
54
54
|
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
55
55
|
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2));
|
package/src/leaderboard.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const levels = require(
|
|
1
|
+
const levels = require("../src/models/level.js");
|
|
2
|
+
const {options} = require("../simplyxp");
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @param {Discord.Client} client
|
|
@@ -7,17 +8,17 @@ const levels = require('../src/models/level.js');
|
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
async function leaderboard(client, guildID, limit) {
|
|
10
|
-
if (!guildID) throw new Error(
|
|
11
|
+
if (!guildID) throw new Error("[XP] Guild ID was not provided.");
|
|
11
12
|
|
|
12
13
|
let g = client.guilds.cache.get(guildID);
|
|
13
|
-
if (!g) throw new Error(
|
|
14
|
+
if (!g) throw new Error("[XP] Guild was not found.");
|
|
14
15
|
|
|
15
|
-
let leaderboard = await levels.find({guild: guildID}).sort([[
|
|
16
|
+
let leaderboard = await levels.find({guild: guildID}).sort([["xp", "descending"]]);
|
|
16
17
|
|
|
17
18
|
let led = [];
|
|
18
19
|
|
|
19
20
|
function shortener(count) {
|
|
20
|
-
const COUNT_ABBRS = [
|
|
21
|
+
const COUNT_ABBRS = ["", "k", "M", "T"];
|
|
21
22
|
|
|
22
23
|
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
23
24
|
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2));
|
|
@@ -27,13 +28,11 @@ async function leaderboard(client, guildID, limit) {
|
|
|
27
28
|
|
|
28
29
|
const led2 = leaderboard.map(async (key) => {
|
|
29
30
|
const user = await g.members.fetch(key.user).catch(() => null);
|
|
30
|
-
if (!user) return levels.deleteOne({user: key.user, guild: guildID});
|
|
31
|
+
if (!user && options.auto_purge) return levels.deleteOne({user: key.user, guild: guildID});
|
|
31
32
|
if (key.xp === 0) return;
|
|
32
|
-
let pos = leaderboard.indexOf(key) + 1;
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
34
|
+
let pos = leaderboard.indexOf(key) + 1;
|
|
35
|
+
if (limit && pos > Number(limit)) return;
|
|
37
36
|
|
|
38
37
|
led.push({
|
|
39
38
|
guildID: key.guild,
|