simply-xp 1.3.5-beta-7 → 2.0.0-dev.1
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 +69 -57
- package/lib/src/add.d.ts +28 -0
- package/lib/src/add.js +23 -0
- package/lib/src/cards.d.ts +91 -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 +26 -0
- package/lib/src/connect.js +47 -0
- package/lib/src/create.d.ts +12 -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 +12 -0
- package/lib/src/fetch.js +11 -0
- package/lib/src/functions/database.d.ts +111 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/utilities.d.ts +41 -0
- package/lib/src/functions/utilities.js +17 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +27 -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 +12 -0
- package/lib/src/reset.js +12 -0
- package/lib/src/roleSetup.d.ts +47 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +25 -0
- package/lib/src/set.js +23 -0
- package/lib/xp.d.ts +25 -0
- package/lib/xp.js +45 -0
- package/package.json +70 -53
- 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/index.d.ts +0 -107
- package/simplyxp.js +0 -31
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -104
- 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 -295
- 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,69 @@
|
|
|
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 `debug`, `auto_create`, `auto_purge` options for `connect()` function
|
|
45
|
+
- Added `db` class for extended database functionality
|
|
46
|
+
- Added `leaderboardCard()` function
|
|
47
|
+
- Added `coreFunctions()` 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`, and accepts `username` parameter
|
|
59
|
+
- `roleSetup` functions now accept roleID arrays! `["role1", "role2", "role3"]`, and will return `timestamp` as a bonus!
|
|
60
|
+
- `reset()` function now accepts `username` and `erase` as optional arguments
|
|
61
|
+
- `addLevel(), addXP(), setLevel(), setXP()` now has a `username` parameter, to automatically create the user if it doesn't exist.
|
|
62
|
+
|
|
63
|
+
# ⚠️ V2 Breaking Changes ⚠️
|
|
64
|
+
|
|
65
|
+
- `create()` Now requires `username` argument.
|
|
66
|
+
- `charts()` Requires new arguments.
|
|
67
|
+
- `rank()` is **deprecated**, use `rankCard()` instead.
|
|
68
|
+
- `rankCard()` Requires completely new arguments.
|
|
69
|
+
- `roleSetup()` functions loses `client` argument.
|
package/lib/src/add.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UserResult } from "./functions/database";
|
|
2
|
+
/**
|
|
3
|
+
* Add XP to a user
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {number} level
|
|
8
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
10
|
+
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/
|
|
13
|
+
export declare function addLevel(userId: string, guildId: string, level: number, username?: string): Promise<UserResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Add XP to a user.
|
|
16
|
+
* @async
|
|
17
|
+
* @param {string} userId - The ID of the user.
|
|
18
|
+
* @param {string} guildId - The ID of the guild.
|
|
19
|
+
* @param {number | {min: number, max: number}} xpData - The XP to add, can be a number or an object with min and max properties.
|
|
20
|
+
* @param {string} username - Username to use if auto_create is enabled.
|
|
21
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
22
|
+
* @returns {Promise<UserResult>} - Object of user data on success.
|
|
23
|
+
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addXP(userId: string, guildId: string, xpData: number | {
|
|
26
|
+
min: number;
|
|
27
|
+
max: number;
|
|
28
|
+
}, username?: string): Promise<UserResult>;
|
package/lib/src/add.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
10
|
+
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/async function addLevel(userId,guildId,level,username){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"});if(!level)throw new xplogs_1.XpFatal({function:"addLevel()",message:"Level was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(e)return 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,utilities_1.convert)("level",level+e.level)}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,utilities_1.convert)("level",level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"User does not exist"})}
|
|
13
|
+
/**
|
|
14
|
+
* Add XP to a user.
|
|
15
|
+
* @async
|
|
16
|
+
* @param {string} userId - The ID of the user.
|
|
17
|
+
* @param {string} guildId - The ID of the guild.
|
|
18
|
+
* @param {number | {min: number, max: number}} xpData - The XP to add, can be a number or an object with min and max properties.
|
|
19
|
+
* @param {string} username - Username to use if auto_create is enabled.
|
|
20
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
21
|
+
* @returns {Promise<UserResult>} - Object of user data on success.
|
|
22
|
+
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
23
|
+
*/async function addXP(userId,guildId,xpData,username){if(!("number"==typeof xpData||"object"==typeof xp_1.xp&&xpData.min&&xpData.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 xpData&&(xpData=Math.floor(Math.random()*(xpData.max-xpData.min)+xpData.min)),!userId)throw new xplogs_1.XpFatal({function:"addXP()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"addXP()",message:"Guild ID was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(e)return database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,utilities_1.convert)("xp",e.xp+xpData),xp:e.xp+xpData}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convert)("xp",xpData),xp:xpData}});throw new xplogs_1.XpFatal({function:"addXP()",message:"User does not exist"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.addXP=exports.addLevel=void 0;const utilities_1=require("./functions/utilities"),xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database"),xp_1=require("../xp");exports.addLevel=addLevel,exports.addXP=addXP;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { User } from "./leaderboard";
|
|
3
|
+
type HexColor = `#${string}` | `0x${string}`;
|
|
4
|
+
/**
|
|
5
|
+
* @property {[HexColor, HexColor]} artworkColors - Gradient colors
|
|
6
|
+
* @property {URL} artworkImage
|
|
7
|
+
* @property {[HexColor, HexColor]} borderColors - Gradient colors
|
|
8
|
+
* @property {HexColor} backgroundColor
|
|
9
|
+
* @property {URL} backgroundImage
|
|
10
|
+
* @property {string} font - ABSOLUTE FILE PATH
|
|
11
|
+
* @property {boolean} light - Use light theme
|
|
12
|
+
*/
|
|
13
|
+
export interface LeaderboardOptions {
|
|
14
|
+
artworkColors?: [HexColor, HexColor];
|
|
15
|
+
artworkImage?: URL;
|
|
16
|
+
borderColors?: [HexColor, HexColor];
|
|
17
|
+
backgroundColor?: HexColor;
|
|
18
|
+
backgroundImage?: URL;
|
|
19
|
+
font?: string;
|
|
20
|
+
light?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @property {URL} background - Background image URL
|
|
24
|
+
* @property {HexColor} color
|
|
25
|
+
* @property {boolean} legacy - Use legacy card design
|
|
26
|
+
* @property {HexColor} lvlbar
|
|
27
|
+
* @property {HexColor} lvlbarBg
|
|
28
|
+
* @property {string} font - ABSOLUTE FILE PATH
|
|
29
|
+
*/
|
|
30
|
+
export interface RankCardOptions {
|
|
31
|
+
background?: URL;
|
|
32
|
+
color?: HexColor;
|
|
33
|
+
legacy?: boolean;
|
|
34
|
+
lvlbar?: HexColor;
|
|
35
|
+
lvlbarBg?: HexColor;
|
|
36
|
+
font?: string;
|
|
37
|
+
}
|
|
38
|
+
export type UserOptions = {
|
|
39
|
+
id: string;
|
|
40
|
+
username: string;
|
|
41
|
+
avatarURL: string;
|
|
42
|
+
};
|
|
43
|
+
export type LeaderboardLocales = {
|
|
44
|
+
level?: string;
|
|
45
|
+
members?: string;
|
|
46
|
+
};
|
|
47
|
+
export type rankLocales = {
|
|
48
|
+
level?: string;
|
|
49
|
+
next_level?: string;
|
|
50
|
+
xp?: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Generate a simple user rank card
|
|
54
|
+
* @async
|
|
55
|
+
* @param {{id: string, name: string}} guild - (id, name)
|
|
56
|
+
* @param {UserOptions} user - (id, username, avatarURL)
|
|
57
|
+
* @param {RankCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
58
|
+
* @param {rankLocales?} locales - [BETA] Translate the rank card
|
|
59
|
+
* @link [Documentation](https://simplyxp.js.org/docs/rankCard)
|
|
60
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
61
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
62
|
+
*/
|
|
63
|
+
export declare function rankCard(guild: {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
}, user: UserOptions, options?: RankCardOptions, locales?: rankLocales): Promise<{
|
|
67
|
+
attachment: Buffer;
|
|
68
|
+
description: string;
|
|
69
|
+
name: string;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Generate a simple leaderboard card
|
|
73
|
+
* @async
|
|
74
|
+
* @param {Array<User>} data - Array of user data
|
|
75
|
+
* @param {LeaderboardOptions?} options - (artworkColor, artworkImage, light)
|
|
76
|
+
* @param {{name: string, imageURL: string, memberCount: number}?} guildInfo - Guild info
|
|
77
|
+
* @param {LeaderboardLocales} locales - Locales
|
|
78
|
+
* @link [Documentation](https://simplyxp.js.org/docs/leaderboard)
|
|
79
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
80
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
81
|
+
*/
|
|
82
|
+
export declare function leaderboardCard(data: Array<User>, options?: LeaderboardOptions, guildInfo?: {
|
|
83
|
+
name: string;
|
|
84
|
+
imageURL: string;
|
|
85
|
+
memberCount: number;
|
|
86
|
+
}, locales?: LeaderboardLocales): Promise<{
|
|
87
|
+
attachment: Buffer;
|
|
88
|
+
description: string;
|
|
89
|
+
name: string;
|
|
90
|
+
}>;
|
|
91
|
+
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");let o=await database_1.db.findOne({collection:"simply-xps",data:{guild:guild.id,user:user.id}});if(!o){if(!xp_1.xp.auto_create)throw new xplogs_1.XpFatal({function:"rankCard()",message:"User not found in database"});o=await(0,xp_1.create)(guild.id,user.id,user.username)}var t,r,l,n,d,i,s,c=(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;return options?.legacy?(t=user.username.replace(/[\u007f-\uffff]/g,""),r=options?.color||"#9900ff",l=options?.lvlbar||"#ffffff",options=options?.lvlbarBg||"#ffffff",s=shortener(o.xp)+(" "+locales.xp),n=locales.level+(" "+shortener(o.level)),d=(0,utilities_1.convert)("level",o.level+1),i=(0,utilities_1.convert)("level",o.level),i=100*(o.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("#"+c,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(o.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"}}
|
|
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"),utilities_1=require("./functions/utilities"),path_1=require("path"),xp_1=require("../xp");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,26 @@
|
|
|
1
|
+
export type ConnectionOptions = {
|
|
2
|
+
type: "mongodb" | "sqlite" | undefined;
|
|
3
|
+
auto_create?: boolean;
|
|
4
|
+
auto_purge?: boolean;
|
|
5
|
+
notify?: boolean;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Connect to a database (MongoDB, SQLite)
|
|
10
|
+
*
|
|
11
|
+
* @async
|
|
12
|
+
* @param {string} uri
|
|
13
|
+
* @param {ConnectionOptions} options
|
|
14
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
15
|
+
* @returns {Promise<boolean>}
|
|
16
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
17
|
+
*/
|
|
18
|
+
export declare function connect(uri: string, options?: ConnectionOptions): Promise<boolean | void>;
|
|
19
|
+
/**
|
|
20
|
+
* Check database package versions
|
|
21
|
+
* @private
|
|
22
|
+
* @param {"mongodb" | "sqlite"} type
|
|
23
|
+
* @returns {Promise<boolean>}
|
|
24
|
+
* @throws {XpFatal} If the package version is not supported
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkPackageVersion(type: "mongodb" | "sqlite"): Promise<boolean>;
|
|
@@ -0,0 +1,47 @@
|
|
|
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,{type:t,auto_create:o,auto_purge:r,notify:a,debug:n}=options;if(!uri)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===a&&(xp_1.xp.notify=!1),o&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_purge=!0),n&&(xp_1.xp.debug=!0),t||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),t){case"mongodb":if(e=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb"))return xplogs_1.XpLog.err("connect()","MongoDB V4 or higher is required");e=await e.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;break;case"sqlite":try{var[s,i]=await Promise.all([Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),checkPackageVersion("sqlite")]);if(!i)return xplogs_1.XpLog.err("connect()","better-sqlite3 V7 or higher is required");xp_1.xp.database=new s.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(t){if("object"==typeof t&&null!==t&&void 0!==(e=t).code&&"MODULE_NOT_FOUND"!==e.code)throw new xplogs_1.XpFatal({function:"connect()",message:e.message})}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 t=["yarn.lock","pnpm-lock.yaml","pnpm-lock.json","package-lock.json"].filter(lockfile=>e(lockfile));if(1===t.length){if("yarn.lock"===t[0])return xplogs_1.XpLog.debug("getPackageManager()","Using Yarn"),"yarn";if("pnpm-lock.yaml"===t[0]||"pnpm-lock.json"===t[0])return xplogs_1.XpLog.debug("getPackageManager()","Using PNPM"),"pnpm"}return xplogs_1.XpLog.debug("getPackageManager()","Using NPM"),"npm"}
|
|
41
|
+
/**
|
|
42
|
+
* Check database package versions
|
|
43
|
+
* @private
|
|
44
|
+
* @param {"mongodb" | "sqlite"} type
|
|
45
|
+
* @returns {Promise<boolean>}
|
|
46
|
+
* @throws {XpFatal} If the package version is not supported
|
|
47
|
+
*/async function checkPackageVersion(type){var e,t;switch(type){case"mongodb":try{return e=await Promise.resolve().then(()=>__importStar(require("mongodb/package.json"))),4<=parseInt(e.version.substring(0,1))}catch(e){return xplogs_1.XpLog.info("checkPackageVersion()","Installing MongoDB [5.x] | Please wait..."),(0,child_process_1.execSync)(await getPackageManager()+" add mongodb@5.x.x"),xplogs_1.XpLog.warn("checkPackageVersion()","Installed MongoDB. Please restart!"),process.exit(1)}case"sqlite":try{return t=await Promise.resolve().then(()=>__importStar(require("better-sqlite3/package.json"))),7<=parseInt(t.version.substring(0,1))}catch(e){return xplogs_1.XpLog.info("checkPackageVersion()","Installing better-sqlite3 [V8] | Please wait..."),(0,child_process_1.execSync)(await getPackageManager()+" add better-sqlite3@8.x.x"),xplogs_1.XpLog.warn("checkPackageVersion()","Installed better-sqlite3. Please restart!"),process.exit(1)}}}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.checkPackageVersion=exports.connect=void 0;const xplogs_1=require("./functions/xplogs"),child_process_1=require("child_process"),xp_1=require("../xp");exports.connect=connect,exports.checkPackageVersion=checkPackageVersion;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UserResult } from "./functions/database";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new user in the database
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {string} username
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
9
|
+
* @returns {Promise<UserResult>}
|
|
10
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
11
|
+
*/
|
|
12
|
+
export declare function create(userId: string, guildId: string, username: string): Promise<UserResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new user in the database
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {string} username
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
9
|
+
* @returns {Promise<UserResult>}
|
|
10
|
+
* @throws {XpFatal} If invalid parameters are provided
|
|
11
|
+
*/async function create(userId,guildId,username){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"});if(!username)throw new xplogs_1.XpFatal({function:"create()",message:"Username was not provided"});xplogs_1.XpLog.warn("create()","We just swapped userId with guildId again, this warning will be removed in the next DEV release.");var e=(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db;return await e.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}})}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,12 @@
|
|
|
1
|
+
import { User } from "./leaderboard";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch user data
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/fetch
|
|
9
|
+
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
10
|
+
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fetch(userId: string, guildId: string, username: string): Promise<User>;
|
package/lib/src/fetch.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch user data
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/fetch
|
|
9
|
+
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
10
|
+
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
11
|
+
*/async function fetch(userId,guildId,username){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=await(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db.find({collection:"simply-xps",data:{guild:guildId}}),t=e.find(u=>u.user===userId);if(t)return e=e.sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===userId)+1,{name:t?.name,user:t.user,guild:t.guild,level:t.level,position:e,xp:t.xp};if(xp_1.xp.auto_create&&username)return(await Promise.resolve().then(()=>__importStar(require("./create")))).create(guildId,userId,username);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"),xp_1=require("../xp");exports.fetch=fetch;
|