simply-xp 1.3.5-beta-6 → 2.0.0-dev.0-fix.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/FUNDING.yml +2 -2
- package/README.md +68 -57
- package/lib/src/add.d.ts +35 -0
- package/lib/src/add.js +21 -0
- package/lib/src/cards.d.ts +86 -0
- package/lib/src/cards.js +23 -0
- package/lib/src/charts.d.ts +17 -0
- package/lib/src/charts.js +10 -0
- package/lib/src/connect.d.ts +17 -0
- package/lib/src/connect.js +40 -0
- package/lib/src/create.d.ts +11 -0
- package/lib/src/create.js +11 -0
- package/lib/src/deprecated/rank.d.ts +18 -0
- package/lib/src/deprecated/rank.js +12 -0
- package/lib/src/fetch.d.ts +17 -0
- package/lib/src/fetch.js +10 -0
- package/lib/src/functions/convert.d.ts +10 -0
- package/lib/src/functions/convert.js +10 -0
- package/lib/src/functions/database.d.ts +90 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +18 -0
- package/lib/src/leaderboard.js +10 -0
- package/lib/src/migrate.d.ts +25 -0
- package/lib/src/migrate.js +19 -0
- package/lib/src/reset.d.ts +11 -0
- package/lib/src/reset.js +11 -0
- package/lib/src/roleSetup.d.ts +41 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +32 -0
- package/lib/src/set.js +21 -0
- package/lib/xp.d.ts +24 -0
- package/lib/xp.js +44 -0
- package/package.json +70 -50
- 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/index.d.ts +0 -107
- package/simplyxp.js +0 -31
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -103
- package/src/charts.js +0 -92
- package/src/connect.js +0 -22
- package/src/create.js +0 -28
- package/src/fetch.js +0 -74
- package/src/leaderboard.js +0 -52
- package/src/lvlRole.js +0 -53
- package/src/models/level.js +0 -10
- package/src/models/lvlrole.js +0 -8
- package/src/rank.js +0 -294
- package/src/reset.js +0 -22
- package/src/roleSetup.js +0 -121
- package/src/setLevel.js +0 -70
- package/src/setXP.js +0 -51
- /package/{src → lib/src}/Fonts/Baloo-Regular.ttf +0 -0
package/FUNDING.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
github: Rahuletto
|
|
2
|
-
patreon:
|
|
3
|
-
tidelift: npm/simply-xp
|
|
2
|
+
patreon: abadima
|
|
3
|
+
tidelift: npm/simply-xp
|
package/README.md
CHANGED
|
@@ -1,57 +1,68 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
<div class="Heading" style="text-align: center;">
|
|
2
|
+
<img src="https://i.ibb.co/cCKJ9FS/simplyxp.png" width="320" height="125" alt="XP Logo">
|
|
3
|
+
|
|
4
|
+
<h2>We have levelling! - You handle the rest.</h2>
|
|
5
|
+
<h3>Made by Abadima</h3>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<br>
|
|
9
|
+
<div class="badges" style="text-align: center;">
|
|
10
|
+
|
|
11
|
+
[](https://www.npmjs.com/package/simply-xp)
|
|
12
|
+
[](https://www.npmjs.com/package/simply-xp)
|
|
13
|
+
[](https://www.codefactor.io/repository/github/abadima/simply-xp)
|
|
14
|
+
|
|
15
|
+
[](https://simplyxp.js.org)
|
|
16
|
+
[](https://discord.gg/hjhnjYJNHX)
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
> CREDITS TO [RAHULETTO](https://github.com/rahuletto) FOR SIMPLY-XP **VERSION 1**
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<br>
|
|
24
|
+
|
|
25
|
+
## 🖥️ <b>[DEV] Installation</b>
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
npm install simply-xp@dev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
pnpm install simply-xp@dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
yarn add simply-xp@dev
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
<br>
|
|
40
|
+
|
|
41
|
+
# ✅ V2 Additions
|
|
42
|
+
|
|
43
|
+
- Added support for `SQLite` database
|
|
44
|
+
- Added `auto_purge` + `debug` option for `connect()` function
|
|
45
|
+
- Added `db` class for extended database functionality
|
|
46
|
+
- Added `leaderboardCard()` function
|
|
47
|
+
- Added `convert()` function
|
|
48
|
+
- Added `migrate` class
|
|
49
|
+
|
|
50
|
+
# 🎉 V2 Changes 🎉
|
|
51
|
+
|
|
52
|
+
- Better Documentation
|
|
53
|
+
- Better Log Handling (`XpDebug`, `XpError`, `XpInfo`, `XpWarn`)
|
|
54
|
+
- Better Performance
|
|
55
|
+
- Better Code Quality (EsLint)
|
|
56
|
+
- Complete TypeScript Rewrite
|
|
57
|
+
- Deleted `chart.js` dependency
|
|
58
|
+
- `fetch()` now also returns `position`
|
|
59
|
+
- `roleSetup` functions now accept roleID arrays! `["role1", "role2", "role3"]`
|
|
60
|
+
- `reset()` function now accepts "erase" as an optional argument
|
|
61
|
+
|
|
62
|
+
# ⚠️ V2 Breaking Changes ⚠️
|
|
63
|
+
|
|
64
|
+
- `create()` Requires new arguments.
|
|
65
|
+
- `charts()` Requires new arguments.
|
|
66
|
+
- `rank()` is **deprecated**, use `rankCard()` instead.
|
|
67
|
+
- `rankCard()` Requires completely new arguments.
|
|
68
|
+
- `roleSetup()` functions loses `client` argument.
|
package/lib/src/add.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add XP to a user
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} userId
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {number} level
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
8
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success
|
|
9
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
10
|
+
*/
|
|
11
|
+
export declare function addLevel(userId: string, guildId: string, level: number): Promise<{
|
|
12
|
+
user: string;
|
|
13
|
+
guild: string;
|
|
14
|
+
level: number;
|
|
15
|
+
xp: number;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Add XP to a user.
|
|
19
|
+
* @async
|
|
20
|
+
* @param {string} userId - The ID of the user.
|
|
21
|
+
* @param {string} guildId - The ID of the guild.
|
|
22
|
+
* @param {number | {min: number, max: number}} xp - The XP to add, can be a number or an object with min and max properties.
|
|
23
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
24
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success.
|
|
25
|
+
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
26
|
+
*/
|
|
27
|
+
export declare function addXP(userId: string, guildId: string, xp: number | {
|
|
28
|
+
min: number;
|
|
29
|
+
max: number;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
user: string;
|
|
32
|
+
guild: string;
|
|
33
|
+
level: number;
|
|
34
|
+
xp: number;
|
|
35
|
+
}>;
|
package/lib/src/add.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Add XP to a user
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {number} level
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
9
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success
|
|
10
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
11
|
+
*/async function addLevel(userId,guildId,level){if(!userId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"Guild ID was not provided"});var e;if(level)return(e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))?database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:e.level+level,xp:(0,convert_1.convert)("level",level+e.level)}}):database_1.db.createOne({collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,convert_1.convert)("level",level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"Level was not provided"})}
|
|
12
|
+
/**
|
|
13
|
+
* Add XP to a user.
|
|
14
|
+
* @async
|
|
15
|
+
* @param {string} userId - The ID of the user.
|
|
16
|
+
* @param {string} guildId - The ID of the guild.
|
|
17
|
+
* @param {number | {min: number, max: number}} xp - The XP to add, can be a number or an object with min and max properties.
|
|
18
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
19
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success.
|
|
20
|
+
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
21
|
+
*/async function addXP(userId,guildId,xp){if(!("number"==typeof xp||"object"==typeof xp&&xp.min&&xp.max))throw new xplogs_1.XpFatal({function:"addXP()",message:"XP is not a number or object, make sure you are using the correct syntax"});if("object"==typeof xp&&(xp=Math.floor(Math.random()*(xp.max-xp.min)+xp.min)),!userId)throw new xplogs_1.XpFatal({function:"addXP()",message:"User ID was not provided"});var e;if(guildId)return(e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))?database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,convert_1.convert)("xp",e.xp+xp),xp:e.xp+xp}}):database_1.db.createOne({collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,convert_1.convert)("xp",xp),xp:xp}});throw new xplogs_1.XpFatal({function:"addXP()",message:"Guild ID was not provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.addXP=exports.addLevel=void 0;const convert_1=require("./functions/convert"),xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database");exports.addLevel=addLevel,exports.addXP=addXP;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { User } from "./leaderboard";
|
|
3
|
+
type HexColor = `#${string}` | `0x${string}`;
|
|
4
|
+
/**
|
|
5
|
+
* @property artworkColors - [HEX, RGB, RGBA]
|
|
6
|
+
* @property borderColor - [HEX, RGB, RGBA]
|
|
7
|
+
* @property backgroundColor - [HEX, RGB, RGBA]
|
|
8
|
+
* @property artworkImage - [PNG, JPG, WEBP]
|
|
9
|
+
* @property font - ABSOLUTE FILE PATH
|
|
10
|
+
* @property light - Use light theme
|
|
11
|
+
*/
|
|
12
|
+
export type LeaderboardOptions = {
|
|
13
|
+
artworkColors?: [HexColor, HexColor];
|
|
14
|
+
artworkImage?: URL;
|
|
15
|
+
borderColors?: [HexColor, HexColor];
|
|
16
|
+
backgroundColor?: HexColor;
|
|
17
|
+
backgroundImage?: URL;
|
|
18
|
+
font?: string;
|
|
19
|
+
light?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @property background - [PNG, JPG, WEBP]
|
|
23
|
+
* @property font - ABSOLUTE FILE PATH
|
|
24
|
+
*/
|
|
25
|
+
export type RankCardOptions = {
|
|
26
|
+
background?: URL;
|
|
27
|
+
color?: HexColor;
|
|
28
|
+
legacy?: boolean;
|
|
29
|
+
lvlbar?: HexColor;
|
|
30
|
+
lvlbarBg?: HexColor;
|
|
31
|
+
font?: string;
|
|
32
|
+
};
|
|
33
|
+
export type UserOptions = {
|
|
34
|
+
id: string;
|
|
35
|
+
username: string;
|
|
36
|
+
avatarURL: string;
|
|
37
|
+
};
|
|
38
|
+
export type LeaderboardLocales = {
|
|
39
|
+
level?: string;
|
|
40
|
+
members?: string;
|
|
41
|
+
};
|
|
42
|
+
export type rankLocales = {
|
|
43
|
+
level?: string;
|
|
44
|
+
next_level?: string;
|
|
45
|
+
xp?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Generate a simple user rank card
|
|
49
|
+
* @async
|
|
50
|
+
* @param {{id: string, name: string}} guild - (id, name)
|
|
51
|
+
* @param {UserOptions} user - (id, username, avatarURL)
|
|
52
|
+
* @param {RankCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
53
|
+
* @param {rankLocales?} locales - [BETA] Translate the rank card
|
|
54
|
+
* @link [Documentation](https://simplyxp.js.org/docs/rankCard)
|
|
55
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
56
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
57
|
+
*/
|
|
58
|
+
export declare function rankCard(guild: {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
}, user: UserOptions, options?: RankCardOptions, locales?: rankLocales): Promise<{
|
|
62
|
+
attachment: Buffer;
|
|
63
|
+
description: string;
|
|
64
|
+
name: string;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Generate a simple leaderboard card
|
|
68
|
+
* @async
|
|
69
|
+
* @param {Array<User>} data - Array of user data
|
|
70
|
+
* @param {LeaderboardOptions?} options - (artworkColor, artworkImage, light)
|
|
71
|
+
* @param {{name: string, imageURL: string, memberCount: number}?} guildInfo - Guild info
|
|
72
|
+
* @param {LeaderboardLocales} locales - Locales
|
|
73
|
+
* @link [Documentation](https://simplyxp.js.org/docs/leaderboard)
|
|
74
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
75
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
76
|
+
*/
|
|
77
|
+
export declare function leaderboardCard(data: Array<User>, options?: LeaderboardOptions, guildInfo?: {
|
|
78
|
+
name: string;
|
|
79
|
+
imageURL: string;
|
|
80
|
+
memberCount: number;
|
|
81
|
+
}, locales?: LeaderboardLocales): Promise<{
|
|
82
|
+
attachment: Buffer;
|
|
83
|
+
description: string;
|
|
84
|
+
name: string;
|
|
85
|
+
}>;
|
|
86
|
+
export {};
|
package/lib/src/cards.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a simple user rank card
|
|
4
|
+
* @async
|
|
5
|
+
* @param {{id: string, name: string}} guild - (id, name)
|
|
6
|
+
* @param {UserOptions} user - (id, username, avatarURL)
|
|
7
|
+
* @param {RankCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
8
|
+
* @param {rankLocales?} locales - [BETA] Translate the rank card
|
|
9
|
+
* @link [Documentation](https://simplyxp.js.org/docs/rankCard)
|
|
10
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/async function rankCard(guild,user,options={},locales={}){if(!guild)throw new xplogs_1.XpFatal({function:"rankCard",message:"No Guild Provided"});if(!user)throw new xplogs_1.XpFatal({function:"rankCard",message:"No User Provided"});options.legacy=!0;let e,a;if(locales?.level||(locales.level="Level"),locales?.next_level||(locales.next_level="Next Level"),locales?.xp||(locales.xp="XP"),xplogs_1.XpLog.debug("rankCard","LEGACY MODE ENABLED"),xplogs_1.XpLog.info("rankCard","Modern RankCard is not supported yet, coming soon!"),!user?.avatarURL.endsWith(".png")&&!user.avatarURL.endsWith(".jpg")&&!user.avatarURL.endsWith(".webp"))throw new xplogs_1.XpFatal({function:"rankCard",message:"Invalid avatar image, avatar image must be a png, jpg, or webp"});if(!user||!user.id||!user.username)throw new xplogs_1.XpFatal({function:"rankCard",message:"Invalid User Provided, user must contain id, username, and avatarURL."});canvas_1.GlobalFonts.registerFromPath(options?.font||(0,path_1.join)(__dirname,"Fonts","Baloo-Regular.ttf"),"Sans Serif"),cachedRankImage=cachedRankImage||await(0,canvas_1.loadImage)(options?.background||"https://i.ibb.co/dck2Tnt/rank-card.webp");var o,t,r,l,n,d,i,s,c=await database_1.db.findOne({collection:"simply-xps",data:{guild:guild.id,user:user.id}});if(c)return o=(await database_1.db.find({collection:"simply-xps",data:{guild:guild.id}})).sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===user.id)+1,options?.legacy?(t=user.username.replace(/[\u007f-\uffff]/g,""),r=options?.color||"#9900ff",l=options?.lvlbar||"#ffffff",options=options?.lvlbarBg||"#ffffff",s=shortener(c.xp)+(" "+locales.xp),n=locales.level+(" "+shortener(c.level)),d=(0,convert_1.convert)("level",c.level+1),i=(0,convert_1.convert)("level",c.level),i=100*(c.xp-i)/(d-i)*660/100,cachedRankContext&&cachedRankCanvas?(e=cachedRankCanvas,a=cachedRankContext):(e=(0,canvas_1.createCanvas)(1080,400),RoundedBox(a=e.getContext("2d"),0,0,e.width,e.height,50),a.clip(),a.fillStyle="#000000",a.fillRect(0,0,1080,400),a.globalAlpha=.7,a.drawImage(cachedRankImage,-5,0,1090,400),a.restore(),a.fillStyle="#000000",a.globalAlpha=.4,a.fillRect(40,0,240,e.height),a.globalAlpha=1),a.save(),RoundedBox(a,70,30,180,180,50),a.strokeStyle=r,a.lineWidth=15,a.stroke(),a.clip(),a.drawImage(await(0,canvas_1.loadImage)(user.avatarURL),70,30,180,180),a.restore(),a.save(),RoundedBox(a,70,320,180,50,20),a.strokeStyle="#BFC85A22",a.stroke(),a.clip(),a.fillStyle=r,a.globalAlpha=1,a.fillRect(70,320,180,50),a.globalAlpha=1,a.fillStyle="#ffffff",a.textAlign="center",dynamicFont(a,s,160,358,160,32),a.restore(),a.save(),RoundedBox(a,70,240,180,50,20),a.strokeStyle="#BFC85A22",a.stroke(),a.clip(),a.fillStyle=r,a.globalAlpha=1,a.fillRect(70,240,180,50),a.globalAlpha=1,a.fillStyle="#ffffff",a.textAlign="center",dynamicFont(a,n,160,278,160,32),a.restore(),a.save(),a.textAlign="left",a.fillStyle="#ffffff",a.shadowColor="#000000",a.shadowBlur=15,a.shadowOffsetX=1,a.shadowOffsetY=1,a.font='39px "Sans Serif"',a.fillText(t,390,80),a.restore(),a.save(),a.textAlign="right",a.fillStyle="#ffffff",a.shadowColor="#000000",a.shadowBlur=15,a.shadowOffsetX=1,a.shadowOffsetY=1,a.font='55px "Sans Serif"',a.fillText("#"+o,e.width-55,80),a.restore(),a.save(),RoundedBox(a,390,305,660,70,Number(20)),a.strokeStyle="#BFC85A22",a.stroke(),a.clip(),a.fillStyle="#ffffff",a.textAlign="center",dynamicFont(a,guild.name,720,355,700,45),a.globalAlpha=.2,a.fillRect(390,305,660,70),a.restore(),a.save(),RoundedBox(a,390,145,660,50,20),a.strokeStyle="#BFC85A22",a.stroke(),a.clip(),a.fillStyle=options,a.globalAlpha=.2,a.fillRect(390,145,660,50),a.restore(),a.save(),RoundedBox(a,390,145,i,50,20),a.strokeStyle="#BFC85A22",a.stroke(),a.clip(),a.fillStyle=l,a.globalAlpha=.5,a.fillRect(390,145,i,50),a.restore(),a.save(),a.textAlign="left",a.fillStyle="#ffffff",a.globalAlpha=.8,a.font='30px "Sans Serif"',a.fillText(locales.next_level+": "+shortener(d)+" "+locales.xp,390,230),a.restore(),s="{current} / {needed}".replace(/{needed}/g,shortener(d)).replace(/{current}/g,shortener(c.xp)),a.textAlign="center",a.fillStyle="#474747",a.globalAlpha=1,a.font='30px "Sans Serif"',a.fillText(s,730,180)):e=(0,canvas_1.createCanvas)(1080,360),{attachment:e.toBuffer("image/png"),description:"Simply-XP Rank Card",name:"rank.png"};throw new xplogs_1.XpFatal({function:"rankCard",message:"User not found in database"})}
|
|
13
|
+
/**
|
|
14
|
+
* Generate a simple leaderboard card
|
|
15
|
+
* @async
|
|
16
|
+
* @param {Array<User>} data - Array of user data
|
|
17
|
+
* @param {LeaderboardOptions?} options - (artworkColor, artworkImage, light)
|
|
18
|
+
* @param {{name: string, imageURL: string, memberCount: number}?} guildInfo - Guild info
|
|
19
|
+
* @param {LeaderboardLocales} locales - Locales
|
|
20
|
+
* @link [Documentation](https://simplyxp.js.org/docs/leaderboard)
|
|
21
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
22
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
23
|
+
*/async function leaderboardCard(data,options={},guildInfo,locales={}){var e,a;if(!data||data.length<1)throw new xplogs_1.XpFatal({function:"leaderboardCard",message:"There must be at least 1 user in the data array"});!cachedLeaderboardArtwork&&options?.artworkImage&&(cachedLeaderboardArtwork=await(0,canvas_1.loadImage)(options.artworkImage)),!cachedLeaderboardImage&&options?.backgroundImage&&(cachedLeaderboardImage=await(0,canvas_1.loadImage)(options.backgroundImage)),locales.level||(locales.level="LEVEL"),locales.members||(locales.members="Members"),data=data.slice(0,8);let o,t,r,l=(r=options?.light?{artworkColors:options?.artworkColors||["#374bff","#5f69ff"],backgroundColor:"#f0f0eb",borderColors:options?.borderColors||["#ffa237","#ffcc6b"],evenColor:"#dcdcdc",oddColor:"#c8c8c8",primaryTextColor:"#000000",secondaryTextColor:"rgba(0,0,0,0.5)"}:{artworkColors:options?.artworkColors||["#374bff","#333793"],backgroundColor:"#141414",borderColors:options?.borderColors||["#ffa237","#b67125"],evenColor:"#1e1e1e",oddColor:"#282828",primaryTextColor:"#ffffff",secondaryTextColor:"rgba(255,255,255,0.5)"},cachedLeaderboardCanvas&&cachedLeaderboardContext?(o=cachedLeaderboardCanvas,t=cachedLeaderboardContext):(o=(0,canvas_1.createCanvas)(1350,1080),RoundedBox(t=o.getContext("2d"),0,0,o.width,o.height,20),t.clip(),(e=t.createLinearGradient(0,0,o.width,0)).addColorStop(0,r.artworkColors[0]),e.addColorStop(1,r.artworkColors[1]),t.fillStyle=e,t.fillRect(0,0,o.width,220),cachedLeaderboardArtwork&&(t.fillStyle="#000000",t.fillRect(0,0,o.width,220),t.globalAlpha=.5,t.drawImage(cachedLeaderboardArtwork,0,0,o.width,220),t.globalAlpha=1),t.fillStyle=options.backgroundColor||r.backgroundColor,t.fillRect(0,220,o.width,1080),cachedLeaderboardImage&&(t.globalAlpha=.9,t.drawImage(cachedLeaderboardImage,0,220,o.width,1080),t.globalAlpha=1)),guildInfo&&guildInfo?.imageURL&&guildInfo?.name&&guildInfo?.memberCount&&(e=await(0,canvas_1.loadImage)(guildInfo.imageURL),t.save(),t.beginPath(),t.arc(150,110,90,0,2*Math.PI,!0),t.closePath(),t.clip(),t.drawImage(e,60,20,180,180),t.restore(),(options=t.createLinearGradient(0,0,0,220)).addColorStop(0,r.borderColors[0]),options.addColorStop(1,r.borderColors[1]),t.strokeStyle=options,t.lineWidth=10,t.beginPath(),t.arc(150,110,90,0,2*Math.PI,!0),t.stroke(),t.fillStyle=r.primaryTextColor,t.font='60px "Sans Serif"',t.fillText(guildInfo.name,270,110),t.fillStyle=r.secondaryTextColor,t.font='40px "Sans Serif"',t.fillText(guildInfo.memberCount+" "+locales.members,270,160)),r.evenColor);for(let e=0;e<data.length;e++)a=300+90*e,1===data.length?RoundedBox(t,30,a,1290,90,20):0===e?RoundedBox(t,30,a,1290,90,20,{top:!0,bottom:!1}):e===data.length-1?RoundedBox(t,30,a,1290,90,20,{top:!1,bottom:!0}):RoundedBox(t,30,a,1290,90,0),t.fillStyle=l,t.globalAlpha=cachedLeaderboardImage?.5:1,t.fill(),t.globalAlpha=1,t.textAlign="left",t.font='30px "Sans Serif"',t.fillStyle=r.secondaryTextColor,t.fillText(e+1+".",60,55+a),t.textAlign="left",t.font='40px "Sans Serif"',t.fillStyle=r.primaryTextColor,t.fillText(data[e]?.name||data[e]?.user||"???",120,60+a),t.textAlign="right",t.font='30px "Sans Serif"',t.fillStyle=r.primaryTextColor,t.fillText(shortener(data[e]?.level)||"???",1270,55+a),t.fillStyle=r.secondaryTextColor,t.fillText(locales.level,1270-t.measureText(shortener(data[e]?.level)||"???").width-15,55+a),l=l===r.evenColor?r.oddColor:r.evenColor;return{attachment:o.toBuffer("image/png"),description:"Simply-XP Leaderboard Card",name:"leaderboard.png"}}function RoundedBox(ctx,x,y,width,height,radius,roundCorners={top:!0,bottom:!0}){ctx.beginPath(),ctx.moveTo(x+(roundCorners.top?radius:0),y),ctx.lineTo(x+width-(roundCorners.top?radius:0),y),roundCorners.top&&ctx.quadraticCurveTo(x+width,y,x+width,y+radius),ctx.lineTo(x+width,y+height-(roundCorners.bottom?radius:0)),roundCorners.bottom&&ctx.quadraticCurveTo(x+width,y+height,x+width-radius,y+height),ctx.lineTo(x+(roundCorners.bottom?radius:0),y+height),roundCorners.bottom&&ctx.quadraticCurveTo(x,y+height,x,y+height-radius),ctx.lineTo(x,y+(roundCorners.top?radius:0)),roundCorners.top&&ctx.quadraticCurveTo(x,y,x+radius,y),ctx.closePath()}function shortener(count){var e,a=["","k","M","B","T","Qa","Qi","Sx","Sp"];return count&&0!==count?count===1/0?"∞":(e=Math.floor(Math.log(count)/Math.log(1e3)),a.length<=e?count.toFixed(0)+a[a.length-1]:(count/Math.pow(1e3,e)).toFixed(0===e?0:2)+a[e]):"0"}function dynamicFont(context,text,x,y,maxWidth,maxSize){let e=maxSize;for(;0<e&&(context.font=e+'px "Sans Serif"',!(context.measureText(text).width<maxWidth));)e--;context.textAlign="center",context.fillText(text,x,y)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.leaderboardCard=exports.rankCard=void 0;const canvas_1=require("@napi-rs/canvas"),xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database"),convert_1=require("./functions/convert"),path_1=require("path");let cachedRankImage,cachedRankCanvas,cachedRankContext,cachedLeaderboardArtwork,cachedLeaderboardCanvas,cachedLeaderboardContext,cachedLeaderboardImage;exports.rankCard=rankCard,exports.leaderboardCard=leaderboardCard;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type HexColor = `#${string}` | `0x${string}`;
|
|
2
|
+
export interface ChartOptions {
|
|
3
|
+
backgroundColor?: HexColor;
|
|
4
|
+
limit?: number;
|
|
5
|
+
type?: "bar" | "line" | "pie" | "doughnut" | "radar" | "polarArea";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a chart
|
|
9
|
+
* @async
|
|
10
|
+
* @param {string} guildId
|
|
11
|
+
* @param {ChartOptions?} options
|
|
12
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/charts
|
|
13
|
+
* @returns {Promise<void>}
|
|
14
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
15
|
+
*/
|
|
16
|
+
export declare function charts(guildId: string, options?: ChartOptions): Promise<void>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a chart
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {ChartOptions?} options
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/charts
|
|
8
|
+
* @returns {Promise<void>}
|
|
9
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
10
|
+
*/async function charts(guildId,options={}){if(!guildId)throw new xplogs_1.XpFatal({function:"charts()",message:"No Guild ID Provided"});if(options)throw options.limit&&10<options.limit&&(options.limit=10),options.type||(options.type="bar"),new xplogs_1.XpFatal({function:"charts()",message:"[V2] Under Development | Should be here within 2-3 dev releases."});throw new xplogs_1.XpFatal({function:"charts()",message:"No Options Provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.charts=void 0;const xplogs_1=require("./functions/xplogs");exports.charts=charts;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ConnectionOptions = {
|
|
2
|
+
type: "mongodb" | "sqlite" | undefined;
|
|
3
|
+
auto_purge?: false | unknown;
|
|
4
|
+
notify?: boolean;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Connect to a database (MongoDB, SQLite)
|
|
9
|
+
*
|
|
10
|
+
* @async
|
|
11
|
+
* @param {string} uri
|
|
12
|
+
* @param {ConnectionOptions} options
|
|
13
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
14
|
+
* @returns {Promise<boolean>}
|
|
15
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
16
|
+
*/
|
|
17
|
+
export declare function connect(uri: string, options?: ConnectionOptions): Promise<boolean | void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Connect to a database (MongoDB, SQLite)
|
|
4
|
+
*
|
|
5
|
+
* @async
|
|
6
|
+
* @param {string} uri
|
|
7
|
+
* @param {ConnectionOptions} options
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
9
|
+
* @returns {Promise<boolean>}
|
|
10
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
|
+
*/async function connect(uri,options={type:void 0}){var e,o,t,{type:n,auto_purge:r,notify:a,debug:i}=options;if(!uri)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===a&&(xp_1.xp.notify=!1),r&&(xp_1.xp.auto_purge=!0),i&&(xp_1.xp.debug=!0),n||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),n){case"mongodb":try{if(t=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!(await Promise.resolve().then(()=>__importStar(require("mongodb/package.json")))).version.startsWith("5"))return xplogs_1.XpLog.err("connect()","MongoDB V5 is required");e=await t.connect(uri).catch(error=>{throw new xplogs_1.XpFatal({function:"connect()",message:error.message})}),xp_1.xp.dbType="mongodb",xp_1.xp.database=e||void 0}catch(e){xplogs_1.XpLog.info("connect()","Installing MongoDB [5.x] | Please wait..."),(0,child_process_1.execSync)(await getPackageManager()+" add mongodb@5.x.x"),xplogs_1.XpLog.warn("connect()","Installed MongoDB. Please restart!"),process.exit(1)}break;case"sqlite":try{if(o=await Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),!(await Promise.resolve().then(()=>__importStar(require("better-sqlite3/package.json")))).version.startsWith("8"))return xplogs_1.XpLog.err("connect()","SQLite V8 is required");xp_1.xp.database=new o.default(uri),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xps"
|
|
12
|
+
(
|
|
13
|
+
user
|
|
14
|
+
TEXT
|
|
15
|
+
UNIQUE,
|
|
16
|
+
guild
|
|
17
|
+
TEXT,
|
|
18
|
+
xp
|
|
19
|
+
INTEGER
|
|
20
|
+
DEFAULT
|
|
21
|
+
0,
|
|
22
|
+
level
|
|
23
|
+
INTEGER
|
|
24
|
+
DEFAULT
|
|
25
|
+
0
|
|
26
|
+
)`),xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xp-levelroles"
|
|
27
|
+
(
|
|
28
|
+
gid
|
|
29
|
+
TEXT
|
|
30
|
+
UNIQUE,
|
|
31
|
+
lvlrole
|
|
32
|
+
TEXT
|
|
33
|
+
NOT
|
|
34
|
+
NULL
|
|
35
|
+
)`)}catch(e){if("object"==typeof e&&null!==e&&void 0!==(t=e).code&&"MODULE_NOT_FOUND"!==t.code)throw new xplogs_1.XpFatal({function:"connect()",message:t.message});xplogs_1.XpLog.info("connect()","Installing better-sqlite3 [V8]..."),(0,child_process_1.execSync)(await getPackageManager()+" add better-sqlite3@8.x.x"),xplogs_1.XpLog.warn("connect()","Installed better-sqlite3. | Please reboot!"),process.exit(0)}break;default:throw new xplogs_1.XpFatal({function:"connect()",message:"DATABASE TYPE NOT PROVIDED OR INVALID"})}return!!xp_1.xp.database&&(xplogs_1.XpLog.info("connect()","Connected to database!"),!0)}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the package manager used
|
|
38
|
+
* @private
|
|
39
|
+
* @returns {Promise<"yarn" | "npm" | "pnpm">}
|
|
40
|
+
*/async function getPackageManager(){const e=(await Promise.resolve().then(()=>__importStar(require("fs")))).existsSync;var o=["yarn.lock","pnpm-lock.yaml","pnpm-lock.json","package-lock.json"].filter(lockfile=>e(lockfile));if(1===o.length){if("yarn.lock"===o[0])return xplogs_1.XpLog.debug("getPackageManager()","Using Yarn"),"yarn";if("pnpm-lock.yaml"===o[0]||"pnpm-lock.json"===o[0])return xplogs_1.XpLog.debug("getPackageManager()","Using PNPM"),"pnpm"}return xplogs_1.XpLog.debug("getPackageManager()","Using NPM"),"npm"}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,o;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(o in mod)"default"!==o&&Object.prototype.hasOwnProperty.call(mod,o)&&__createBinding(e,mod,o);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.connect=void 0;const xplogs_1=require("./functions/xplogs"),child_process_1=require("child_process"),xp_1=require("../xp");exports.connect=connect;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new user in the database
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} guildId
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} username
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
8
|
+
* @returns {Promise<object>}
|
|
9
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
10
|
+
*/
|
|
11
|
+
export declare function create(guildId: string, userId: string, username: string): Promise<object>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new user in the database
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {string} userId
|
|
7
|
+
* @param {string} username
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
9
|
+
* @returns {Promise<object>}
|
|
10
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
11
|
+
*/async function create(guildId,userId,username){if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});var e;if(username)return await(e=(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db).findOne({collection:"simply-xps",data:{user:userId,guild:guildId}})||e.createOne({collection:"simply-xps",data:{name:username,user:userId,guild:guildId,level:0,xp:0}});throw new xplogs_1.XpFatal({function:"create()",message:"Username was not provided"})}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,t;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(t in mod)"default"!==t&&Object.prototype.hasOwnProperty.call(mod,t)&&__createBinding(e,mod,t);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.create=void 0;const xplogs_1=require("./functions/xplogs");exports.create=create;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RankCardOptions } from "../cards";
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use rankCard() instead.
|
|
5
|
+
* Get user rank card
|
|
6
|
+
* @param {Message} message (DISCORD)
|
|
7
|
+
* @param {string} userId
|
|
8
|
+
* @param {string} _guildId
|
|
9
|
+
* @param {RankCardOptions?} options
|
|
10
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/deprecated/rank
|
|
11
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
12
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
13
|
+
*/
|
|
14
|
+
export declare function rank(message: import("discord.js").Message, userId: string, _guildId: string, options?: RankCardOptions): Promise<{
|
|
15
|
+
attachment: Buffer;
|
|
16
|
+
description: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use rankCard() instead.
|
|
4
|
+
* Get user rank card
|
|
5
|
+
* @param {Message} message (DISCORD)
|
|
6
|
+
* @param {string} userId
|
|
7
|
+
* @param {string} _guildId
|
|
8
|
+
* @param {RankCardOptions?} options
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/deprecated/rank
|
|
10
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/async function rank(message,userId,_guildId,options){var e;try{e=await Promise.resolve().then(()=>__importStar(require("discord.js/package.json"))),parseInt(e.version.split(".")[0])<13?xplogs_1.XpLog.warn("rank()","This may not work with Discord.JS v12 or below."):xplogs_1.XpLog.debug("rank()",`Discord.JS v${e.version} detected.`)}catch(e){throw new xplogs_1.XpFatal({function:"rank()",message:"This function requires Discord.JS, as it is only for Discord bots. | Use rankCard() instead."})}if(!message||!message?.guild)throw new xplogs_1.XpFatal({function:"rank()",message:"Invalid Message Provided"});if(!userId)throw new xplogs_1.XpFatal({function:"rank()",message:"No User ID Provided"});if(xplogs_1.XpLog.warn("rank()","DEPRECATED FUNCTION!! Please use rankCard() instead."),e=await message.guild.members.fetch(userId).catch(()=>null))return(0,cards_1.rankCard)({id:message.guild.id,name:message.guild.name},{id:e.id,username:e.user.username,avatarURL:e.user.displayAvatarURL()},options);throw new xplogs_1.XpFatal({function:"rank()",message:"Member not found"})}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,r;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(r in mod)"default"!==r&&Object.prototype.hasOwnProperty.call(mod,r)&&__createBinding(e,mod,r);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.rank=void 0;const xplogs_1=require("../functions/xplogs"),cards_1=require("../cards");exports.rank=rank;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch user data
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} userId
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/fetch
|
|
7
|
+
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
8
|
+
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetch(userId: string, guildId: string): Promise<{
|
|
11
|
+
name: string | null;
|
|
12
|
+
user: string;
|
|
13
|
+
guild: string;
|
|
14
|
+
level: number;
|
|
15
|
+
position: number;
|
|
16
|
+
xp: number;
|
|
17
|
+
}>;
|
package/lib/src/fetch.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch user data
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/fetch
|
|
8
|
+
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
9
|
+
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
10
|
+
*/async function fetch(userId,guildId){if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});var e=(guildId=await(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db.find({collection:"simply-xps",data:{guild:guildId}})).find(u=>u.user===userId);if(e)return guildId=guildId.sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===userId)+1,{name:e?.name||null,user:e.user,guild:e.guild,level:e.level,position:guildId,xp:e.xp};throw new xplogs_1.XpFatal({function:"fetch()",message:"User data not found"})}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,t;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(t in mod)"default"!==t&&Object.prototype.hasOwnProperty.call(mod,t)&&__createBinding(e,mod,t);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetch=void 0;const xplogs_1=require("./functions/xplogs");exports.fetch=fetch;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert XP to level and vice versa.
|
|
3
|
+
*
|
|
4
|
+
* @param {"xp" | "level"} type - Type to convert from. Use either "xp" or "level".
|
|
5
|
+
* @param {number} value - Value to convert.
|
|
6
|
+
* @link https://simplyxp.js.org/docs/convert Documentation
|
|
7
|
+
* @returns {number} - The converted value. (XP to level or level to XP)
|
|
8
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare function convert(type: "xp" | "level", value: number): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Convert XP to level and vice versa.
|
|
4
|
+
*
|
|
5
|
+
* @param {"xp" | "level"} type - Type to convert from. Use either "xp" or "level".
|
|
6
|
+
* @param {number} value - Value to convert.
|
|
7
|
+
* @link https://simplyxp.js.org/docs/convert Documentation
|
|
8
|
+
* @returns {number} - The converted value. (XP to level or level to XP)
|
|
9
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
10
|
+
*/function convert(type,value){if("xp"===type||"level"===type){if(!value)throw new xplogs_1.XpFatal({function:"convert()",message:"Value was not provided"});if("level"===type)return Math.pow(value/.1,2);if("xp"===type)return Math.floor(.1*Math.sqrt(value))}throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.convert=void 0;const xplogs_1=require("./xplogs");exports.convert=convert;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export type UserOptions = {
|
|
2
|
+
collection: "simply-xps";
|
|
3
|
+
data: {
|
|
4
|
+
guild: string;
|
|
5
|
+
user?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
level?: number;
|
|
8
|
+
xp?: number;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type UserResult = {
|
|
12
|
+
_id?: string;
|
|
13
|
+
user: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
guild: string;
|
|
16
|
+
level: number;
|
|
17
|
+
xp: number;
|
|
18
|
+
};
|
|
19
|
+
export type LevelRoleOptions = {
|
|
20
|
+
collection: "simply-xp-levelroles";
|
|
21
|
+
data: {
|
|
22
|
+
guild: string;
|
|
23
|
+
level?: number;
|
|
24
|
+
roles?: string | Array<string>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type LevelRoleResult = {
|
|
28
|
+
_id?: string;
|
|
29
|
+
guild: string;
|
|
30
|
+
level: number;
|
|
31
|
+
roles: Array<string>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Database class providing methods to interact with the database.
|
|
35
|
+
* @class db
|
|
36
|
+
*/
|
|
37
|
+
export declare class db {
|
|
38
|
+
/**
|
|
39
|
+
* Creates one document in the database.
|
|
40
|
+
*
|
|
41
|
+
* @async
|
|
42
|
+
* @param {UserOptions | LevelRoleOptions} query - The document to create.
|
|
43
|
+
* @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
|
|
44
|
+
* @returns {Promise<UserResult | LevelRoleResult>} The created document.
|
|
45
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
46
|
+
*/
|
|
47
|
+
static createOne(query: UserOptions | LevelRoleOptions): Promise<UserResult | LevelRoleResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Deletes one document from the database.
|
|
50
|
+
*
|
|
51
|
+
* @async
|
|
52
|
+
* @param {UserOptions | LevelRoleOptions} query - The document to delete.
|
|
53
|
+
* @link https://simplyxp.js.org/docs/handlers/database#deleteOne Documentation
|
|
54
|
+
* @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
|
|
55
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
56
|
+
*/
|
|
57
|
+
static deleteOne(query: UserOptions | LevelRoleOptions): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Finds one document in the database.
|
|
60
|
+
*
|
|
61
|
+
* @async
|
|
62
|
+
* @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
|
|
63
|
+
* @link https://simplyxp.js.org/docs/handlers/database#findOne Documentation
|
|
64
|
+
* @returns {Promise<UserResult | LevelRoleResult>} The found document.
|
|
65
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
66
|
+
*/
|
|
67
|
+
static findOne(query: UserOptions | LevelRoleOptions): Promise<UserResult | LevelRoleResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Finds multiple documents in the database.
|
|
70
|
+
*
|
|
71
|
+
* @async
|
|
72
|
+
* @param {UserOptions | LevelRoleOptions} query - The query to search for multiple documents.
|
|
73
|
+
* @link https://simplyxp.js.org/docs/handlers/database#find Documentation
|
|
74
|
+
* @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
|
|
75
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
76
|
+
*/
|
|
77
|
+
static find(query: UserOptions | LevelRoleOptions): Promise<UserResult[] | LevelRoleResult[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Updates one document in the database.
|
|
80
|
+
*
|
|
81
|
+
* @async
|
|
82
|
+
* @param {UserOptions | LevelRoleOptions} filter - The document to update.
|
|
83
|
+
* @param {UserOptions | LevelRoleOptions} update - The document update data.
|
|
84
|
+
* @param {object} [options] - MongoDB options for updating the document.
|
|
85
|
+
* @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
|
|
86
|
+
* @returns {Promise<UserResult | LevelRoleResult>} The updated document.
|
|
87
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
88
|
+
*/
|
|
89
|
+
static updateOne(filter: UserOptions | LevelRoleOptions, update: UserOptions | LevelRoleOptions, options?: object): Promise<UserResult | LevelRoleResult>;
|
|
90
|
+
}
|