simply-xp 2.0.0-dev.3-fix.2 → 2.0.0-dev.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 +4 -4
- package/lib/src/Fonts/BalooBhaijaan-Regular.woff2 +0 -0
- package/lib/src/add.d.ts +2 -2
- package/lib/src/add.js +4 -6
- package/lib/src/cards.d.ts +75 -25
- package/lib/src/cards.js +23 -11
- package/lib/src/charts.d.ts +19 -9
- package/lib/src/charts.js +4 -5
- package/lib/src/connect.d.ts +5 -3
- package/lib/src/connect.js +9 -9
- package/lib/src/create.d.ts +1 -1
- package/lib/src/create.js +2 -3
- package/lib/src/deprecated/rank.d.ts +1 -1
- package/lib/src/deprecated/rank.js +2 -3
- package/lib/src/fetch.d.ts +3 -3
- package/lib/src/fetch.js +3 -4
- package/lib/src/functions/database.d.ts +15 -6
- package/lib/src/functions/database.js +17 -10
- package/lib/src/functions/utilities.d.ts +2 -2
- package/lib/src/functions/utilities.js +4 -6
- package/lib/src/leaderboard.d.ts +2 -2
- package/lib/src/leaderboard.js +2 -3
- package/lib/src/migrate.d.ts +2 -2
- package/lib/src/migrate.js +4 -4
- package/lib/src/reset.d.ts +1 -1
- package/lib/src/reset.js +2 -3
- package/lib/src/roleSetup.d.ts +3 -4
- package/lib/src/roleSetup.js +3 -3
- package/lib/src/set.d.ts +2 -2
- package/lib/src/set.js +4 -6
- package/lib/xp.d.ts +1 -1
- package/lib/xp.js +5 -4
- package/package.json +19 -16
- package/lib/src/Fonts/Baloo-Regular.eot +0 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
[](https://www.npmjs.com/package/simply-xp)
|
|
13
13
|
[](https://www.codefactor.io/repository/github/abadima/simply-xp)
|
|
14
14
|
|
|
15
|
-
[](https://simplyxp.js.org)
|
|
15
|
+
[](https://simplyxp.js.org/docs/next/intro/)
|
|
16
16
|
[](https://discord.gg/hjhnjYJNHX)
|
|
17
17
|
</div>
|
|
18
18
|
|
|
@@ -45,6 +45,7 @@ yarn add simply-xp@dev
|
|
|
45
45
|
- Added `db` class for extended database functionality
|
|
46
46
|
- Added `leaderboardCard()` function
|
|
47
47
|
- Added `convertFrom()` function
|
|
48
|
+
- Added `compareCard` function
|
|
48
49
|
- Added `migrate` class
|
|
49
50
|
|
|
50
51
|
# 🎉 V2 Changes 🎉
|
|
@@ -63,8 +64,7 @@ yarn add simply-xp@dev
|
|
|
63
64
|
# ⚠️ V2 Breaking Changes ⚠️
|
|
64
65
|
|
|
65
66
|
- `create()` Now requires `username` argument.
|
|
66
|
-
- `charts()` Requires new arguments.
|
|
67
|
-
- `rank()` is **deprecated**, use `rankCard()` instead.
|
|
68
|
-
- `rankCard()` Requires completely new arguments.
|
|
67
|
+
- `charts()` Requires new arguments, and is revamped.
|
|
68
|
+
- `rank()` is **deprecated**, use `rankCard()` instead. (REQUIRES NEW ARGUMENTS)
|
|
69
69
|
- `roleSetup()` functions loses `client` argument.
|
|
70
70
|
- `leaderboard()` loses `client` argument, and returns `user` instead of `userID`
|
|
Binary file
|
package/lib/src/add.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { UserResult } from "./functions/database";
|
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {number} level
|
|
8
8
|
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addlevel
|
|
10
10
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
11
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
12
|
*/
|
|
@@ -25,7 +25,7 @@ interface XPResult extends UserResult {
|
|
|
25
25
|
* @param {string} guildId - The ID of the guild.
|
|
26
26
|
* @param {number | {min: number, max: number}} xpData - The XP to add, can be a number or an object with min and max properties.
|
|
27
27
|
* @param {string} username - Username to use if auto_create is enabled.
|
|
28
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
28
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addxp
|
|
29
29
|
* @returns {Promise<XPResult>} - Object of user data on success.
|
|
30
30
|
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
31
31
|
*/
|
package/lib/src/add.js
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {number} level
|
|
8
8
|
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/addlevel
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addlevel
|
|
10
10
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
11
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
-
*/
|
|
13
|
-
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(isNaN(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.convertFrom)(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.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"User does not exist"})}
|
|
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(isNaN(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.convertFrom)(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.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"User does not exist"})}
|
|
14
13
|
/**
|
|
15
14
|
* Add XP to a user.
|
|
16
15
|
* @async
|
|
@@ -18,8 +17,7 @@ async function addLevel(userId,guildId,level,username){if(!userId)throw new xplo
|
|
|
18
17
|
* @param {string} guildId - The ID of the guild.
|
|
19
18
|
* @param {number | {min: number, max: number}} xpData - The XP to add, can be a number or an object with min and max properties.
|
|
20
19
|
* @param {string} username - Username to use if auto_create is enabled.
|
|
21
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/addxp
|
|
20
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addxp
|
|
22
21
|
* @returns {Promise<XPResult>} - Object of user data on success.
|
|
23
22
|
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
24
|
-
*/
|
|
25
|
-
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}});let a;if(e)a=await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,utilities_1.convertFrom)(e.xp+xpData,"xp"),xp:e.xp+xpData}}).catch(err=>{throw new xplogs_1.XpFatal({function:"addXP()",message:err.stack})});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"addXP()",message:"User does not exist"});a=await database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convertFrom)(xpData,"xp"),xp:xpData}}).catch(err=>{throw new xplogs_1.XpFatal({function:"addXP()",message:err.stack})})}return{...a,hasLevelledUp:a.level>e.level}}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;
|
|
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}});let a;if(e)a=await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,utilities_1.convertFrom)(e.xp+xpData,"xp"),xp:e.xp+xpData}}).catch(err=>{throw new xplogs_1.XpFatal({function:"addXP()",message:err.stack})});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"addXP()",message:"User does not exist"});a=await database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convertFrom)(xpData,"xp"),xp:xpData}}).catch(err=>{throw new xplogs_1.XpFatal({function:"addXP()",message:err.stack})})}return{...a,hasLevelledUp:!e||a.level>e.level}}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;
|
package/lib/src/cards.d.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { SKRSContext2D } from "@napi-rs/canvas";
|
|
2
3
|
import { User } from "./leaderboard";
|
|
3
4
|
type HexColor = `#${string}` | `0x${string}`;
|
|
5
|
+
export type CompareCardLocales = {
|
|
6
|
+
level?: string;
|
|
7
|
+
versus?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @property {URL} background - Background image URL
|
|
11
|
+
* @property {HexColor} color - Avatar border color
|
|
12
|
+
* @property {HexColor} centerBar - Center bar color
|
|
13
|
+
* @property {HexColor} centerBarBg - Center bar background color
|
|
14
|
+
* @property {string} font - ABSOLUTE FILE PATH
|
|
15
|
+
* @property {boolean} light - Use light theme
|
|
16
|
+
*/
|
|
17
|
+
export interface CompareCardOptions {
|
|
18
|
+
background?: URL;
|
|
19
|
+
color?: HexColor;
|
|
20
|
+
centerBar?: HexColor;
|
|
21
|
+
centerBarBg?: HexColor;
|
|
22
|
+
font?: string;
|
|
23
|
+
light?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type LeaderboardCardLocales = {
|
|
26
|
+
level?: string;
|
|
27
|
+
members?: string;
|
|
28
|
+
};
|
|
4
29
|
/**
|
|
5
30
|
* @property {[HexColor, HexColor]} artworkColors - Gradient colors
|
|
6
31
|
* @property {URL} artworkImage
|
|
@@ -10,7 +35,7 @@ type HexColor = `#${string}` | `0x${string}`;
|
|
|
10
35
|
* @property {string} font - ABSOLUTE FILE PATH
|
|
11
36
|
* @property {boolean} light - Use light theme
|
|
12
37
|
*/
|
|
13
|
-
export interface
|
|
38
|
+
export interface LeaderboardCardOptions {
|
|
14
39
|
artworkColors?: [HexColor, HexColor];
|
|
15
40
|
artworkImage?: URL;
|
|
16
41
|
borderColors?: [HexColor, HexColor];
|
|
@@ -19,9 +44,14 @@ export interface LeaderboardOptions {
|
|
|
19
44
|
font?: string;
|
|
20
45
|
light?: boolean;
|
|
21
46
|
}
|
|
47
|
+
export type RankCardLocales = {
|
|
48
|
+
level?: string;
|
|
49
|
+
next_level?: string;
|
|
50
|
+
xp?: string;
|
|
51
|
+
};
|
|
22
52
|
/**
|
|
23
53
|
* @property {URL} background - Background image URL
|
|
24
|
-
* @property {HexColor} color
|
|
54
|
+
* @property {HexColor} color - Avatar border color
|
|
25
55
|
* @property {boolean} legacy - Use legacy card design
|
|
26
56
|
* @property {HexColor} lvlbar
|
|
27
57
|
* @property {HexColor} lvlbarBg
|
|
@@ -31,39 +61,32 @@ export interface RankCardOptions {
|
|
|
31
61
|
background?: URL;
|
|
32
62
|
color?: HexColor;
|
|
33
63
|
legacy?: boolean;
|
|
64
|
+
light?: boolean;
|
|
34
65
|
lvlbar?: HexColor;
|
|
35
66
|
lvlbarBg?: HexColor;
|
|
36
67
|
font?: string;
|
|
37
68
|
}
|
|
38
|
-
export type
|
|
69
|
+
export type CardUserOptions = {
|
|
39
70
|
id: string;
|
|
40
71
|
username: string;
|
|
41
72
|
avatarURL: string;
|
|
42
73
|
};
|
|
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
74
|
/**
|
|
53
|
-
* Generate a simple
|
|
75
|
+
* Generate a simple comparison card
|
|
54
76
|
* @async
|
|
55
77
|
* @param {{id: string, name: string}} guild - (id, name)
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {
|
|
59
|
-
* @
|
|
78
|
+
* @param {CardUserOptions} user1 - User 1
|
|
79
|
+
* @param {CardUserOptions} user2 - User 2
|
|
80
|
+
* @param {CompareCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
81
|
+
* @param {CompareCardLocales?} locales - [BETA] Translate the rank card
|
|
82
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/compareCard
|
|
60
83
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
61
|
-
* @throws {XpFatal} - If parameters are not provided correctly
|
|
84
|
+
* @throws {XpFatal} - If parameters are not provided correctly or if the user is not found in the database
|
|
62
85
|
*/
|
|
63
|
-
export declare function
|
|
86
|
+
export declare function compareCard(guild: {
|
|
64
87
|
id: string;
|
|
65
88
|
name: string;
|
|
66
|
-
},
|
|
89
|
+
}, user1: CardUserOptions, user2: CardUserOptions, options?: CompareCardOptions, locales?: CompareCardLocales): Promise<{
|
|
67
90
|
attachment: Buffer;
|
|
68
91
|
description: string;
|
|
69
92
|
name: string;
|
|
@@ -72,20 +95,47 @@ export declare function rankCard(guild: {
|
|
|
72
95
|
* Generate a simple leaderboard card
|
|
73
96
|
* @async
|
|
74
97
|
* @param {Array<User>} data - Array of user data
|
|
75
|
-
* @param {
|
|
98
|
+
* @param {LeaderboardCardOptions?} options - (artworkColor, artworkImage, light)
|
|
76
99
|
* @param {{name: string, imageURL: string, memberCount: number}?} guildInfo - Guild info
|
|
77
|
-
* @param {
|
|
78
|
-
* @link
|
|
100
|
+
* @param {LeaderboardCardLocales?} locales - Locales
|
|
101
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/leaderboard
|
|
79
102
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
80
103
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
81
104
|
*/
|
|
82
|
-
export declare function leaderboardCard(data: Array<User>, options?:
|
|
105
|
+
export declare function leaderboardCard(data: Array<User>, options?: LeaderboardCardOptions, guildInfo?: {
|
|
83
106
|
name: string;
|
|
84
107
|
imageURL: string;
|
|
85
108
|
memberCount: number;
|
|
86
|
-
}, locales?:
|
|
109
|
+
}, locales?: LeaderboardCardLocales): Promise<{
|
|
110
|
+
attachment: Buffer;
|
|
111
|
+
description: string;
|
|
112
|
+
name: string;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Generate a simple user rank card
|
|
116
|
+
* @async
|
|
117
|
+
* @param {{id: string, name: string}} guild - (id, name)
|
|
118
|
+
* @param {CardUserOptions} user - (id, username, avatarURL)
|
|
119
|
+
* @param {RankCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
120
|
+
* @param {RankCardLocales?} locales - [BETA] Translate the rank card
|
|
121
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/rankCard
|
|
122
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
123
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
124
|
+
*/
|
|
125
|
+
export declare function rankCard(guild: {
|
|
126
|
+
id: string;
|
|
127
|
+
name: string;
|
|
128
|
+
}, user: CardUserOptions, options?: RankCardOptions, locales?: RankCardLocales): Promise<{
|
|
87
129
|
attachment: Buffer;
|
|
88
130
|
description: string;
|
|
89
131
|
name: string;
|
|
90
132
|
}>;
|
|
133
|
+
/**
|
|
134
|
+
* @constructor
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
export declare function RoundedBox(ctx: SKRSContext2D, x: number, y: number, width: number, height: number, radius: number, strokeColor?: string, roundCorners?: {
|
|
138
|
+
top?: boolean;
|
|
139
|
+
bottom?: boolean;
|
|
140
|
+
}): void;
|
|
91
141
|
export {};
|
package/lib/src/cards.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Generate a simple
|
|
3
|
+
* Generate a simple comparison card
|
|
4
4
|
* @async
|
|
5
5
|
* @param {{id: string, name: string}} guild - (id, name)
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {
|
|
9
|
-
* @
|
|
6
|
+
* @param {CardUserOptions} user1 - User 1
|
|
7
|
+
* @param {CardUserOptions} user2 - User 2
|
|
8
|
+
* @param {CompareCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
9
|
+
* @param {CompareCardLocales?} locales - [BETA] Translate the rank card
|
|
10
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/compareCard
|
|
10
11
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
11
|
-
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
-
*/async function
|
|
12
|
+
* @throws {XpFatal} - If parameters are not provided correctly or if the user is not found in the database
|
|
13
|
+
*/async function compareCard(guild,user1,user2,options={},locales={}){var e,a,o,t,r,l;if(!guild?.id||!guild?.name)throw new xplogs_1.XpFatal({function:"compareCard()",message:"Please provide a guild"});if(!(user1?.id&&user1?.username&&user2?.id&&user2?.username))throw new xplogs_1.XpFatal({function:"compareCard()",message:"Please provide two valid users!"});if(!user1?.avatarURL.endsWith(".png")&&!user1.avatarURL.endsWith(".jpg")&&!user1.avatarURL.endsWith(".webp"))throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 1] Avatar image must be a png, jpg, or webp"});if(!user2?.avatarURL.endsWith(".png")&&!user2.avatarURL.endsWith(".jpg")&&!user2.avatarURL.endsWith(".webp"))throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 2] Avatar image, avatar image must be a png, jpg, or webp"});canvas_1.GlobalFonts.registerFromPath(options?.font||(0,path_1.join)(__dirname,"Fonts","BalooBhaijaan-Regular.woff2"),"Sans Serif"),locales?.level||(locales.level="Level"),locales?.versus||(locales.versus="vs"),t=await(0,canvas_1.loadImage)(options?.background||"https://i.ibb.co/WnfXZjc/clouds.jpg").catch(()=>{throw new xplogs_1.XpFatal({function:"compareCard()",message:"Unable to load background image, is it valid?"})}),e=await(0,canvas_1.loadImage)(user1.avatarURL).catch(()=>{throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 1] Unable to load user's AvatarURL, is it reachable?"})}),a=await(0,canvas_1.loadImage)(user2.avatarURL).catch(()=>{throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 2] Unable to load user's AvatarURL, is it reachable?"})});let n=await database_1.db.findOne({collection:"simply-xps",data:{guild:guild.id,user:user1.id}});if(!n){if(!xp_1.xp.auto_create||!user2?.username)throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 1] User not found in database"});n=await(0,xp_1.create)(user1.id,guild.id,user1.username)}let s=await database_1.db.findOne({collection:"simply-xps",data:{guild:guild.id,user:user2.id}});if(!s){if(!xp_1.xp.auto_create||!user2?.username)throw new xplogs_1.XpFatal({function:"compareCard()",message:"[USER 2] User not found in database"});s=await(0,xp_1.create)(user2.id,guild.id,user2.username)}return RoundedBox(o=(guild=(0,canvas_1.createCanvas)(1080,400)).getContext("2d"),0,0,guild.width,guild.height,25),o.clip(),o.globalAlpha=.2,o.fillStyle=options?.light?"#ffffff":"#000000",o.fill(),o.globalAlpha=.5,o.drawImage(t,-5,0,1090,400),o.restore(),o.globalAlpha=1,t=user1.username.replace(/[\u007f-\uffff]/g,""),user1=user2.username.replace(/[\u007f-\uffff]/g,""),user2=options?.color||"rgba(255,255,255,0.5)",options=options?.centerBarBg||options?.light?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",r=locales.level+(" "+shortener(n.level)),l=locales.level+(" "+shortener(s.level)),o.save(),o.textAlign="center",o.fillStyle="#ffffff",o.shadowColor="#000000",o.shadowBlur=6,o.shadowOffsetX=1,o.shadowOffsetY=1,o.font='39px "Sans Serif"',o.fillText(`${t} ${locales.versus} `+user1,540,60),o.restore(),o.save(),o.beginPath(),o.arc(160,200,100,0,2*Math.PI,!0),o.closePath(),o.strokeStyle=user2,o.lineWidth=15,o.stroke(),o.clip(),o.drawImage(e,50,90,220,220),o.restore(),o.save(),o.beginPath(),o.arc(920,200,100,0,2*Math.PI,!0),o.closePath(),o.strokeStyle=user2,o.lineWidth=15,o.stroke(),o.clip(),o.drawImage(a,810,90,220,220),o.restore(),o.save(),o.globalAlpha=1,o.fillStyle="#ffffff",o.textAlign="center",o.font='25px "Sans Serif"',o.fillText(r,160,350),o.fillText(l,920,350),o.restore(),o.save(),o.globalAlpha=1,RoundedBox(o,265,330,540,25,10),o.clip(),o.fillStyle=options,o.fill(),{attachment:guild.toBuffer("image/png"),description:"Simply-XP Comparison Card",name:"compareCard.png"}}
|
|
13
14
|
/**
|
|
14
15
|
* Generate a simple leaderboard card
|
|
15
16
|
* @async
|
|
16
17
|
* @param {Array<User>} data - Array of user data
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {LeaderboardCardOptions?} options - (artworkColor, artworkImage, light)
|
|
18
19
|
* @param {{name: string, imageURL: string, memberCount: number}?} guildInfo - Guild info
|
|
19
|
-
* @param {
|
|
20
|
-
* @link
|
|
20
|
+
* @param {LeaderboardCardLocales?} locales - Locales
|
|
21
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/leaderboard
|
|
22
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
23
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
24
|
+
*/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).catch(()=>{throw new xplogs_1.XpFatal({function:"leaderboardCard()",message:"Unable to load artwork image, is it valid?"})})),!cachedLeaderboardImage&&options?.backgroundImage&&(cachedLeaderboardImage=await(0,canvas_1.loadImage)(options.backgroundImage).catch(()=>{throw new xplogs_1.XpFatal({function:"leaderboardCard()",message:"Unable to load background image, is it valid?"})})),canvas_1.GlobalFonts.registerFromPath(options?.font||(0,path_1.join)(__dirname,"Fonts","BalooBhaijaan-Regular.woff2"),"Sans Serif"),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,void 0,{top:!0,bottom:!1}):e===data.length-1?RoundedBox(t,30,a,1290,90,20,void 0,{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"}}
|
|
25
|
+
/**
|
|
26
|
+
* Generate a simple user rank card
|
|
27
|
+
* @async
|
|
28
|
+
* @param {{id: string, name: string}} guild - (id, name)
|
|
29
|
+
* @param {CardUserOptions} user - (id, username, avatarURL)
|
|
30
|
+
* @param {RankCardOptions?} options - (background, color, legacy, lvlbar, lvlbarBg, font)
|
|
31
|
+
* @param {RankCardLocales?} locales - [BETA] Translate the rank card
|
|
32
|
+
* @link `Documentation` https://simplyxp.js.org/docs/next/functions/rankCard
|
|
21
33
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
22
34
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
23
|
-
*/async function
|
|
35
|
+
*/async function rankCard(guild,user,options={},locales={}){var e,a,o,t,r,l,n,s,i,d,f;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"});let c,p;if(locales?.level||(locales.level="Level"),locales?.next_level||(locales.next_level="Next Level"),locales?.xp||(locales.xp="XP"),xplogs_1.XpLog.debug("rankCard()",`${options?.legacy?"LEGACY":"MODERN"} ENABLED`),!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","BalooBhaijaan-Regular.woff2"),"Sans Serif"),cachedRankImage=cachedRankImage||await(0,canvas_1.loadImage)(options?.background||(options?.legacy?"https://i.ibb.co/dck2Tnt/rank-card.webp":"https://i.ibb.co/WnfXZjc/clouds.jpg")).catch(()=>{throw new xplogs_1.XpFatal({function:"rankCard()",message:"Unable to load background image, is it valid?"})}),e=await(0,canvas_1.loadImage)(user.avatarURL).catch(()=>{throw new xplogs_1.XpFatal({function:"rankCard()",message:"Unable to load user's AvatarURL, is it reachable?"})});let g=await database_1.db.findOne({collection:"simply-xps",data:{guild:guild.id,user:user.id}});if(!g){if(!xp_1.xp.auto_create)throw new xplogs_1.XpFatal({function:"rankCard()",message:"User not found in database"});g=await(0,xp_1.create)(user.id,guild.id,user.username)}return a=await database_1.db.find({collection:"simply-xps",data:{guild:guild.id}}),g.position=a.sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===user.id)+1,cachedRankContext&&cachedRankCanvas?(c=cachedRankCanvas,p=cachedRankContext):(c=(0,canvas_1.createCanvas)(1080,400),RoundedBox(p=c.getContext("2d"),0,0,c.width,c.height,25),p.clip(),options?.legacy?(p.globalAlpha=1,p.fillStyle="#000000",p.fill()):(p.globalAlpha=.2,p.fillStyle=options?.light?"#ffffff":"#000000",p.fill(),p.globalAlpha=.5),p.drawImage(cachedRankImage,-5,0,1090,400),p.restore()),a=user.username.replace(/[\u007f-\uffff]/g,""),o=options?.color||(options?.legacy?"#9900ff":"rgba(255,255,255,0.5)"),t=options?.lvlbar||"#ffffff",r=options?.lvlbarBg||options?.legacy?"#FFFFFF":options?.light?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.2)",l=shortener(g.xp)+(" "+locales.xp),n=locales.level+(" "+shortener(g.level)),s="{current} / {needed}",i=(0,utilities_1.convertFrom)(g.level+1),d=(0,utilities_1.convertFrom)(g.level),d=100*(g.xp-d)/(i-d)*(options?.legacy?660:530)/100,f="326815959358898189"===g.user?"#ade6d8":1===g.position?"#ADD8E6":2===g.position?"#C0C0C0":3===g.position?"#CD7F32":"#ffffff",p.save(),options?.legacy?(p.fillStyle="#000000",p.globalAlpha=.4,p.fillRect(40,0,240,c.height),p.globalAlpha=1,RoundedBox(p,70,30,180,180,50),p.strokeStyle=o,p.lineWidth=15,p.stroke(),p.clip(),p.drawImage(e,70,30,180,180),p.restore(),p.save(),RoundedBox(p,70,320,180,50,20,"#BFC85A22"),p.fillStyle=o,p.globalAlpha=1,p.fillRect(70,320,180,50),p.globalAlpha=1,p.fillStyle="#ffffff",p.textAlign="center",dynamicFont(p,l,160,358,160,32),p.restore(),p.save(),RoundedBox(p,70,240,180,50,20,"#BFC85A22"),p.fillStyle=o,p.globalAlpha=1,p.fillRect(70,240,180,50),p.globalAlpha=1,p.fillStyle="#ffffff",p.textAlign="center",dynamicFont(p,n,160,278,160,32),p.restore(),p.save(),p.textAlign="left",p.fillStyle="#ffffff",p.shadowColor="#000000",p.shadowBlur=15,p.shadowOffsetX=1,p.shadowOffsetY=1,p.font='39px "Sans Serif"',p.fillText(a,390,80),p.restore(),p.save(),p.textAlign="right",p.fillStyle="#ffffff",p.shadowColor="#000000",p.shadowBlur=15,p.shadowOffsetX=1,p.shadowOffsetY=1,p.font='55px "Sans Serif"',p.fillText("#"+g.position,c.width-55,80),p.restore(),p.save(),RoundedBox(p,390,305,660,70,20,"#BFC85A22"),p.fillStyle="#ffffff",p.textAlign="center",dynamicFont(p,guild.name,720,355,700,45),p.globalAlpha=.2,p.fillRect(390,305,660,70),p.restore(),p.save(),RoundedBox(p,390,145,660,50,20,"#BFC85A22"),p.fillStyle=r,p.globalAlpha=.2,p.fillRect(390,145,660,50),p.restore(),p.save(),RoundedBox(p,390,145,d,50,20,"#BFC85A22"),p.fillStyle=t,p.globalAlpha=.5,p.fillRect(390,145,d,50),p.restore(),p.save(),p.textAlign="left",p.fillStyle="#ffffff",p.globalAlpha=.8,p.font='30px "Sans Serif"',p.fillText(locales.next_level+": "+shortener(i)+" "+locales.xp,390,230),p.restore(),options=s.replace(/{needed}/g,shortener(i)).replace(/{current}/g,shortener(g.xp)),p.textAlign="center",p.fillStyle="#474747",p.globalAlpha=1,p.font='30px "Sans Serif"',p.fillText(options,730,180)):(p.globalAlpha=1,p.save(),p.textAlign="center",p.fillStyle="#ffffff",p.shadowColor="#000000",p.shadowBlur=5,p.shadowOffsetX=1,p.shadowOffsetY=1,p.font='39px "Sans Serif"',p.fillText(a,540,80),p.restore(),p.save(),p.beginPath(),p.arc(160,200,100,0,2*Math.PI,!0),p.closePath(),p.strokeStyle=o,p.lineWidth=15,p.stroke(),p.clip(),p.drawImage(e,50,90,220,220),p.restore(),p.save(),p.beginPath(),p.arc(230,130,30,0,2*Math.PI,!0),p.closePath(),p.strokeStyle=o,p.lineWidth=5,p.stroke(),p.clip(),p.beginPath(),p.arc(230,130,30,0,2*Math.PI,!0),p.closePath(),p.fillStyle=f,p.fill(),p.clip(),p.fillStyle="#000000",p.textAlign="center",p.font='25px "Sans Serif"',p.fillText(shortener(g.position,!0),230,138),p.restore(),p.save(),p.fillStyle="#ffffff",p.font='25px "Sans Serif"',p.textAlign="center",p.globalAlpha=1,p.fillText(n,160,350),p.restore(),p.save(),p.globalAlpha=1,RoundedBox(p,265,330,540,25,10),p.clip(),p.fillStyle=r,p.fill(),RoundedBox(p,270,335,d,15,5),p.fillStyle=t,p.fill(),p.restore(),p.save(),p.textAlign="center",p.fillStyle="#ffffff",p.globalAlpha=.6,p.font='20px "Sans Serif"',p.fillText(s.replace(/{needed}/g,shortener(i)).replace(/{current}/g,shortener(g.xp)),540,320),p.save(),p.fillStyle="#ffffff",p.textAlign="center",p.globalAlpha=1,p.font='25px "Sans Serif"',p.fillText(locales.level+" "+shortener(g.level+1),920,350),p.restore()),{attachment:c.toBuffer("image/png"),description:"Simply-XP Rank Card",name:"rank.png"}}function RoundedBox(ctx,x,y,width,height,radius,strokeColor,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(),strokeColor&&(ctx.strokeStyle=strokeColor,ctx.stroke(),ctx.clip())}function shortener(count,roundedNumber){let e="",a=0;if(!count||0===count)return"0";if(count===1/0)return"∞";for(;1e3<=count&&a<8;)count/=1e3,a++;switch(a){case 1:e="K";break;case 2:e="M";break;case 3:e="B";break;case 4:e="T";break;case 5:e="Qa";break;case 6:e="Qi";break;case 7:e="Sx";break;case 8:e="Sp"}return""+count.toFixed(0===a||roundedNumber?0:2)+e}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.RoundedBox=exports.rankCard=exports.leaderboardCard=exports.compareCard=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.compareCard=compareCard,exports.leaderboardCard=leaderboardCard,exports.rankCard=rankCard,exports.RoundedBox=RoundedBox;
|
package/lib/src/charts.d.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Chart options
|
|
4
|
+
* @property {string} font - Font of the chart
|
|
5
|
+
* @property {"blue" | "dark" | "discord" | "green" | "orange" | "red" | "space" | "yellow"} theme - Theme of the chart
|
|
6
|
+
* @property {number} limit - Limit of users to return (2-10)
|
|
7
|
+
*/
|
|
2
8
|
export interface ChartOptions {
|
|
3
|
-
|
|
4
|
-
limit?:
|
|
5
|
-
|
|
9
|
+
font?: string;
|
|
10
|
+
limit?: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
11
|
+
theme?: "blue" | "dark" | "discord" | "green" | "orange" | "red" | "space" | "yellow";
|
|
12
|
+
type?: "bar" | "doughnut" | "pie";
|
|
6
13
|
}
|
|
7
14
|
/**
|
|
8
15
|
* Creates a chart
|
|
9
16
|
* @async
|
|
10
17
|
* @param {string} guildId
|
|
11
18
|
* @param {ChartOptions?} options
|
|
12
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/charts
|
|
13
|
-
* @returns {Promise<
|
|
14
|
-
* @throws {XpFatal} If invalid parameters are provided
|
|
19
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/charts
|
|
20
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>} Chart attachment
|
|
21
|
+
* @throws {XpFatal} If invalid parameters are provided, or if there are not enough users to create a chart
|
|
15
22
|
*/
|
|
16
|
-
export declare function charts(guildId: string, options?: ChartOptions): Promise<
|
|
17
|
-
|
|
23
|
+
export declare function charts(guildId: string, options?: ChartOptions): Promise<{
|
|
24
|
+
attachment: Buffer;
|
|
25
|
+
description: string;
|
|
26
|
+
name: string;
|
|
27
|
+
}>;
|
package/lib/src/charts.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} guildId
|
|
6
6
|
* @param {ChartOptions?} options
|
|
7
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/charts
|
|
8
|
-
* @returns {Promise<
|
|
9
|
-
* @throws {XpFatal} If invalid parameters are provided
|
|
10
|
-
*/
|
|
11
|
-
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;
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/charts
|
|
8
|
+
* @returns {Promise<{attachment: Buffer, description: string, name: string}>} Chart attachment
|
|
9
|
+
* @throws {XpFatal} If invalid parameters are provided, or if there are not enough users to create a chart
|
|
10
|
+
*/async function charts(guildId,options={}){var F,t,o,r,a,i,l,s,e;if(!guildId)throw new xplogs_1.XpFatal({function:"charts()",message:"No Guild ID Provided"});if(!options)throw new xplogs_1.XpFatal({function:"charts()",message:"No Options Provided"});options.theme&&["blue","dark","discord","green","orange","red","space","yellow"].includes(options.theme)||(xplogs_1.XpLog.warn("charts()","Invalid theme provided, defaulting to discord"),options.theme="discord"),options.type&&["bar","doughnut","pie"].includes(options.type)||(xplogs_1.XpLog.warn("charts()","Invalid type provided, defaulting to bar chart"),options.type="bar");let n={background:"#FFFFFF",barColor:"#FFFFFF",pieColors:["#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF","#FFFFFF"],textColor:"#FFFFFF"};if((F=await(0,leaderboard_1.leaderboard)(guildId,Math.min(Math.max(options?.limit||10,2),10)).catch(XPError=>{throw new xplogs_1.XpFatal({function:"charts()",message:XPError.message})})).length<2)throw new xplogs_1.XpFatal({function:"charts()",message:"Not enough users to create a chart"});switch(F.sort((a,b)=>b.position-a.position),canvas_1.GlobalFonts.registerFromPath(options?.font||(0,path_1.join)(__dirname,"Fonts","BalooBhaijaan-Regular.woff2"),"Sans Serif"),options.theme){case"blue":n={background:"#1e1e3c",barColor:"#747fff",pieColors:["#747fff","#2832C2","#59788E","#00d2e7","#281E5D","#a9f5ff","#000e3f","#30edc2","#186c84","#0098ff"],textColor:"#FFFFFF"};break;case"dark":n={background:"#1e1e1e",barColor:"#747474",pieColors:["#1B1D1F","#454C53","#72787F","#999999","#9EA4AA","#CCCCCC","#C9CDD2","#DEDEDE","#E8EBED","#FFFFFF"],textColor:"#FFFFFF"};break;case"discord":n={background:"#36393f",barColor:"#5865F2",pieColors:["#5865F2","#57F287","#FEE75C","#EB459E","#ED4245","#FFFFFF","#000000","#FAA61A","#C04DF9","#00AAFF"],textColor:"#FFFFFF"};break;case"green":n={background:"#1e321e",barColor:"#74ff7f",pieColors:["#00FF00","#008000","#7FFF00","#32CD32","#228B22","#006400","#9ACD32","#00FA9A","#ADFF2F","#7CFC00"],textColor:"#FFFFFF"};break;case"orange":n={background:"#321e1e",barColor:"#ff9f74",pieColors:["#FF8C00","#FF5E0E","#FF4500","#FF6347","#E26310","#F5761A","#FD673A","#FFA500","#FF7F50","#FFD700"],textColor:"#FFFFFF"};break;case"red":n={background:"#321e1e",barColor:"#ff7474",pieColors:["#FF0000","#FF2400","#FF4500","#FF6347","#FF7F50","#FF8C00","#FFA07A","#FFA500","#FFC0CB","#FFD700"],textColor:"#FFFFFF"};break;case"space":n={background:"#001F3F",barColor:"#192E5B",pieColors:["#192E5B","#1F3F7F","#264FA3","#2C5FC7","#337FEA","#3D8FFF","#4D9FFF","#5DAFFF","#6DBFFF","#7DCFFF"],textColor:"#FFFFFF"};break;case"yellow":n={background:"#32321e",barColor:"#ffff74",pieColors:["#FFFD37","#FFEF00","#FDFF00","#DAA520","#F4C430","#E4D00A","#D2B55B","#FFFFE0","#FFFACD","#F5DEB3"],textColor:"#FFFFFF"}}const d=(0,canvas_1.createCanvas)(920,600),h=d.getContext("2d"),c=Math.max(...F.map(user=>user.level));if((0,cards_1.RoundedBox)(h,0,0,d.width,d.height,25),h.clip(),h.fillStyle=n.background,h.fillRect(0,0,d.width,d.height),"space"===options.theme){h.clearRect(0,0,d.width,d.height),(guildId=h.createRadialGradient(d.width/2,d.height/2,1,d.width/2,d.height/2,Math.max(d.width,d.height))).addColorStop(0,"#000000"),guildId.addColorStop(1,"#001F3F"),h.fillStyle=guildId,h.fillRect(0,0,d.width,d.height),(guildId=h.createRadialGradient(150,150,10,150,150,100)).addColorStop(0,"#F2F2F2"),guildId.addColorStop(.8,"#D3D3D3"),guildId.addColorStop(1,"#001F3F"),h.fillStyle=guildId,h.beginPath(),h.arc(150,150,100,0,2*Math.PI),h.fill(),t=["#6B6B6B","#AA8F00","#473E83","#456579"];for(let e=0;e<t.length;e++)o=Math.random()*d.width,r=Math.random()*d.height,a=50*Math.random()+30,h.beginPath(),h.arc(o,r,a,0,2*Math.PI),h.fillStyle=t[e]||"#FFFFFF",h.fill();h.filter="blur(5px)",h.drawImage(d,0,0),h.filter="none";for(let e=0;e<100;e++)i=Math.random()*d.width,l=Math.random()*d.height,s=2*Math.random(),h.beginPath(),h.arc(i,l,s,0,2*Math.PI),h.fillStyle="#FFFFFF",h.fill()}let u=d.width-40,p=d.height-40;switch(options.type){case"bar":{e=h.measureText(c.toString()).width,u=d.width-e-60-40,p=d.height-100-40;const f=u/F.length-20,g=20+e+40,C=d.height-50-20;await Promise.all(F.map(async(user,index)=>{var e,F,t=user.level/c*p,index=g+index*(20+f),o=C-t,t=(h.fillStyle=n.barColor,h.strokeStyle=n.barColor,h.lineWidth=2,(0,cards_1.RoundedBox)(h,index,o,f,t,10),h.fill(),h.stroke(),index+f/2),index=(h.fillStyle=n.textColor,h.font="22px Sans Serif",user.level.toString()),r=h.measureText(index).width,o=o-10,index=(h.fillText(index,t-r/2,o),user?.name||user.user),r=h.measureText(index).width,o=(h.font=Math.min(Math.floor(f/r*16),18)+"px Sans Serif",r=h.measureText(index).width,30+C);"space"===options.theme&&(e=t-(user=r+10)/2,F=o-18,h.fillStyle="rgba(0, 0, 0, 0.5)",h.fillRect(e,F,user,22)),h.fillStyle=n.textColor,h.fillText(index,t-r/2,o)}))}break;case"doughnut":{const x=F.reduce((sum,user)=>sum+user.level,0),m=Math.min(u,p)/3,b=.6*m;let e=-Math.PI/2;const w=d.width/2,D=d.height/2;await Promise.all(F.map(async(user,index)=>{user=user.level/x,user=e+2*Math.PI*user,h.fillStyle=n.pieColors[index%n.pieColors.length]||"#FFFFFF",h.beginPath(),h.moveTo(w+m*Math.cos(e),D+m*Math.sin(e)),h.arc(w,D,m,e,user),h.lineTo(w+b*Math.cos(user),D+b*Math.sin(user)),h.arc(w,D,b,user,e,!0),h.closePath(),h.fill(),e=user}))}break;case"pie":{const y=F.reduce((sum,user)=>sum+user.level,0),S=Math.min(u,p)/3;let e=-Math.PI/2;const v=d.width/2,A=d.height/2;await Promise.all(F.map(async(user,index)=>{user=user.level/y,user=e+2*Math.PI*user,h.fillStyle=n.pieColors[index%n.pieColors.length]||"#FFFFFF",h.beginPath(),h.moveTo(v,A),h.arc(v,A,S,e,user),h.closePath(),h.fill(),e=user}))}break;default:throw new xplogs_1.XpFatal({function:"charts()",message:"Invalid chart type provided"})}if(["doughnut","pie"].includes(options.type)){const E=d.height-20-20*F.length;h.fillStyle="rgba(0,0,0,0.25)",h.fillRect(15,E-5,200,20*F.length+5),h.font="12px Sans Serif",await Promise.all(F.map(async(user,index)=>{var user=user?.name||user.user,e=n.pieColors[index%n.pieColors.length],index=E+20*index;h.fillStyle=e||"#FFFFFF",h.fillRect(20,index,15,15),h.fillStyle=n.textColor,h.fillText(user,40,11.5+index)}))}return{attachment:d.toBuffer("image/png"),description:"Chart",name:"chart.png"}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.charts=void 0;const canvas_1=require("@napi-rs/canvas"),path_1=require("path"),leaderboard_1=require("./leaderboard"),cards_1=require("./cards"),xplogs_1=require("./functions/xplogs");exports.charts=charts;
|
package/lib/src/connect.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ConnectionOptions = {
|
|
|
11
11
|
* @async
|
|
12
12
|
* @param {string} uri
|
|
13
13
|
* @param {ConnectionOptions} options
|
|
14
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
14
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/connect
|
|
15
15
|
* @returns {Promise<boolean>}
|
|
16
16
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
17
17
|
*/
|
|
@@ -19,8 +19,10 @@ export declare function connect(uri: string, options?: ConnectionOptions): Promi
|
|
|
19
19
|
/**
|
|
20
20
|
* Check database package versions
|
|
21
21
|
* @private
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {string} type - NPM Package Name (lowercase)
|
|
23
|
+
* @param {number} min - Minimum Major Version Number
|
|
24
|
+
* @param {number} max - Maximum Major Version Number (Optional)
|
|
23
25
|
* @returns {Promise<boolean>}
|
|
24
26
|
* @throws {XpFatal} If the package version is not supported
|
|
25
27
|
*/
|
|
26
|
-
export declare function checkPackageVersion(type:
|
|
28
|
+
export declare function checkPackageVersion(type: string, min: number, max?: number): Promise<boolean>;
|
package/lib/src/connect.js
CHANGED
|
@@ -5,32 +5,32 @@
|
|
|
5
5
|
* @async
|
|
6
6
|
* @param {string} uri
|
|
7
7
|
* @param {ConnectionOptions} options
|
|
8
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/connect
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/connect
|
|
9
9
|
* @returns {Promise<boolean>}
|
|
10
10
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
|
-
*/
|
|
12
|
-
async function connect(uri,options={type:void 0}){var o,{type:e,auto_create:t,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),t&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_purge=!0),n&&(xp_1.xp.debug=!0),e||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),e){case"mongodb":if(o=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb"))return xplogs_1.XpLog.err("connect()","MongoDB V4 or higher is required");o=await o.connect(uri).catch(error=>{throw new xplogs_1.XpFatal({function:"connect()",message:error.message})}),xp_1.xp.dbType="mongodb",xp_1.xp.database=o||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"
|
|
11
|
+
*/async function connect(uri,options={type:void 0}){var e,{type:o,auto_create:t,auto_purge:n,notify:r,debug:a}=options;if(!uri)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===r&&(xp_1.xp.notify=!1),t&&(xp_1.xp.auto_create=!0),n&&(xp_1.xp.auto_purge=!0),a&&(xp_1.xp.debug=!0),o||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),o){case"mongodb":if(e=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb",4,6))return xplogs_1.XpLog.err("connect()","MongoDB Version 4 to 6 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[i,s]=await Promise.all([Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),checkPackageVersion("better-sqlite3",7,9)]);if(!s)return xplogs_1.XpLog.err("connect()","better-sqlite3 Version 7 to 9 is required");xp_1.xp.database=new i.default(uri),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xps"
|
|
13
12
|
(
|
|
14
13
|
user TEXT NOT NULL,
|
|
15
14
|
guild TEXT NOT NULL,
|
|
16
|
-
name TEXT DEFAULT
|
|
15
|
+
name TEXT DEFAULT user,
|
|
17
16
|
level INTEGER DEFAULT 0,
|
|
18
17
|
xp INTEGER DEFAULT 0
|
|
19
18
|
)`),xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xp-levelroles"
|
|
20
19
|
(
|
|
21
20
|
gid TEXT UNIQUE,
|
|
22
21
|
lvlrole TEXT NOT NULL
|
|
23
|
-
)`)}catch(
|
|
22
|
+
)`)}catch(o){if("object"==typeof o&&null!==o&&void 0!==(e=o).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)}
|
|
24
23
|
/**
|
|
25
24
|
* Returns the package manager used
|
|
26
25
|
* @private
|
|
27
26
|
* @returns {Promise<"yarn" | "npm" | "pnpm">}
|
|
28
|
-
*/
|
|
29
|
-
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"}
|
|
27
|
+
*/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"}
|
|
30
28
|
/**
|
|
31
29
|
* Check database package versions
|
|
32
30
|
* @private
|
|
33
|
-
* @param {
|
|
31
|
+
* @param {string} type - NPM Package Name (lowercase)
|
|
32
|
+
* @param {number} min - Minimum Major Version Number
|
|
33
|
+
* @param {number} max - Maximum Major Version Number (Optional)
|
|
34
34
|
* @returns {Promise<boolean>}
|
|
35
35
|
* @throws {XpFatal} If the package version is not supported
|
|
36
|
-
*/async function checkPackageVersion(type
|
|
36
|
+
*/async function checkPackageVersion(type,min,max){try{var e=await Promise.resolve(type+"/package.json").then(s=>__importStar(require(s)));return parseInt(e.version.substring(0,1))>=min&&(!max||parseInt(e.version.substring(0,1))<=max)}catch(e){return xplogs_1.XpLog.info("checkPackageVersion()",`Installing ${type} [V${max||min}] | Please wait...`),(0,child_process_1.execSync)(await getPackageManager()+` add ${type}@${max||min}.x.x`),xplogs_1.XpLog.warn("checkPackageVersion()",`Installed ${type}. 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,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.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;
|
package/lib/src/create.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { UserResult } from "./functions/database";
|
|
|
5
5
|
* @param {string} userId
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {string} username
|
|
8
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/create
|
|
9
9
|
* @returns {Promise<UserResult>}
|
|
10
10
|
* @throws {XpFatal} If invalid parameters are provided
|
|
11
11
|
*/
|
package/lib/src/create.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* @param {string} userId
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {string} username
|
|
8
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/create
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/create
|
|
9
9
|
* @returns {Promise<UserResult>}
|
|
10
10
|
* @throws {XpFatal} If invalid parameters are provided
|
|
11
|
-
*/
|
|
12
|
-
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"});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;
|
|
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"});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;
|
|
@@ -7,7 +7,7 @@ import { RankCardOptions } from "../cards";
|
|
|
7
7
|
* @param {string} userId
|
|
8
8
|
* @param {string} _guildId
|
|
9
9
|
* @param {RankCardOptions?} options
|
|
10
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/deprecated/rank
|
|
10
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/deprecated/rank
|
|
11
11
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
12
12
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
13
13
|
*/
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* @param {string} userId
|
|
7
7
|
* @param {string} _guildId
|
|
8
8
|
* @param {RankCardOptions?} options
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/deprecated/rank
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/deprecated/rank
|
|
10
10
|
* @returns {Promise<{attachment: Buffer, description: string, name: string}>}
|
|
11
11
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
-
*/
|
|
13
|
-
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;
|
|
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;
|
package/lib/src/fetch.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { User } from "./leaderboard";
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} userId
|
|
6
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
|
|
7
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/fetch
|
|
9
9
|
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
10
10
|
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
11
11
|
*/
|
|
12
|
-
export declare function fetch(userId: string, guildId: string, username
|
|
12
|
+
export declare function fetch(userId: string, guildId: string, username?: string): Promise<User>;
|