simply-xp 1.3.7 → 2.0.0-beta.0
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 +73 -43
- package/lib/src/add.d.ts +35 -0
- package/lib/src/add.js +23 -0
- package/lib/src/cards.d.ts +158 -0
- package/lib/src/cards.js +35 -0
- package/lib/src/charts.d.ts +27 -0
- package/lib/src/charts.js +10 -0
- package/lib/src/connect.d.ts +29 -0
- package/lib/src/connect.js +41 -0
- package/lib/src/create.d.ts +12 -0
- package/lib/src/create.js +11 -0
- package/lib/src/fetch.d.ts +12 -0
- package/lib/src/fetch.js +11 -0
- package/lib/src/functions/database.d.ts +164 -0
- package/lib/src/functions/database.js +78 -0
- package/lib/src/functions/https.d.ts +26 -0
- package/lib/src/functions/https.js +15 -0
- package/lib/src/functions/utilities.d.ts +79 -0
- package/lib/src/functions/utilities.js +43 -0
- package/lib/src/functions/xplogs.d.ts +81 -0
- package/lib/src/functions/xplogs.js +15 -0
- package/lib/src/leaderboard.d.ts +11 -0
- package/lib/src/leaderboard.js +10 -0
- package/lib/src/migrate.d.ts +27 -0
- package/lib/src/migrate.js +19 -0
- package/lib/src/remove.d.ts +29 -0
- package/lib/src/remove.js +23 -0
- package/lib/src/reset.d.ts +12 -0
- package/lib/src/reset.js +12 -0
- package/lib/src/roleSetup.d.ts +78 -0
- package/lib/src/roleSetup.js +47 -0
- package/lib/src/set.d.ts +26 -0
- package/lib/src/set.js +23 -0
- package/lib/xp.d.ts +62 -0
- package/lib/xp.js +56 -0
- package/package.json +49 -35
- package/index.d.ts +0 -108
- package/simplyxp.js +0 -33
- package/src/Fonts/Baloo-Regular.ttf +0 -0
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -104
- package/src/charts.js +0 -92
- package/src/connect.js +0 -21
- package/src/create.js +0 -28
- package/src/fetch.js +0 -74
- package/src/leaderboard.js +0 -51
- 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 -42
- package/src/setXP.js +0 -23
|
@@ -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/next/functions/addlevel
|
|
10
|
+
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/async function removeLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"removeLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"removeLevel()",message:"Guild ID was not provided"});if(isNaN(level))throw new xplogs_1.XpFatal({function:"removeLevel()",message:"Level was not provided"});var e=await xp_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(e)return xp_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{name:username||e?.name||userId,user:userId,guild:guildId,level:e.level-level,xp:(0,xp_1.convertFrom)(e.level-level),xp_rate:xp_1.xp.xp_rate}});if(xp_1.xp.auto_create&&username)return xp_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"removeLevel()",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/next/functions/addxp
|
|
21
|
+
* @returns {Promise<XPResult>} - Object of user data on success.
|
|
22
|
+
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
23
|
+
*/async function removeXP(userId,guildId,xpData,username){var e;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:"removeXP()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"removeXP()",message:"Guild ID was not provided"});let a;if(e=await xp_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))a=await xp_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,name:username||e?.name||userId,level:(0,xp_1.convertFrom)(e.xp-xpData,"xp"),xp:e.xp-xpData,xp_rate:xp_1.xp.xp_rate}}).catch(err=>{throw new xplogs_1.XpFatal({function:"removeXP()",message:err.stack})});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"removeXP()",message:"User does not exist"});a=await xp_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}}).catch(err=>{throw new xplogs_1.XpFatal({function:"removeXP()",message:err.stack})})}return xpData=xplogs_1.XpEvents.eventCallback,(username=e?.level&&a?.level?a.level!==e.level?a.level-e.level:0:0<a?.level?a.level:0)<0&&xpData?.levelDown&&"function"==typeof xpData.levelDown&&xpData.levelDown(a,await xp_1.roleSetup.getRoles(userId,guildId,{includeNextRoles:!0})),0<username&&xpData?.levelUp&&"function"==typeof xpData.levelUp&&xpData.levelUp(a,await xp_1.roleSetup.getRoles(userId,guildId)),{...a,levelDifference:username}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeXP=exports.removeLevel=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.removeLevel=removeLevel,exports.removeXP=removeXP;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reset user levels to 0 in a guild
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} userId
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {boolean?} erase - Erase user entry from the database
|
|
7
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/reset
|
|
9
|
+
* @returns {Promise<boolean>}
|
|
10
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
|
+
*/
|
|
12
|
+
export declare function reset(userId: string, guildId: string, erase?: boolean, username?: string): Promise<boolean>;
|
package/lib/src/reset.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reset user levels to 0 in a guild
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {boolean?} erase - Erase user entry from the database
|
|
8
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/reset
|
|
10
|
+
* @returns {Promise<boolean>}
|
|
11
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
12
|
+
*/async function reset(userId,guildId,erase=!1,username){var e;if(userId&&guildId)return e={guild:guildId,user:userId,xp_rate:xp_1.xp.xp_rate},await xp_1.db.findOne({collection:"simply-xps",data:e})?(erase?await xp_1.db.deleteOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):await xp_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{...e,level:0,xp:0}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}),!0):xp_1.xp.auto_create&&!erase&&username?(await xp_1.db.createOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error.stack})}),!0):xplogs_1.XpLog.info("reset()","User was not found, we did not know what to do without a username.");throw new xplogs_1.XpFatal({function:"reset()",message:"Invalid parameters provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.reset=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.reset=reset;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { LevelRoleResult } from "./functions/database";
|
|
2
|
+
/**
|
|
3
|
+
* Get Roles Object
|
|
4
|
+
* @property {boolean?} includeNextRoles - Include roles for the next levels.
|
|
5
|
+
* @property {boolean?} includePreviousRoles - Include roles for the previous levels.
|
|
6
|
+
*/
|
|
7
|
+
type GetRolesObject = {
|
|
8
|
+
includeNextRoles?: boolean;
|
|
9
|
+
includePreviousRoles?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Role setup object
|
|
13
|
+
* @property {string} guild - The guild ID
|
|
14
|
+
* @property {number} level - The level number
|
|
15
|
+
* @property {string[] | string} role - The role(s) to add
|
|
16
|
+
*/
|
|
17
|
+
export interface RoleSetupObject {
|
|
18
|
+
level: number;
|
|
19
|
+
role: string[] | string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Setup roles for levels
|
|
23
|
+
* @class roleSetup
|
|
24
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup
|
|
25
|
+
*/
|
|
26
|
+
export declare class roleSetup {
|
|
27
|
+
/**
|
|
28
|
+
* Add a role to the role setup
|
|
29
|
+
* @async
|
|
30
|
+
* @param {string} guildId - The guild ID
|
|
31
|
+
* @param {RoleSetupObject} options - Level/role options
|
|
32
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
|
|
33
|
+
* @returns {Promise<boolean>} - True if successful
|
|
34
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
35
|
+
*/
|
|
36
|
+
static add(guildId: string, options: RoleSetupObject): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Get roles for a user's level
|
|
39
|
+
* @async
|
|
40
|
+
* @param {string} userId - The user ID
|
|
41
|
+
* @param {string} guildId - The guild ID
|
|
42
|
+
* @param {GetRolesObject} options - Options
|
|
43
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupgetRoles
|
|
44
|
+
* @returns {Promise<string[]>} - Array of role IDs or empty array if none
|
|
45
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
46
|
+
*/
|
|
47
|
+
static getRoles(userId: string, guildId: string, options?: GetRolesObject): Promise<string[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Find a role in roleSetup
|
|
50
|
+
* @async
|
|
51
|
+
* @param {string} guildId - The guild ID
|
|
52
|
+
* @param {number} levelNumber - The level number
|
|
53
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
|
|
54
|
+
* @returns {Promise<LevelRoleResult>} - The level role object
|
|
55
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
56
|
+
*/
|
|
57
|
+
static find(guildId: string, levelNumber: number): Promise<LevelRoleResult>;
|
|
58
|
+
/**
|
|
59
|
+
* List all level roles in a guild
|
|
60
|
+
* @async
|
|
61
|
+
* @param {string} guildId - The guild ID
|
|
62
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetuplist
|
|
63
|
+
* @returns {Promise<LevelRoleResult[]>} - The level role object
|
|
64
|
+
* @throws {XpFatal} If there are no roles in the guild.
|
|
65
|
+
*/
|
|
66
|
+
static list(guildId: string): Promise<LevelRoleResult[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Remove a level from the role setup
|
|
69
|
+
* @async
|
|
70
|
+
* @param {string} guildId - The guild ID
|
|
71
|
+
* @param {number} levelNumber - The level number
|
|
72
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
|
|
73
|
+
* @returns {Promise<boolean>} - True if successful
|
|
74
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
75
|
+
*/
|
|
76
|
+
static remove(guildId: string, levelNumber: number): Promise<boolean>;
|
|
77
|
+
}
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.roleSetup=void 0;const xp_1=require("../xp"),xplogs_1=require("./functions/xplogs");class roleSetup{
|
|
2
|
+
/**
|
|
3
|
+
* Add a role to the role setup
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} guildId - The guild ID
|
|
6
|
+
* @param {RoleSetupObject} options - Level/role options
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
|
|
8
|
+
* @returns {Promise<boolean>} - True if successful
|
|
9
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
10
|
+
*/
|
|
11
|
+
static async add(guildId,options){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Guild ID was not provided"});if(!options)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Options were not provided"});if(isNaN(options?.level))throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Level must be a number"});if(options?.role)return"string"==typeof options?.role&&(options.role=[options.role]),xp_1.db.createOne({collection:"simply-xp-levelroles",data:{guild:guildId,lvlrole:{lvl:options.level,role:options.role}}}).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Role was not provided"})}
|
|
12
|
+
/**
|
|
13
|
+
* Get roles for a user's level
|
|
14
|
+
* @async
|
|
15
|
+
* @param {string} userId - The user ID
|
|
16
|
+
* @param {string} guildId - The guild ID
|
|
17
|
+
* @param {GetRolesObject} options - Options
|
|
18
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupgetRoles
|
|
19
|
+
* @returns {Promise<string[]>} - Array of role IDs or empty array if none
|
|
20
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
21
|
+
*/static async getRoles(userId,guildId,options={}){if(!userId)throw new xplogs_1.XpFatal({function:"roleSetup.getRoles()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.getRoles()",message:"Guild ID was not provided"});const e=await xp_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(userId=await roleSetup.list(guildId),!e||!e?.level)return[];const l=[];return userId.forEach(({lvlrole:{lvl,role}})=>{role&&(lvl<e.level&&options?.includePreviousRoles||lvl>e.level&&options?.includeNextRoles||lvl===e.level)&&l.push(...Array.isArray(role)?role:[role])}),l}
|
|
22
|
+
/**
|
|
23
|
+
* Find a role in roleSetup
|
|
24
|
+
* @async
|
|
25
|
+
* @param {string} guildId - The guild ID
|
|
26
|
+
* @param {number} levelNumber - The level number
|
|
27
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
|
|
28
|
+
* @returns {Promise<LevelRoleResult>} - The level role object
|
|
29
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
30
|
+
*/static async find(guildId,levelNumber){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Guild ID was not provided"});if(isNaN(levelNumber))throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Level Number was not provided"});return xp_1.db.findOne({collection:"simply-xp-levelroles",data:{guild:guildId,lvlrole:{lvl:levelNumber}}})}
|
|
31
|
+
/**
|
|
32
|
+
* List all level roles in a guild
|
|
33
|
+
* @async
|
|
34
|
+
* @param {string} guildId - The guild ID
|
|
35
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetuplist
|
|
36
|
+
* @returns {Promise<LevelRoleResult[]>} - The level role object
|
|
37
|
+
* @throws {XpFatal} If there are no roles in the guild.
|
|
38
|
+
*/static async list(guildId){if(guildId)return xp_1.db.find({collection:"simply-xp-levelroles",data:{guild:guildId,lvlrole:{lvl:null,role:null}}});throw new xplogs_1.XpFatal({function:"roleSetup.list()",message:"Guild ID was not provided"})}
|
|
39
|
+
/**
|
|
40
|
+
* Remove a level from the role setup
|
|
41
|
+
* @async
|
|
42
|
+
* @param {string} guildId - The guild ID
|
|
43
|
+
* @param {number} levelNumber - The level number
|
|
44
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
|
|
45
|
+
* @returns {Promise<boolean>} - True if successful
|
|
46
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
47
|
+
*/static async remove(guildId,levelNumber){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Guild ID was not provided"});if(isNaN(levelNumber))throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Level Number was not provided"});return xp_1.db.deleteOne({collection:"simply-xp-levelroles",data:{guild:guildId,lvlrole:{lvl:levelNumber}}})}}exports.roleSetup=roleSetup;
|
package/lib/src/set.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UserResult } from "./functions/database";
|
|
2
|
+
import { XPResult } from "./add";
|
|
3
|
+
/**
|
|
4
|
+
* Set user level
|
|
5
|
+
* @async
|
|
6
|
+
* @param {string} userId
|
|
7
|
+
* @param {string} guildId
|
|
8
|
+
* @param {number} level
|
|
9
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
10
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setlevel
|
|
11
|
+
* @returns {Promise<UserResult>} - Object of user data on success
|
|
12
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
13
|
+
*/
|
|
14
|
+
export declare function setLevel(userId: string, guildId: string, level: number, username?: string): Promise<UserResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Set user XP
|
|
17
|
+
* @async
|
|
18
|
+
* @param {string} userId
|
|
19
|
+
* @param {string} guildId
|
|
20
|
+
* @param {number} xpData
|
|
21
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
22
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setxp
|
|
23
|
+
* @returns {Promise<XPResult>} - Object of user data on success
|
|
24
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
25
|
+
*/
|
|
26
|
+
export declare function setXP(userId: string, guildId: string, xpData: number, username?: string): Promise<XPResult>;
|
package/lib/src/set.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Set user level
|
|
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/next/functions/setlevel
|
|
10
|
+
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
+
*/async function setLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"Guild ID was not provided"});if(isNaN(level))throw new xplogs_1.XpFatal({function:"setLevel()",message:"Level was not provided"});if(await xp_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))return xp_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,xp_1.convertFrom)(level),xp_rate:xp_1.xp.xp_rate}});if(xp_1.xp.auto_create&&username)return xp_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,xp_1.convertFrom)(level),xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"})}
|
|
13
|
+
/**
|
|
14
|
+
* Set user XP
|
|
15
|
+
* @async
|
|
16
|
+
* @param {string} userId
|
|
17
|
+
* @param {string} guildId
|
|
18
|
+
* @param {number} xpData
|
|
19
|
+
* @param {string} username - Username to use if auto_create is enabled
|
|
20
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setxp
|
|
21
|
+
* @returns {Promise<XPResult>} - Object of user data on success
|
|
22
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
23
|
+
*/async function setXP(userId,guildId,xpData,username){var e;if(!userId)throw new xplogs_1.XpFatal({function:"setXP()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setXP()",message:"Guild ID was not provided"});if(isNaN(xpData))throw new xplogs_1.XpFatal({function:"setXP()",message:"XP was not provided"});let l;if(e=await xp_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))l=await xp_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{name:username||e?.name||userId,user:userId,guild:guildId,level:(0,xp_1.convertFrom)(xpData),xp:xpData,xp_rate:xp_1.xp.xp_rate}});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"setXP()",message:"User does not exist"});l=await xp_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,xp_1.convertFrom)(xpData),xp:xpData,xp_rate:xp_1.xp.xp_rate}})}return username=xplogs_1.XpEvents.eventCallback,(xpData=e?.level&&l?.level?l.level!==e.level?l.level-e.level:0:0<l?.level?l.level:0)<0&&username?.levelDown&&"function"==typeof username.levelDown&&username.levelDown(l,await xp_1.roleSetup.getRoles(userId,guildId,{includeNextRoles:!0})),0<xpData&&username?.levelUp&&"function"==typeof username.levelUp&&username.levelUp(l,await xp_1.roleSetup.getRoles(userId,guildId)),{...l,levelDifference:xpData}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setXP=exports.setLevel=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.setLevel=setLevel,exports.setXP=setXP;
|
package/lib/xp.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Database } from "better-sqlite3";
|
|
2
|
+
import { MongoClient } from "mongodb";
|
|
3
|
+
/**
|
|
4
|
+
* XP Plugin
|
|
5
|
+
* @property {string} name - The name of the plugin.
|
|
6
|
+
* @property {Record<string, (arg: number | object | string) => Promise<Array<unknown> | boolean | number | object | string | void>>} functions - The functions to add to the XP client.
|
|
7
|
+
* @property {Function} initialize - The function to run when the plugin is initialized.
|
|
8
|
+
* @property {Array<string>} requiredVersions - Compatible SimplyXP Versions.
|
|
9
|
+
* @returns {Promise<boolean | Error>} - Returns true if the plugin was initialized successfully, otherwise returns an error.
|
|
10
|
+
*/
|
|
11
|
+
export interface Plugin {
|
|
12
|
+
name: string;
|
|
13
|
+
functions?: Record<string, (arg: number | object | string) => Promise<Array<unknown> | boolean | number | object | string | void>>;
|
|
14
|
+
initialize: (client: XPClient) => Promise<void>;
|
|
15
|
+
requiredVersions?: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* User object
|
|
19
|
+
* @property {string} guild - Guild ID
|
|
20
|
+
* @property {string} user - User ID
|
|
21
|
+
* @property {string} name - Username
|
|
22
|
+
* @property {number} position - Position in leaderboard
|
|
23
|
+
* @property {number} level - User level
|
|
24
|
+
* @property {number} xp - User XP
|
|
25
|
+
*/
|
|
26
|
+
export interface User {
|
|
27
|
+
guild: string;
|
|
28
|
+
user: string;
|
|
29
|
+
name?: string | null;
|
|
30
|
+
position: number;
|
|
31
|
+
lastUpdated?: string;
|
|
32
|
+
level: number;
|
|
33
|
+
xp: number;
|
|
34
|
+
}
|
|
35
|
+
export interface XPClient {
|
|
36
|
+
auto_clean: boolean;
|
|
37
|
+
auto_create: boolean;
|
|
38
|
+
database: MongoClient | Database | undefined;
|
|
39
|
+
dbType: "mongodb" | "sqlite";
|
|
40
|
+
debug: boolean;
|
|
41
|
+
notify: boolean;
|
|
42
|
+
registeredFonts: string[];
|
|
43
|
+
version: string;
|
|
44
|
+
xp_rate: number;
|
|
45
|
+
}
|
|
46
|
+
export { addLevel, addXP } from "./src/add";
|
|
47
|
+
export { db } from "./src/functions/database";
|
|
48
|
+
export { charts } from "./src/charts";
|
|
49
|
+
export { compareCard, leaderboardCard, rankCard } from "./src/cards";
|
|
50
|
+
export { connect } from "./src/connect";
|
|
51
|
+
export { clean, convertFrom, registerFont, registerPlugins, updateOptions } from "./src/functions/utilities";
|
|
52
|
+
export { create } from "./src/create";
|
|
53
|
+
export { fetch } from "./src/fetch";
|
|
54
|
+
export { https } from "./src/functions/https";
|
|
55
|
+
export { leaderboard } from "./src/leaderboard";
|
|
56
|
+
export { migrate } from "./src/migrate";
|
|
57
|
+
export { removeLevel, removeXP } from "./src/remove";
|
|
58
|
+
export { reset } from "./src/reset";
|
|
59
|
+
export { roleSetup } from "./src/roleSetup";
|
|
60
|
+
export { setLevel, setXP } from "./src/set";
|
|
61
|
+
export { XpEvents } from "./src/functions/xplogs";
|
|
62
|
+
export declare const xp: XPClient;
|
package/lib/xp.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.xp = exports.XpEvents = exports.setXP = exports.setLevel = exports.roleSetup = exports.reset = exports.removeXP = exports.removeLevel = exports.migrate = exports.leaderboard = exports.https = exports.fetch = exports.create = exports.updateOptions = exports.registerPlugins = exports.registerFont = exports.convertFrom = exports.clean = exports.connect = exports.rankCard = exports.leaderboardCard = exports.compareCard = exports.charts = exports.db = exports.addXP = exports.addLevel = void 0;
|
|
4
|
+
// FUNCTION/CLASS EXPORTS
|
|
5
|
+
var add_1 = require("./src/add");
|
|
6
|
+
Object.defineProperty(exports, "addLevel", { enumerable: true, get: function () { return add_1.addLevel; } });
|
|
7
|
+
Object.defineProperty(exports, "addXP", { enumerable: true, get: function () { return add_1.addXP; } });
|
|
8
|
+
var database_1 = require("./src/functions/database");
|
|
9
|
+
Object.defineProperty(exports, "db", { enumerable: true, get: function () { return database_1.db; } });
|
|
10
|
+
var charts_1 = require("./src/charts");
|
|
11
|
+
Object.defineProperty(exports, "charts", { enumerable: true, get: function () { return charts_1.charts; } });
|
|
12
|
+
var cards_1 = require("./src/cards");
|
|
13
|
+
Object.defineProperty(exports, "compareCard", { enumerable: true, get: function () { return cards_1.compareCard; } });
|
|
14
|
+
Object.defineProperty(exports, "leaderboardCard", { enumerable: true, get: function () { return cards_1.leaderboardCard; } });
|
|
15
|
+
Object.defineProperty(exports, "rankCard", { enumerable: true, get: function () { return cards_1.rankCard; } });
|
|
16
|
+
var connect_1 = require("./src/connect");
|
|
17
|
+
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connect_1.connect; } });
|
|
18
|
+
var utilities_1 = require("./src/functions/utilities");
|
|
19
|
+
Object.defineProperty(exports, "clean", { enumerable: true, get: function () { return utilities_1.clean; } });
|
|
20
|
+
Object.defineProperty(exports, "convertFrom", { enumerable: true, get: function () { return utilities_1.convertFrom; } });
|
|
21
|
+
Object.defineProperty(exports, "registerFont", { enumerable: true, get: function () { return utilities_1.registerFont; } });
|
|
22
|
+
Object.defineProperty(exports, "registerPlugins", { enumerable: true, get: function () { return utilities_1.registerPlugins; } });
|
|
23
|
+
Object.defineProperty(exports, "updateOptions", { enumerable: true, get: function () { return utilities_1.updateOptions; } });
|
|
24
|
+
var create_1 = require("./src/create");
|
|
25
|
+
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return create_1.create; } });
|
|
26
|
+
var fetch_1 = require("./src/fetch");
|
|
27
|
+
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
|
|
28
|
+
var https_1 = require("./src/functions/https");
|
|
29
|
+
Object.defineProperty(exports, "https", { enumerable: true, get: function () { return https_1.https; } });
|
|
30
|
+
var leaderboard_1 = require("./src/leaderboard");
|
|
31
|
+
Object.defineProperty(exports, "leaderboard", { enumerable: true, get: function () { return leaderboard_1.leaderboard; } });
|
|
32
|
+
var migrate_1 = require("./src/migrate");
|
|
33
|
+
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migrate_1.migrate; } });
|
|
34
|
+
var remove_1 = require("./src/remove");
|
|
35
|
+
Object.defineProperty(exports, "removeLevel", { enumerable: true, get: function () { return remove_1.removeLevel; } });
|
|
36
|
+
Object.defineProperty(exports, "removeXP", { enumerable: true, get: function () { return remove_1.removeXP; } });
|
|
37
|
+
var reset_1 = require("./src/reset");
|
|
38
|
+
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
|
|
39
|
+
var roleSetup_1 = require("./src/roleSetup");
|
|
40
|
+
Object.defineProperty(exports, "roleSetup", { enumerable: true, get: function () { return roleSetup_1.roleSetup; } });
|
|
41
|
+
var set_1 = require("./src/set");
|
|
42
|
+
Object.defineProperty(exports, "setLevel", { enumerable: true, get: function () { return set_1.setLevel; } });
|
|
43
|
+
Object.defineProperty(exports, "setXP", { enumerable: true, get: function () { return set_1.setXP; } });
|
|
44
|
+
var xplogs_1 = require("./src/functions/xplogs");
|
|
45
|
+
Object.defineProperty(exports, "XpEvents", { enumerable: true, get: function () { return xplogs_1.XpEvents; } });
|
|
46
|
+
exports.xp = {
|
|
47
|
+
auto_clean: false,
|
|
48
|
+
auto_create: false,
|
|
49
|
+
database: undefined,
|
|
50
|
+
dbType: "mongodb",
|
|
51
|
+
debug: false,
|
|
52
|
+
notify: true,
|
|
53
|
+
registeredFonts: [],
|
|
54
|
+
version: "2.0.0-beta.0",
|
|
55
|
+
xp_rate: 0.1
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,55 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"typings": "index.d.ts",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "The easiest way to implement xp system",
|
|
5
|
+
"main": "lib/xp.js",
|
|
7
6
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"beta": "node Tests/clean.mjs && pnpm update && npm publish --tag beta",
|
|
8
|
+
"dev": "node Tests/clean.mjs && pnpm update && npm publish --tag dev",
|
|
9
|
+
"latest": "node Tests/clean.mjs && pnpm update && npm publish",
|
|
10
|
+
"test": "node Tests/clean.mjs && node Tests/test.cjs"
|
|
11
11
|
},
|
|
12
|
-
"author": "
|
|
12
|
+
"author": "Abadima",
|
|
13
13
|
"keywords": [
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"mongoose",
|
|
14
|
+
"amaribot",
|
|
15
|
+
"canvacord",
|
|
16
|
+
"charts",
|
|
17
|
+
"compare",
|
|
18
|
+
"compete",
|
|
20
19
|
"discord",
|
|
21
|
-
"discord xp",
|
|
22
|
-
"discord-xp",
|
|
23
|
-
"simply-djs",
|
|
24
20
|
"discord.js",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"level role",
|
|
30
|
-
"amari",
|
|
31
|
-
"package",
|
|
21
|
+
"discord-xp",
|
|
22
|
+
"easy",
|
|
23
|
+
"fun",
|
|
24
|
+
"guilded",
|
|
32
25
|
"leaderboard",
|
|
26
|
+
"level",
|
|
27
|
+
"leveling",
|
|
33
28
|
"mee6",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
29
|
+
"mongodb",
|
|
30
|
+
"package",
|
|
31
|
+
"simply",
|
|
32
|
+
"simply-djs",
|
|
33
|
+
"simplydjs",
|
|
34
|
+
"slack",
|
|
35
|
+
"sqlite",
|
|
36
|
+
"system",
|
|
37
|
+
"xp"
|
|
37
38
|
],
|
|
38
39
|
"license": "Apache-2.0",
|
|
39
40
|
"repository": {
|
|
40
41
|
"type": "git",
|
|
41
42
|
"url": "git+https://github.com/Abadima/simply-xp.git"
|
|
42
43
|
},
|
|
43
|
-
"homepage": "https://simplyxp.js.org",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@napi-rs/canvas": "
|
|
46
|
-
"chart.js": "^3.9.1",
|
|
47
|
-
"mongoose": "^7.4.2"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"discord.js": ">=13.12.0"
|
|
45
|
+
"@napi-rs/canvas": "0.1.41"
|
|
51
46
|
},
|
|
52
47
|
"devDependencies": {
|
|
53
|
-
"eslint": "^
|
|
48
|
+
"@eslint/eslintrc": "^2.1.4",
|
|
49
|
+
"@types/better-sqlite3": "^7.6.8",
|
|
50
|
+
"@types/node": "^20.10.5",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
|
52
|
+
"@typescript-eslint/parser": "^6.16.0",
|
|
53
|
+
"better-sqlite3": "^9.2.2",
|
|
54
|
+
"eslint": "^8.56.0",
|
|
55
|
+
"mongodb": "^6.3.0",
|
|
56
|
+
"typescript": "^5.3.3",
|
|
57
|
+
"uglify-js": "^3.17.4"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=15.5.0"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/Abadima/simply-xp/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://simplyxp.js.org",
|
|
66
|
+
"directories": {
|
|
67
|
+
"lib": "lib"
|
|
54
68
|
}
|
|
55
69
|
}
|
package/index.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Message, Client } from 'discord.js'
|
|
2
|
-
|
|
3
|
-
type HexColorString = `#${string}` | string
|
|
4
|
-
|
|
5
|
-
export type connectOptions = {
|
|
6
|
-
auto_purge?: boolean,
|
|
7
|
-
notify?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export declare function connect(
|
|
11
|
-
db: string,
|
|
12
|
-
options?: connectOptions
|
|
13
|
-
): Promise<any>
|
|
14
|
-
|
|
15
|
-
export declare function addLevel(
|
|
16
|
-
message: Message,
|
|
17
|
-
userID: string,
|
|
18
|
-
guildID: string,
|
|
19
|
-
level: number
|
|
20
|
-
): Promise<any>
|
|
21
|
-
|
|
22
|
-
export declare function addXP(
|
|
23
|
-
message: Message,
|
|
24
|
-
userID: string,
|
|
25
|
-
guildID: string,
|
|
26
|
-
xp: number
|
|
27
|
-
): Promise<any>
|
|
28
|
-
|
|
29
|
-
export type chartsOptions = {
|
|
30
|
-
position?: string
|
|
31
|
-
background?: HexColorString
|
|
32
|
-
type?: 'bar' | 'line' | 'radar' | 'doughnut' | 'polarArea'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export declare function charts(
|
|
36
|
-
message: Message,
|
|
37
|
-
options?: chartsOptions
|
|
38
|
-
): Promise<any>
|
|
39
|
-
|
|
40
|
-
export declare function create(userID: string, guildID: string): Promise<any>
|
|
41
|
-
|
|
42
|
-
export declare function fetch(userID: string, guildID: string): Promise<any>
|
|
43
|
-
|
|
44
|
-
export declare function leaderboard(
|
|
45
|
-
userID: string,
|
|
46
|
-
guildID: string,
|
|
47
|
-
limit?: number
|
|
48
|
-
): Promise<any>
|
|
49
|
-
|
|
50
|
-
export declare function lvlRole(
|
|
51
|
-
message: Message,
|
|
52
|
-
userID: string,
|
|
53
|
-
guildID: string
|
|
54
|
-
): Promise<any>
|
|
55
|
-
|
|
56
|
-
export type rankOptions = {
|
|
57
|
-
slash?: boolean
|
|
58
|
-
background?: string
|
|
59
|
-
color?: HexColorString
|
|
60
|
-
}
|
|
61
|
-
export declare function rank(
|
|
62
|
-
message: Message,
|
|
63
|
-
userID: string,
|
|
64
|
-
guildID: string,
|
|
65
|
-
options?: rankOptions
|
|
66
|
-
): Promise<any>
|
|
67
|
-
|
|
68
|
-
export declare function reset(userID: string, guildID: string): Promise<any>
|
|
69
|
-
|
|
70
|
-
export type lvladdOptions = {
|
|
71
|
-
level: string
|
|
72
|
-
role: string
|
|
73
|
-
}
|
|
74
|
-
export type lvlremoveOptions = {
|
|
75
|
-
level: string
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export declare function setLevel(
|
|
79
|
-
message: Message,
|
|
80
|
-
userID: string,
|
|
81
|
-
guildID: string,
|
|
82
|
-
level: number
|
|
83
|
-
): Promise<any>
|
|
84
|
-
|
|
85
|
-
export declare function setXP(
|
|
86
|
-
userID: string,
|
|
87
|
-
guildID: string,
|
|
88
|
-
xp: number
|
|
89
|
-
): Promise<any>
|
|
90
|
-
|
|
91
|
-
/** For levelUp event */
|
|
92
|
-
export type Data = {
|
|
93
|
-
xp: string
|
|
94
|
-
level: number
|
|
95
|
-
userID: string
|
|
96
|
-
guildID: string
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export type Role = {
|
|
100
|
-
lvl: string
|
|
101
|
-
role: string
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
declare module 'discord.js' {
|
|
105
|
-
export interface ClientEvents {
|
|
106
|
-
levelUp: [Message, Data, Role]
|
|
107
|
-
}
|
|
108
|
-
}
|
package/simplyxp.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
try {
|
|
2
|
-
require("discord.js");
|
|
3
|
-
} catch (e) {
|
|
4
|
-
console.warn("[XP] Discord.js is recommended for this package.");
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
module.exports.options = {auto_purge: false};
|
|
8
|
-
|
|
9
|
-
module.exports.roleSetup = require("./src/roleSetup");
|
|
10
|
-
|
|
11
|
-
module.exports.addLevel = require("./src/addLevel");
|
|
12
|
-
|
|
13
|
-
module.exports.addXP = require("./src/addXP");
|
|
14
|
-
|
|
15
|
-
module.exports.charts = require("./src/charts");
|
|
16
|
-
|
|
17
|
-
module.exports.connect = require("./src/connect");
|
|
18
|
-
|
|
19
|
-
module.exports.create = require("./src/create");
|
|
20
|
-
|
|
21
|
-
module.exports.fetch = require("./src/fetch");
|
|
22
|
-
|
|
23
|
-
module.exports.leaderboard = require("./src/leaderboard");
|
|
24
|
-
|
|
25
|
-
module.exports.lvlRole = require("./src/lvlRole");
|
|
26
|
-
|
|
27
|
-
module.exports.rank = require("./src/rank");
|
|
28
|
-
|
|
29
|
-
module.exports.setLevel = require("./src/setLevel");
|
|
30
|
-
|
|
31
|
-
module.exports.setXP = require("./src/setXP");
|
|
32
|
-
|
|
33
|
-
module.exports.reset = require("./src/reset");
|
|
Binary file
|