simply-xp 2.0.0-beta.2 → 2.0.0-beta.3
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 +41 -36
- package/lib/src/add.d.ts +1 -1
- package/lib/src/add.js +2 -2
- package/lib/src/cards.d.ts +1 -1
- package/lib/src/cards.js +2 -2
- package/lib/src/charts.js +1 -1
- package/lib/src/{functions/database.d.ts → classes/Database.d.ts} +48 -32
- package/lib/src/classes/Database.js +79 -0
- package/lib/src/classes/LevelRoles.d.ts +88 -0
- package/lib/src/classes/LevelRoles.js +55 -0
- package/lib/src/classes/Migrate.d.ts +42 -0
- package/lib/src/classes/Migrate.js +31 -0
- package/lib/src/connect.js +28 -20
- package/lib/src/create.d.ts +1 -1
- package/lib/src/create.js +1 -1
- package/lib/src/fetch.js +1 -1
- package/lib/src/functions/https.js +1 -1
- package/lib/src/functions/utilities.js +7 -7
- package/lib/src/functions/xplogs.d.ts +1 -1
- package/lib/src/functions/xplogs.js +4 -4
- package/lib/src/leaderboard.js +1 -1
- package/lib/src/remove.d.ts +1 -1
- package/lib/src/remove.js +2 -2
- package/lib/src/reset.js +1 -1
- package/lib/src/set.d.ts +1 -1
- package/lib/src/set.js +2 -2
- package/lib/src/setFlags.d.ts +1 -1
- package/lib/src/setFlags.js +1 -1
- package/lib/xp.d.ts +6 -6
- package/lib/xp.js +10 -8
- package/package.json +7 -7
- package/lib/src/functions/database.js +0 -79
- package/lib/src/migrate.d.ts +0 -27
- package/lib/src/migrate.js +0 -19
- package/lib/src/roleSetup.d.ts +0 -78
- package/lib/src/roleSetup.js +0 -47
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LevelRoleResult } from "./Database";
|
|
2
|
+
/**
|
|
3
|
+
* Get Roles Object
|
|
4
|
+
* @property {boolean} [includeCurrent=true] - Include roles for the current level
|
|
5
|
+
* @property {boolean} [includeNext=false] - Include roles for the next levels
|
|
6
|
+
* @property {boolean} [includePrevious=false] - Include roles for the previous levels
|
|
7
|
+
*/
|
|
8
|
+
type GetRolesOptions = {
|
|
9
|
+
includeCurrent?: boolean;
|
|
10
|
+
includeNext?: boolean;
|
|
11
|
+
includePrevious?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Role setup object
|
|
15
|
+
* @property {number} level - The level number
|
|
16
|
+
* @property {string[]} roles - The role(s) to add
|
|
17
|
+
*/
|
|
18
|
+
export interface LevelRole {
|
|
19
|
+
level: number;
|
|
20
|
+
roles: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Setup roles for levels
|
|
24
|
+
* @class LevelRoles
|
|
25
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles
|
|
26
|
+
*/
|
|
27
|
+
export declare class LevelRoles {
|
|
28
|
+
/**
|
|
29
|
+
* Add a role to the role setup
|
|
30
|
+
* @async
|
|
31
|
+
* @param {string} guildId - The guild ID
|
|
32
|
+
* @param {LevelRole} options - Level and role to add
|
|
33
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesadd
|
|
34
|
+
* @returns {Promise<boolean>} - True if successful
|
|
35
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
36
|
+
*/
|
|
37
|
+
static add(guildId: string, options: LevelRole): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Delete some or all roles from the level.
|
|
40
|
+
* @async
|
|
41
|
+
* @param {string} guildId - The guild ID
|
|
42
|
+
* @param {LevelRole} options - Level and/or roles to delete
|
|
43
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesdelete
|
|
44
|
+
* @returns {Promise<boolean>} - True if successful
|
|
45
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
46
|
+
*/
|
|
47
|
+
static delete(guildId: string, options: LevelRole): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete all roles in a guild's role setup
|
|
50
|
+
* @async
|
|
51
|
+
* @param {string} guildId - The guild ID
|
|
52
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesdeleteall
|
|
53
|
+
* @returns {Promise<boolean>} - True if successful
|
|
54
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
55
|
+
*/
|
|
56
|
+
static deleteAll(guildId: string): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Fetch all roles in a guild's role setup
|
|
59
|
+
* @async
|
|
60
|
+
* @param {string} guildId - The guild ID
|
|
61
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesfetchall
|
|
62
|
+
* @returns {Promise<LevelRoleResult[]>} - The level role object
|
|
63
|
+
* @throws {XpFatal} If there are no roles in the guild.
|
|
64
|
+
*/
|
|
65
|
+
static getGuildRoles(guildId: string): Promise<LevelRoleResult[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Get roles for a user's level
|
|
68
|
+
* @async
|
|
69
|
+
* @param {string} userId - The user ID
|
|
70
|
+
* @param {string} guildId - The guild ID
|
|
71
|
+
* @param {GetRolesOptions} options - Options
|
|
72
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#getuserroles
|
|
73
|
+
* @returns {Promise<string[]>} - Array of role IDs or empty array if none
|
|
74
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
75
|
+
*/
|
|
76
|
+
static getUserRoles(userId: string, guildId: string, options?: GetRolesOptions): Promise<string[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Set roles for a level (overwrites existing roles)
|
|
79
|
+
* @async
|
|
80
|
+
* @param {string} guildId - The guild ID
|
|
81
|
+
* @param {LevelRole} options - Level and role to set
|
|
82
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesset
|
|
83
|
+
* @returns {Promise<boolean>} - True if successful
|
|
84
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
85
|
+
*/
|
|
86
|
+
static set(guildId: string, options: LevelRole): Promise<boolean>;
|
|
87
|
+
}
|
|
88
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.LevelRoles=void 0;let xp_1=require("../../xp"),xplogs_1=require("../functions/xplogs");class LevelRoles{
|
|
2
|
+
/**
|
|
3
|
+
* Add a role to the role setup
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} guildId - The guild ID
|
|
6
|
+
* @param {LevelRole} options - Level and role to add
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesadd
|
|
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(e,l){if(!e)throw new xplogs_1.XpFatal({function:"LevelRoles.add()",message:"Guild ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"LevelRoles.add()",message:"Options were not provided"});if(isNaN(l?.level))throw new xplogs_1.XpFatal({function:"LevelRoles.add()",message:"Level must be a number"});var s;if(l?.roles&&Array.isArray(l?.roles)&&0!==l?.roles.length)return(s=await xp_1.db.findOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}}))&&(l.roles=Array.from(new Set([...s.levelrole.roles||[],...l.roles]))),xp_1.db.updateOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}},{collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level,roles:l.roles}}},{upsert:!0}).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"LevelRoles.add()",message:"Roles must be a non-empty array of strings"});}
|
|
12
|
+
/**
|
|
13
|
+
* Delete some or all roles from the level.
|
|
14
|
+
* @async
|
|
15
|
+
* @param {string} guildId - The guild ID
|
|
16
|
+
* @param {LevelRole} options - Level and/or roles to delete
|
|
17
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesdelete
|
|
18
|
+
* @returns {Promise<boolean>} - True if successful
|
|
19
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
20
|
+
*/static async delete(e,l){if(!e)throw new xplogs_1.XpFatal({function:"LevelRoles.delete()",message:"Guild ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"LevelRoles.delete()",message:"Options were not provided"});if(isNaN(l?.level))throw new xplogs_1.XpFatal({function:"LevelRoles.delete()",message:"Level must be a number"});var s;if(!l?.roles||Array.isArray(l?.roles)&&0!==l?.roles.length)return!!(s=await xp_1.db.findOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}}))&&(0===(s=l.roles?(s.levelrole.roles||[]).filter(e=>!l.roles.includes(e)):[]).length?xp_1.db.deleteOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}}):xp_1.db.updateOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}},{collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level,roles:s}}})).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"LevelRoles.delete()",message:"Roles must be a non-empty array of strings"});}
|
|
21
|
+
/**
|
|
22
|
+
* Delete all roles in a guild's role setup
|
|
23
|
+
* @async
|
|
24
|
+
* @param {string} guildId - The guild ID
|
|
25
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesdeleteall
|
|
26
|
+
* @returns {Promise<boolean>} - True if successful
|
|
27
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
28
|
+
*/static async deleteAll(e){if(e)return xp_1.db.deleteMany({collection:"simply-xp-levelroles",data:{guild:e}}).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"LevelRoles.deleteAll()",message:"Guild ID was not provided"});}
|
|
29
|
+
/**
|
|
30
|
+
* Fetch all roles in a guild's role setup
|
|
31
|
+
* @async
|
|
32
|
+
* @param {string} guildId - The guild ID
|
|
33
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesfetchall
|
|
34
|
+
* @returns {Promise<LevelRoleResult[]>} - The level role object
|
|
35
|
+
* @throws {XpFatal} If there are no roles in the guild.
|
|
36
|
+
*/static async getGuildRoles(e){if(e)return xp_1.db.find("simply-xp-levelroles",e);throw new xplogs_1.XpFatal({function:"LevelRoles.fetchAll()",message:"Guild ID was not provided"});}
|
|
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 {GetRolesOptions} options - Options
|
|
43
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#getuserroles
|
|
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
|
+
*/static async getUserRoles(e,l,s={}){if(!e)throw new xplogs_1.XpFatal({function:"LevelRoles.getUserRoles()",message:"User ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"LevelRoles.getUserRoles()",message:"Guild ID was not provided"});let o=await xp_1.db.findOne({collection:"simply-xps",data:{user:e,guild:l}});if(!o?.level)return[];let t=await LevelRoles.getGuildRoles(l),{includeCurrent:a=!0,includeNext:r=!1,includePrevious:n=!1}=s;return t.reduce((e,{levelrole:{level:l,roles:s}})=>((a&&l===o.level||r&&l>o.level||n&&l<o.level)&&s?.length&&e.push(...s),e),[]);}
|
|
47
|
+
/**
|
|
48
|
+
* Set roles for a level (overwrites existing roles)
|
|
49
|
+
* @async
|
|
50
|
+
* @param {string} guildId - The guild ID
|
|
51
|
+
* @param {LevelRole} options - Level and role to set
|
|
52
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/LevelRoles#levelrolesset
|
|
53
|
+
* @returns {Promise<boolean>} - True if successful
|
|
54
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
55
|
+
*/static async set(e,l){if(!e)throw new xplogs_1.XpFatal({function:"LevelRoles.set()",message:"Guild ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"LevelRoles.set()",message:"Options were not provided"});if(isNaN(l?.level))throw new xplogs_1.XpFatal({function:"LevelRoles.set()",message:"Level must be a number"});if(Array.isArray(l?.roles)&&0!==l?.roles.length)return xp_1.db.updateOne({collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level}}},{collection:"simply-xp-levelroles",data:{guild:e,levelrole:{level:l.level,roles:l.roles}}},{upsert:!0}).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"LevelRoles.set()",message:"Roles must be a non-empty array of strings"});}}exports.LevelRoles=LevelRoles;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Database as SQLiteClient } from "better-sqlite3";
|
|
2
|
+
import { MongoClient } from "mongodb";
|
|
3
|
+
/**
|
|
4
|
+
* Migration functions
|
|
5
|
+
* @class Migrate
|
|
6
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/Migrate
|
|
7
|
+
*/
|
|
8
|
+
export declare class Migrate {
|
|
9
|
+
/**
|
|
10
|
+
* Effortlessly migrate from discord-xp to simply-xp.
|
|
11
|
+
* @async
|
|
12
|
+
* @param {boolean} deleteOld - Delete old data after migration
|
|
13
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratediscord_xp
|
|
14
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
15
|
+
* @throws {XpLog.err} - If migration fails.
|
|
16
|
+
*/
|
|
17
|
+
static discord_xp(deleteOld?: boolean): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Effortlessly migrate from MongoDB to SQLite. (or vice versa)
|
|
20
|
+
* @async
|
|
21
|
+
* @param {"mongodb"|"sqlite"} dbType
|
|
22
|
+
* @param {SQLiteClient | MongoClient} connection
|
|
23
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratefromdb
|
|
24
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
25
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
26
|
+
*/
|
|
27
|
+
static fromDB(dbType: "mongodb" | "sqlite", connection: SQLiteClient | MongoClient): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Effortlessly migrate from roleSetup's schema to LevelRoles schema.
|
|
30
|
+
* @async
|
|
31
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migraterolesetup
|
|
32
|
+
* @param {boolean} keepOld - Keep old data after migration
|
|
33
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
34
|
+
* @throws {XpLog.err} - If migration fails.
|
|
35
|
+
*/
|
|
36
|
+
static roleSetup(keepOld?: boolean): Promise<boolean>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Exports the `Migrate` class as `migrate`.
|
|
40
|
+
* @deprecated Use `Migrate` class instead, this will be removed in the near future.
|
|
41
|
+
*/
|
|
42
|
+
export declare const migrate: typeof Migrate;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.migrate=exports.Migrate=void 0;let xplogs_1=require("../functions/xplogs"),Database_1=require("./Database"),connect_1=require("../connect"),xp_1=require("../../xp");class Migrate{
|
|
2
|
+
/**
|
|
3
|
+
* Effortlessly migrate from discord-xp to simply-xp.
|
|
4
|
+
* @async
|
|
5
|
+
* @param {boolean} deleteOld - Delete old data after migration
|
|
6
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratediscord_xp
|
|
7
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
8
|
+
* @throws {XpLog.err} - If migration fails.
|
|
9
|
+
*/
|
|
10
|
+
static async discord_xp(e=!1){var a,l=await xp_1.db.getCollection("levels").find().toArray();
|
|
11
|
+
/**
|
|
12
|
+
* Effortlessly migrate from MongoDB to SQLite. (or vice versa)
|
|
13
|
+
* @async
|
|
14
|
+
* @param {"mongodb"|"sqlite"} dbType
|
|
15
|
+
* @param {SQLiteClient | MongoClient} connection
|
|
16
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratefromdb
|
|
17
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
18
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
19
|
+
*/xplogs_1.XpLog.debug("migrate.discord_xp()",`FOUND ${l.length} DOCUMENTS`);try{for(a of l)await xp_1.db.findOne({collection:"simply-xps",data:{guild:a.guildID,user:a.userID}})||(await xp_1.db.createOne({collection:"simply-xps",data:{guild:a.guildID,user:a.userID,xp:a.xp,level:(0,xp_1.convertFrom)(a.xp,"xp")}}),e&&await xp_1.db.getCollection("levels").deleteOne({userID:a.userID,guildID:a.guildID}));return!0;}catch(e){return xplogs_1.XpLog.err("migrate.discord_xp()",e),!1;}}static async fromDB(e,a){if(!e)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database type provided"});if(!a)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database connection provided"});if(xp_1.xp.dbType===e)return xplogs_1.XpLog.info("migrate.fromDB()","Same database received, that was unnecessary!");let l;switch(e){case"mongodb":try{switch(await(0,connect_1.checkPackageVersion)("mongodb",3,7)){case"too_low":throw new xplogs_1.XpFatal({function:"migrate.fromDB()",message:"MongoDB V3 OR NEWER IS REQUIRED"});case"too_high":xplogs_1.XpLog.warn("migrate.fromDB()","MongoDB VERSION IS NEWER THAN TESTED (V7) -- CONTINUE WITH CAUTION");break;case"ok":xplogs_1.XpLog.debug("migrate.fromDB()","MongoDB is natively compatible with our package! 🎉");}l=await a.db().collection("simply-xps").find().toArray();}catch(e){return xplogs_1.XpLog.err("migrate.fromDB()",e),!1;}break;case"sqlite":try{switch(await(0,connect_1.checkPackageVersion)("better-sqlite3",7,12)){case"too_low":throw new xplogs_1.XpFatal({function:"migrate.fromDB()",message:"BETTER-SQLITE3 V7 OR NEWER IS REQUIRED"});case"too_high":xplogs_1.XpLog.warn("migrate.fromDB()","BETTER-SQLITE3 VERSION IS NEWER THAN TESTED (V12) -- CONTINUE WITH CAUTION");break;case"ok":xplogs_1.XpLog.debug("migrate.fromDB()","better-sqlite3 is natively compatible with our package! 🎉");}l=a.prepare("SELECT * FROM `simply-xps`").all();}catch(e){return xplogs_1.XpLog.err("migrate.fromDB()",e),!1;}}return xplogs_1.XpLog.debug("migrate.fromDB()",`FOUND ${l.length} RESULTS`),await Promise.all(l.map(async e=>await xp_1.db.findOne({collection:"simply-xps",data:{guild:e.guild,user:e.user}})?xp_1.db.updateOne({collection:"simply-xps",data:{guild:e.guild,user:e.user}},{collection:"simply-xps",data:{guild:e.guild,user:e.user,name:e.name,xp:e.xp,level:e.level}}):xp_1.db.createOne({collection:"simply-xps",data:{guild:e.guild,user:e.user,xp:e.xp,level:e.level}}))),!0;}
|
|
20
|
+
/**
|
|
21
|
+
* Effortlessly migrate from roleSetup's schema to LevelRoles schema.
|
|
22
|
+
* @async
|
|
23
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migraterolesetup
|
|
24
|
+
* @param {boolean} keepOld - Keep old data after migration
|
|
25
|
+
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
26
|
+
* @throws {XpLog.err} - If migration fails.
|
|
27
|
+
*/static async roleSetup(e=!1){var a,l,t,r=await Database_1.Database.findAll("simply-xp-levelroles");xplogs_1.XpLog.debug("migrate.roleSetup()",`FOUND ${r.length} DOCUMENTS`);try{for(a of r)if((l=a.lvlrole)&&!a.levelrole&&(t=Array.isArray(l.role)?l.role:[l.role],await Database_1.Database.createOne({collection:"simply-xp-levelroles",data:{guild:a.guild,levelrole:{level:l.lvl,roles:t}}}),!e))switch(xp_1.xp.dbType){case"mongodb":await Database_1.Database.getCollection("simply-xp-levelroles").deleteOne({guild:a.guild,lvlrole:l});break;case"sqlite":xp_1.xp.database.prepare("DELETE FROM `simply-xp-levelroles` WHERE gid = ? AND lvlrole = ?").run(a.guild,JSON.stringify(l));}return"sqlite"!==xp_1.xp.dbType||e||xp_1.xp.database.exec(`
|
|
28
|
+
CREATE TABLE "simply-xp-levelroles_tmp" AS SELECT gid, levelrole, createdAt, lastUpdated FROM "simply-xp-levelroles";
|
|
29
|
+
DROP TABLE "simply-xp-levelroles";
|
|
30
|
+
ALTER TABLE "simply-xp-levelroles_tmp" RENAME TO "simply-xp-levelroles";
|
|
31
|
+
`),!0;}catch(e){return xplogs_1.XpLog.err("migrate.roleSetup()",e);}}}exports.Migrate=Migrate,exports.migrate=Migrate;
|
package/lib/src/connect.js
CHANGED
|
@@ -8,29 +8,37 @@
|
|
|
8
8
|
* @returns {Promise<boolean>}
|
|
9
9
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
10
10
|
*/
|
|
11
|
-
async function connect(e,t={type:void 0}){var
|
|
11
|
+
async function connect(e,t={type:void 0}){var a,{type:o,auto_create:n,auto_clean:r,notify:c,debug:s,xp_rate:p}=t;
|
|
12
12
|
/**
|
|
13
13
|
* Returns the package manager used
|
|
14
14
|
* @private
|
|
15
15
|
* @returns {Promise<"yarn" | "npm" | "pnpm">}
|
|
16
|
-
*/if(!
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
*/if(!p||"slow"!==p&&"normal"!==p&&"fast"!==p&&isNaN(p)||(xp_1.xp.xp_rate="slow"===p?.05:"normal"===p?.1:"fast"===p?.5:p),!e)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===c&&(xp_1.xp.notify=!1),n&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_clean=!0),s&&(xp_1.xp.debug=!0),o||(t.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),o){case"mongodb":switch(await checkPackageVersion("mongodb",3,7)){case"too_low":throw new xplogs_1.XpFatal({function:"connect()",message:"MONGODB V3 OR NEWER IS REQUIRED"});case"too_high":xplogs_1.XpLog.warn("connect()","MONGODB VERSION IS NEWER THAN TESTED (V7) -- CONTINUE WITH CAUTION");break;case"ok":xplogs_1.XpLog.debug("connect()","MongoDB is natively compatible with our package! 🎉");}xplogs_1.XpLog.debug("[connect()]","ATTEMPTING MONGODB CONNECTION"),a=await(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient.connect(e).catch(e=>{throw new xplogs_1.XpFatal({function:"connect()",message:e.message});}),xp_1.xp.dbType="mongodb",xp_1.xp.database=a||void 0;break;case"sqlite":try{switch(await checkPackageVersion("better-sqlite3",7,12)){case"too_low":throw new xplogs_1.XpFatal({function:"connect()",message:"BETTER-SQLITE3 V7 OR NEWER IS REQUIRED"});case"too_high":xplogs_1.XpLog.warn("connect()","BETTER-SQLITE3 VERSION IS NEWER THAN TESTED (V12) -- CONTINUE WITH CAUTION");break;case"ok":xplogs_1.XpLog.debug("connect()","better-sqlite3 is natively compatible with our package! 🎉");}xp_1.xp.database=new(await Promise.resolve().then(()=>__importStar(require("better-sqlite3")))).default(e),xplogs_1.XpLog.info("[connect()]","Successfully connected to SQLite database."),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`
|
|
17
|
+
CREATE TABLE IF NOT EXISTS "simply-xps" (
|
|
18
|
+
user TEXT NOT NULL,
|
|
19
|
+
guild TEXT NOT NULL,
|
|
20
|
+
name TEXT NOT NULL DEFAULT user,
|
|
21
|
+
level INTEGER NOT NULL DEFAULT 0,
|
|
22
|
+
flags TEXT DEFAULT NULL,
|
|
23
|
+
xp INTEGER NOT NULL DEFAULT 0,
|
|
24
|
+
voice_xp INTEGER DEFAULT 0,
|
|
25
|
+
voice_time INTEGER DEFAULT 0,
|
|
26
|
+
xp_rate INTEGER DEFAULT 0.1,
|
|
27
|
+
createdAt DATE NOT NULL DEFAULT (datetime('now')),
|
|
28
|
+
lastUpdated DATE NOT NULL DEFAULT (datetime('now'))
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE TABLE IF NOT EXISTS "simply-xp-levelroles" (
|
|
32
|
+
gid TEXT NOT NULL,
|
|
33
|
+
levelrole TEXT NOT NULL,
|
|
34
|
+
createdAt DATE NOT NULL DEFAULT (datetime('now')),
|
|
35
|
+
lastUpdated DATE NOT NULL DEFAULT (datetime('now'))
|
|
36
|
+
);
|
|
37
|
+
`);try{xp_1.xp.database.exec(`
|
|
38
|
+
ALTER TABLE "simply-xps" ADD COLUMN createdAt DATE NOT NULL DEFAULT (datetime('now'));
|
|
39
|
+
ALTER TABLE "simply-xp-levelroles" ADD COLUMN createdAt DATE NOT NULL DEFAULT (datetime('now'));
|
|
40
|
+
ALTER TABLE "simply-xp-levelroles" ADD COLUMN levelrole TEXT NOT NULL DEFAULT '{}';
|
|
41
|
+
`);}catch{}}catch(e){if("object"==typeof e&&null!==e&&void 0!==(a=e).code&&"MODULE_NOT_FOUND"!==a.code)throw new xplogs_1.XpFatal({function:"connect()",message:a.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!"),r&&(0,xp_1.clean)({db:!0}),await xp_1.Database.findAll("simply-xps").then(e=>{e.filter(e=>e?.xp_rate!==xp_1.xp.xp_rate).map(e=>{xp_1.Database.updateOne({collection:"simply-xps",data:{user:e.user,guild:e.guild}},{collection:"simply-xps",data:{user:e.user,guild:e.guild,level:(0,xp_1.convertFrom)(e.xp,"xp"),xp:e.xp,xp_rate:xp_1.xp.xp_rate}});});}),xplogs_1.XpLog.debug("connect()","UPDATED ALL USERS WITH NEW XP RATE"),!0);}async function getPackageManager(){var e,t,a=(await Promise.resolve().then(()=>__importStar(require("fs")))).existsSync;for([e,t]of Object.entries({"yarn.lock":"yarn","pnpm-lock.yaml":"pnpm","pnpm-lock.json":"pnpm","package-lock.json":"npm"}))if(a(e))return xplogs_1.XpLog.debug("getPackageManager()","Using "+t.toUpperCase()),t;return xplogs_1.XpLog.debug("getPackageManager()","No lockfile found, defaulting to NPM"),"npm";}
|
|
34
42
|
/**
|
|
35
43
|
* Check database package versions
|
|
36
44
|
* @private
|
|
@@ -39,4 +47,4 @@ async function connect(e,t={type:void 0}){var o,{type:a,auto_create:n,auto_clean
|
|
|
39
47
|
* @param {number} max - Maximum Major Version Number (Optional)
|
|
40
48
|
* @returns {Promise<"too_low" | "ok" | "too_high">} - Version Status
|
|
41
49
|
* @throws {XpFatal} If the package version is not supported
|
|
42
|
-
*/async function checkPackageVersion(e,t,
|
|
50
|
+
*/async function checkPackageVersion(e,t,a){try{var o=await Promise.resolve(e+"/package.json").then(e=>__importStar(require(e))),n=parseInt(o.version.split(".")[0],10);return n<t?"too_low":a&&a<n?"too_high":"ok";}catch(o){return xplogs_1.XpLog.info("checkPackageVersion()",`Installing ${e} [V${a||t}] | Please wait...`),(0,child_process_1.execSync)(await getPackageManager()+` add ${e}@${a||t}.x.x`),xplogs_1.XpLog.warn("checkPackageVersion()",`Installed ${e}. Please restart!`),process.exit(0);}}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,o){void 0===o&&(o=a);var n=Object.getOwnPropertyDescriptor(t,a);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[a];}}),Object.defineProperty(e,o,n);}:function(e,t,a,o){e[o=void 0===o?a:o]=t[a];}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t});}:function(e,t){e.default=t;}),__importStar=this&&this.__importStar||(()=>{var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t,a=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(a[a.length]=t);return a;})(e);};return function(e){var t,a,o;if(e&&e.__esModule)return e;if(t={},null!=e)for(a=n(e),o=0;o<a.length;o++)"default"!==a[o]&&__createBinding(t,e,a[o]);return __setModuleDefault(t,e),t;};})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.connect=connect,exports.checkPackageVersion=checkPackageVersion;let xp_1=require("../xp"),xplogs_1=require("./functions/xplogs"),child_process_1=require("child_process");
|
package/lib/src/create.d.ts
CHANGED
package/lib/src/create.js
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
* @returns {Promise<UserResult>}
|
|
9
9
|
* @throws {XpFatal} If invalid parameters are provided
|
|
10
10
|
*/
|
|
11
|
-
async function create(e,t,r){if(!e)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!t)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});var
|
|
11
|
+
async function create(e,t,r){if(!e)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!t)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});var a;if(r)return await(a=(await Promise.resolve().then(()=>__importStar(require("./classes/Database")))).Database).findOne({collection:"simply-xps",data:{user:e,guild:t}})||a.createOne({collection:"simply-xps",data:{name:r,user:e,guild:t,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"create()",message:"Username was not provided"});}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[r];}}),Object.defineProperty(e,a,n);}:function(e,t,r,a){e[a=void 0===a?r:a]=t[r];}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t});}:function(e,t){e.default=t;}),__importStar=this&&this.__importStar||(()=>{var n=function(e){return(n=Object.getOwnPropertyNames||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r;})(e);};return function(e){var t,r,a;if(e&&e.__esModule)return e;if(t={},null!=e)for(r=n(e),a=0;a<r.length;a++)"default"!==r[a]&&__createBinding(t,e,r[a]);return __setModuleDefault(t,e),t;};})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.create=create;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");
|
package/lib/src/fetch.js
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
9
9
|
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
10
10
|
*/
|
|
11
|
-
async function fetch(t,e,r){var n;if(!t)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!e)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});(0,xp_1.clean)({db:!0});let
|
|
11
|
+
async function fetch(t,e,r){var n;if(!t)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!e)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});(0,xp_1.clean)({db:!0});let a=(n=await(await Promise.resolve().then(()=>__importStar(require("./classes/Database")))).db.find("simply-xps",e)).find(e=>e.user===t);if(!a){if(!xp_1.xp.auto_create||!r)throw new xplogs_1.XpFatal({function:"fetch()",message:"User data not found"});a=await(await Promise.resolve().then(()=>__importStar(require("./create")))).create(e,t,r),n.push(a);}return e=n.sort((e,t)=>t.xp-e.xp).findIndex(e=>e.user===t)+1,{flags:a?.flags,guild:a.guild,user:a.user,name:a?.name,level:a.level,position:e,xp:a.xp};}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var a=Object.getOwnPropertyDescriptor(t,r);a&&("get"in a?t.__esModule:!a.writable&&!a.configurable)||(a={enumerable:!0,get:function(){return t[r];}}),Object.defineProperty(e,n,a);}:function(e,t,r,n){e[n=void 0===n?r:n]=t[r];}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t});}:function(e,t){e.default=t;}),__importStar=this&&this.__importStar||(()=>{var a=function(e){return(a=Object.getOwnPropertyNames||function(e){var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[r.length]=t);return r;})(e);};return function(e){var t,r,n;if(e&&e.__esModule)return e;if(t={},null!=e)for(r=a(e),n=0;n<r.length;n++)"default"!==r[n]&&__createBinding(t,e,r[n]);return __setModuleDefault(t,e),t;};})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetch=fetch;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
* @returns {Promise<Object|Buffer|string>} - Returns the response from the request.
|
|
13
13
|
* @throws {PromiseRejectedResult} - If the request fails.
|
|
14
14
|
*/
|
|
15
|
-
function https(t,o={}){return new Promise((r,s)=>{let e=(0,https_1.request)({agent:new https_1.Agent({keepAlive:!0}),headers:o?.headers||{"Content-Type":"application/json"},hostname:new url_1.URL(t).hostname,method:o?.method||"GET",path:o?.endpoint||new url_1.URL(t).pathname},e=>{let t=[];e.on("error",s),e.on("data",e=>t.push(Buffer.from(e))),e.on("end",()=>{o?.statusCode&&e.statusCode!==o?.statusCode&&s({error:"Unexpected Status Code",status:e.statusCode});try{switch(o?.responseType||"json"){case"json":r(JSON.parse(Buffer.concat(t).toString()));break;case"stream":r(Buffer.concat(t));break;default:r(Buffer.concat(t).toString())}}catch(e){s(e)}})}).on("error",s);e.setTimeout(o?.timeout||5e3,()=>{e.destroy(),s({error:"Request Timed Out",status:408})}),o?.body&&e.write(JSON.stringify(o.body)),e.end()})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.https=https;let https_1=require("https"),url_1=require("url");
|
|
15
|
+
function https(t,o={}){return new Promise((r,s)=>{let e=(0,https_1.request)({agent:new https_1.Agent({keepAlive:!0}),headers:o?.headers||{"Content-Type":"application/json"},hostname:new url_1.URL(t).hostname,method:o?.method||"GET",path:o?.endpoint||new url_1.URL(t).pathname},e=>{let t=[];e.on("error",s),e.on("data",e=>t.push(Buffer.from(e))),e.on("end",()=>{o?.statusCode&&e.statusCode!==o?.statusCode&&s({error:"Unexpected Status Code",status:e.statusCode});try{switch(o?.responseType||"json"){case"json":r(JSON.parse(Buffer.concat(t).toString()));break;case"stream":r(Buffer.concat(t));break;default:r(Buffer.concat(t).toString());}}catch(e){s(e);}});}).on("error",s);e.setTimeout(o?.timeout||5e3,()=>{e.destroy(),s({error:"Request Timed Out",status:408});}),o?.body&&e.write(JSON.stringify(o.body)),e.end();});}Object.defineProperty(exports,"__esModule",{value:!0}),exports.https=https;let https_1=require("https"),url_1=require("url");
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @returns {void} - Nothing.
|
|
7
7
|
* @throws {XpFatal} If an error occurs.
|
|
8
8
|
*/
|
|
9
|
-
function clean(e={}){e?.db&&xp_1.xp?.database&&xp_1.db.findAll("simply-xps").then(e=>{e.forEach(async e=>{0===e.level&&0===e.xp&&await xp_1.db.deleteOne({collection:"simply-xps",data:{user:e.user,guild:e.guild}})}),xplogs_1.XpLog.debug("clean()","REMOVED ALL USERS WITHOUT XP")}),(0,canvas_1.clearAllCache)(),xplogs_1.XpLog.debug("clean()","CLEARED CANVAS CACHE")}
|
|
9
|
+
function clean(e={}){e?.db&&xp_1.xp?.database&&xp_1.db.findAll("simply-xps").then(e=>{e.forEach(async e=>{0===e.level&&0===e.xp&&await xp_1.db.deleteOne({collection:"simply-xps",data:{user:e.user,guild:e.guild}});}),xplogs_1.XpLog.debug("clean()","REMOVED ALL USERS WITHOUT XP");}),(0,canvas_1.clearAllCache)(),xplogs_1.XpLog.debug("clean()","CLEARED CANVAS CACHE");}
|
|
10
10
|
/**
|
|
11
11
|
* Convert XP to level and vice versa.
|
|
12
12
|
*
|
|
@@ -15,7 +15,7 @@ function clean(e={}){e?.db&&xp_1.xp?.database&&xp_1.db.findAll("simply-xps").the
|
|
|
15
15
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/Functions/convert
|
|
16
16
|
* @returns {number} - The converted value. (XP to level or level to XP)
|
|
17
17
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
18
|
-
*/function convertFrom(e,t="level"){if(isNaN(e))throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Value was not provided"});if("xp"!==t&&"level"!==t)throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"});if("level"===t)return Math.pow(Math.max(0,e)/xp_1.xp.xp_rate,2);if("xp"===t)return Math.floor(xp_1.xp.xp_rate*Math.sqrt(Math.max(0,e)));throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Invalid type provided"})}
|
|
18
|
+
*/function convertFrom(e,t="level"){if(isNaN(e))throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Value was not provided"});if("xp"!==t&&"level"!==t)throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"});if("level"===t)return Math.pow(Math.max(0,e)/xp_1.xp.xp_rate,2);if("xp"===t)return Math.floor(xp_1.xp.xp_rate*Math.sqrt(Math.max(0,e)));throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Invalid type provided"});}
|
|
19
19
|
/**
|
|
20
20
|
* Registers fonts from URLs or paths (For convenience).
|
|
21
21
|
* @param {string} pathOrURL - The path or URL to the font.
|
|
@@ -24,20 +24,20 @@ function clean(e={}){e?.db&&xp_1.xp?.database&&xp_1.db.findAll("simply-xps").the
|
|
|
24
24
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/Functions/registerFont
|
|
25
25
|
* @returns {Promise<void>} - Nothing.
|
|
26
26
|
* @throws {XpFatal} If an invalid path or URL is provided.
|
|
27
|
-
*/async function registerFont(e,t,a=1500){xp_1.xp.registeredFonts.includes(t)||(e.startsWith("https://")?await(0,xp_1.https)(e,{responseType:"stream",timeout:a}).then(e=>{canvas_1.GlobalFonts.register(e,t),xp_1.xp.registeredFonts.push(t)}).catch(e=>{throw new xplogs_1.XpFatal({function:"registerFont()",message:`Failed to register font from URL
|
|
28
|
-
`+JSON.stringify(e)})}):(canvas_1.GlobalFonts.registerFromPath(e,t),xp_1.xp.registeredFonts.push(t)))}
|
|
27
|
+
*/async function registerFont(e,t,a=1500){xp_1.xp.registeredFonts.includes(t)||(e.startsWith("https://")?await(0,xp_1.https)(e,{responseType:"stream",timeout:a}).then(e=>{canvas_1.GlobalFonts.register(e,t),xp_1.xp.registeredFonts.push(t);}).catch(e=>{throw new xplogs_1.XpFatal({function:"registerFont()",message:`Failed to register font from URL
|
|
28
|
+
`+JSON.stringify(e)});}):(canvas_1.GlobalFonts.registerFromPath(e,t),xp_1.xp.registeredFonts.push(t)));}
|
|
29
29
|
/**
|
|
30
30
|
* Register Simply-XP Plugins.
|
|
31
31
|
* @param {Plugin[]} plugins - The plugins to register.
|
|
32
32
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/Functions/registerPlugins
|
|
33
33
|
* @returns {void} - Nothing.
|
|
34
34
|
* @throws {XpFatal} If an invalid plugin is provided.
|
|
35
|
-
*/function registerPlugins(e){if(!Array.isArray(e))throw new xplogs_1.XpFatal({function:"registerPlugins()",message:"Plugins must be an array"});e.
|
|
36
|
-
`+e})}})}
|
|
35
|
+
*/function registerPlugins(e){if(!Array.isArray(e))throw new xplogs_1.XpFatal({function:"registerPlugins()",message:"Plugins must be an array"});Promise.all(e.map(async t=>{try{let n=!1,o=!0;if(t?.initialize&&t?.name||(o=!1,xplogs_1.XpLog.warn("registerPlugins()",t?.name?t.name.toUpperCase()+" PLUGIN NOT INITIALIZED: No initialize function provided.":"INVALID PLUGIN PROVIDED")),Array.isArray(t?.requiredVersions)&&!t.requiredVersions.includes(xp_1.xp.version)&&(t.requiredVersions.forEach(e=>{var[t,a,p]=xp_1.xp.version.split(".").map(e=>parseInt(e));return(e=e.match(/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-[\w\d.-]+)?$/))?o=parseInt(e[1]||"0")===t&&!(e[2]&&parseInt(e[2])!==a||e[3]&&parseInt(e[3])!==p):n=!0;}),n&&xplogs_1.XpLog.warn("registerPlugins()",t.name.toUpperCase()+" PLUGIN FAILED VERSION CHECKS, ANYWAYS..."),!o))return xplogs_1.XpLog.warn("registerPlugins()",t.name.toUpperCase()+" PLUGIN NOT INITIALIZED: Requires: v"+t.requiredVersions.join(", v"));await t.initialize(xp_1.xp),xplogs_1.XpLog.info("registerPlugins()",t.name.toUpperCase()+" PLUGIN INITIALIZED");}catch(e){throw new xplogs_1.XpFatal({function:"registerPlugins()",message:`Failed to register plugin: ${t.name}
|
|
36
|
+
`+e});}}));}
|
|
37
37
|
/**
|
|
38
38
|
* Updates the options of the XP client.
|
|
39
39
|
* @param {NewClientOptions} clientOptions - The new options to update.
|
|
40
40
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/Functions/updateOptions
|
|
41
41
|
* @returns {void} - Nothing.
|
|
42
42
|
* @throws {XpFatal} If an invalid option is provided.
|
|
43
|
-
*/function updateOptions(e){if(!e)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options were not provided"});if("object"!=typeof e)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options must be an object"});if(e?.auto_clean&&(xp_1.xp.auto_clean=!0),e?.auto_create&&(xp_1.xp.auto_create=!0),e?.debug&&(xp_1.xp.debug=!0),e?.notify&&(xp_1.xp.notify=e.notify),e?.xp_rate&&("number"==typeof e.xp_rate||["fast","normal","slow"].includes(e.xp_rate))&&(xp_1.xp.xp_rate="slow"===e.xp_rate?.05:"normal"===e.xp_rate?.1:"fast"===e.xp_rate?.5:e.xp_rate),e.dbOptions&&"object"==typeof e.dbOptions&&e.dbOptions.type&&e.dbOptions.database){var{type:t,database:a}=e.dbOptions;if(!(t&&"mongodb"===t||"sqlite"===t))throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid database type provided"});if(xp_1.xp.dbType=t,a){xp_1.xp.database=a;let t="mongodb"===xp_1.xp.dbType?{name:"MONGODB",type:"mongodb",min:3,max:7}:{name:"BETTER-SQLITE3",type:"better-sqlite3",min:7,max:12};(0,connect_1.checkPackageVersion)(t.type,t.min,t.max).then(e=>{switch(e){case"too_low":throw new xplogs_1.XpFatal({function:"updateOptions()",message:`${t.name} V${t.min} OR NEWER IS REQUIRED`});case"too_high":xplogs_1.XpLog.warn("updateOptions()",`${t.name} VERSION IS NEWER THAN TESTED (V${t.max}) -- CONTINUE WITH CAUTION`);break;case"ok":xplogs_1.XpLog.debug("updateOptions()",t.name+" is natively compatible with our package! 🎉")}switch(xp_1.xp.dbType){case"mongodb":xp_1.xp.database.db().command({ping:1}).catch(()=>{throw xp_1.xp.database=void 0,new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid MongoDB connection"})});break;case"sqlite":try{xp_1.xp.database.prepare("SELECT 1").get()}catch(e){throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid SQLite connection"})}}})}}e?.auto_clean&&clean({db:!0}),xp_1.db.findAll("simply-xps").then(e=>{e.filter(e=>e?.xp_rate!==xp_1.xp.xp_rate).map(async e=>{await xp_1.db.updateOne({collection:"simply-xps",data:{user:e.user,guild:e.guild}},{collection:"simply-xps",data:{user:e.user,guild:e.guild,level:convertFrom(e.xp,"xp"),xp:e.xp,xp_rate:xp_1.xp.xp_rate}})}),xplogs_1.XpLog.debug("updateOptions()","UPDATED ALL USERS WITH NEW XP RATE")})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.clean=clean,exports.convertFrom=convertFrom,exports.registerFont=registerFont,exports.registerPlugins=registerPlugins,exports.updateOptions=updateOptions;let connect_1=require("../connect"),canvas_1=require("@napi-rs/canvas"),xp_1=require("../../xp"),xplogs_1=require("./xplogs");
|
|
43
|
+
*/function updateOptions(e){if(!e)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options were not provided"});if("object"!=typeof e)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options must be an object"});if(e?.auto_clean&&(xp_1.xp.auto_clean=!0),e?.auto_create&&(xp_1.xp.auto_create=!0),e?.debug&&(xp_1.xp.debug=!0),e?.notify&&(xp_1.xp.notify=e.notify),e?.xp_rate&&("number"==typeof e.xp_rate||["fast","normal","slow"].includes(e.xp_rate))&&(xp_1.xp.xp_rate="slow"===e.xp_rate?.05:"normal"===e.xp_rate?.1:"fast"===e.xp_rate?.5:e.xp_rate),e.dbOptions&&"object"==typeof e.dbOptions&&e.dbOptions.type&&e.dbOptions.database){var{type:t,database:a}=e.dbOptions;if(!(t&&"mongodb"===t||"sqlite"===t))throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid database type provided"});if(xp_1.xp.dbType=t,a){xp_1.xp.database=a;let t="mongodb"===xp_1.xp.dbType?{name:"MONGODB",type:"mongodb",min:3,max:7}:{name:"BETTER-SQLITE3",type:"better-sqlite3",min:7,max:12};(0,connect_1.checkPackageVersion)(t.type,t.min,t.max).then(e=>{switch(e){case"too_low":throw new xplogs_1.XpFatal({function:"updateOptions()",message:`${t.name} V${t.min} OR NEWER IS REQUIRED`});case"too_high":xplogs_1.XpLog.warn("updateOptions()",`${t.name} VERSION IS NEWER THAN TESTED (V${t.max}) -- CONTINUE WITH CAUTION`);break;case"ok":xplogs_1.XpLog.debug("updateOptions()",t.name+" is natively compatible with our package! 🎉");}switch(xp_1.xp.dbType){case"mongodb":xp_1.xp.database.db().command({ping:1}).catch(()=>{throw xp_1.xp.database=void 0,new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid MongoDB connection"});});break;case"sqlite":try{xp_1.xp.database.prepare("SELECT 1").get();}catch(e){throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid SQLite connection"});}}});}}e?.auto_clean&&clean({db:!0}),xp_1.db.findAll("simply-xps").then(e=>{e.filter(e=>e?.xp_rate!==xp_1.xp.xp_rate).map(async e=>{await xp_1.db.updateOne({collection:"simply-xps",data:{user:e.user,guild:e.guild}},{collection:"simply-xps",data:{user:e.user,guild:e.guild,level:convertFrom(e.xp,"xp"),xp:e.xp,xp_rate:xp_1.xp.xp_rate}});}),xplogs_1.XpLog.debug("updateOptions()","UPDATED ALL USERS WITH NEW XP RATE");});}Object.defineProperty(exports,"__esModule",{value:!0}),exports.clean=clean,exports.convertFrom=convertFrom,exports.registerFont=registerFont,exports.registerPlugins=registerPlugins,exports.updateOptions=updateOptions;let connect_1=require("../connect"),canvas_1=require("@napi-rs/canvas"),xp_1=require("../../xp"),xplogs_1=require("./xplogs");
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpEvents=exports.XpLog=exports.XpFatal=void 0;let xp_1=require("../../xp");class XpFatal extends Error{constructor(e){super(e.function+": "+e.message)}}exports.XpFatal=XpFatal,Object.defineProperty(XpFatal.prototype,"name",{value:"SimplyXpFatal"});class XpLog{static log(e,t,o){var p=XpEvents.eventCallback?.[e],a=e.toUpperCase(),r=t.toUpperCase();p&&"function"==typeof p?p(t,o):console.log(`[35m[SIMPLY XP][0m ${{debug:"[36m",info:"[34m",error:"[31m",warn:"[33m"}[e]}(${a})[0m ${r}: `+o)}static debug(e,t){xp_1.xp.debug&&XpLog.log("debug",e,t)}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpEvents=exports.XpLog=exports.XpFatal=void 0;let xp_1=require("../../xp");class XpFatal extends Error{constructor(e){super(e.function+": "+e.message);}}exports.XpFatal=XpFatal,Object.defineProperty(XpFatal.prototype,"name",{value:"SimplyXpFatal"});class XpLog{static log(e,t,o){var p=XpEvents.eventCallback?.[e],a=e.toUpperCase(),r=t.toUpperCase();p&&"function"==typeof p?p(t,o):console.log(`[35m[SIMPLY XP][0m ${{debug:"[36m",info:"[34m",error:"[31m",warn:"[33m"}[e]}(${a})[0m ${r}: `+o);}static debug(e,t){xp_1.xp.debug&&XpLog.log("debug",e,t);}
|
|
2
2
|
/**
|
|
3
3
|
* Emits an info log
|
|
4
4
|
* @param {string} xpFunction - The command or context of the log message
|
|
5
5
|
* @param {string} message - The log message
|
|
6
6
|
* @returns {boolean} Returns true
|
|
7
7
|
* @private
|
|
8
|
-
*/static info(e,t){return xp_1.xp.notify&&XpLog.log("info",e,t),!0}
|
|
9
|
-
/**
|
|
8
|
+
*/static info(e,t){return xp_1.xp.notify&&XpLog.log("info",e,t),!0;}
|
|
9
|
+
/**
|
|
10
10
|
* Emits an error log
|
|
11
11
|
* @param {string} xpFunction - The command or context of the log message
|
|
12
12
|
* @param {string} message - The log message
|
|
13
13
|
* @returns {boolean} Returns false
|
|
14
14
|
* @private
|
|
15
|
-
*/static err(e,t){return XpLog.log("error",e,t),!1}static warn(e,t){XpLog.log("warn",e,t)}}exports.XpLog=XpLog;class XpEvents{static eventCallback;static on(e){XpEvents.eventCallback=e}}exports.XpEvents=XpEvents;
|
|
15
|
+
*/static err(e,t){return XpLog.log("error",e,t),!1;}static warn(e,t){XpLog.log("warn",e,t);}}exports.XpLog=XpLog;class XpEvents{static eventCallback;static on(e){XpEvents.eventCallback=e;}}exports.XpEvents=XpEvents;
|
package/lib/src/leaderboard.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* @returns {Promise<User[]>} Array of all users in the leaderboard
|
|
8
8
|
* @throws {XpFatal} If guild ID is not provided or limit is less than 1
|
|
9
9
|
*/
|
|
10
|
-
async function leaderboard(e,
|
|
10
|
+
async function leaderboard(e,a){var r,s,t;if(a&&!(1<=a))throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Limit must be a number greater than 0"});let p;if(e)p=(await xp_1.Database.find("simply-xps",e)).sort((e,a)=>a.xp-e.xp);else{p=await xp_1.Database.findAll("simply-xps"),s=new Map;for(r of p)(!(t=s.get(r.user))||r.xp>t.xp)&&s.set(r.user,r);p=Array.from(s.values()).sort((e,a)=>a.xp-e.xp);}return p.slice(0,a).map((e,a)=>({...e,position:a+1}));}Object.defineProperty(exports,"__esModule",{value:!0}),exports.leaderboard=leaderboard;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");
|
package/lib/src/remove.d.ts
CHANGED
package/lib/src/remove.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
10
10
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
11
11
|
*/
|
|
12
|
-
async function removeLevel(e,
|
|
12
|
+
async function removeLevel(e,a,t,l){if(!e)throw new xplogs_1.XpFatal({function:"removeLevel()",message:"User ID was not provided"});if(!a)throw new xplogs_1.XpFatal({function:"removeLevel()",message:"Guild ID was not provided"});if(isNaN(t))throw new xplogs_1.XpFatal({function:"removeLevel()",message:"Level was not provided"});var o=await xp_1.Database.findOne({collection:"simply-xps",data:{user:e,guild:a}});if(o)return xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:a}},{collection:"simply-xps",data:{name:l||o?.name||e,user:e,guild:a,level:o.level-t,xp:(0,xp_1.convertFrom)(o.level-t),xp_rate:xp_1.xp.xp_rate}});if(xp_1.xp.auto_create&&l)return xp_1.Database.createOne({collection:"simply-xps",data:{guild:a,user:e,name:l,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"removeLevel()",message:"User does not exist"});}
|
|
13
13
|
/**
|
|
14
14
|
* Add XP to a user.
|
|
15
15
|
* @async
|
|
@@ -20,4 +20,4 @@ async function removeLevel(e,l,t,o){if(!e)throw new xplogs_1.XpFatal({function:"
|
|
|
20
20
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addxp
|
|
21
21
|
* @returns {Promise<XPResult>} - Object of user data on success.
|
|
22
22
|
* @throws {XpFatal} - If parameters are not provided correctly.
|
|
23
|
-
*/async function removeXP(e,
|
|
23
|
+
*/async function removeXP(e,a,t,l){var o;if(!("number"==typeof t||"object"==typeof xp_1.xp&&t.min&&t.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 t&&(t=Math.floor(Math.random()*(t.max-t.min)+t.min)),!e)throw new xplogs_1.XpFatal({function:"removeXP()",message:"User ID was not provided"});if(!a)throw new xplogs_1.XpFatal({function:"removeXP()",message:"Guild ID was not provided"});let p;if(o=await xp_1.Database.findOne({collection:"simply-xps",data:{user:e,guild:a}}))p=await xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:a}},{collection:"simply-xps",data:{user:e,guild:a,name:l||o?.name||e,level:(0,xp_1.convertFrom)(o.xp-t,"xp"),xp:o.xp-t,xp_rate:xp_1.xp.xp_rate}}).catch(e=>{throw new xplogs_1.XpFatal({function:"removeXP()",message:e.stack});});else{if(!xp_1.xp.auto_create||!l)throw new xplogs_1.XpFatal({function:"removeXP()",message:"User does not exist"});p=await xp_1.Database.createOne({collection:"simply-xps",data:{guild:a,user:e,name:l,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}}).catch(e=>{throw new xplogs_1.XpFatal({function:"removeXP()",message:e.stack});});}return t=xplogs_1.XpEvents.eventCallback,(l=o?.level&&p?.level?p.level!==o.level?p.level-o.level:0:0<p?.level?p.level:0)<0&&t?.levelDown&&"function"==typeof t.levelDown&&t.levelDown(p,await xp_1.LevelRoles.getUserRoles(e,a,{includeNext:!0})),0<l&&t?.levelUp&&"function"==typeof t.levelUp&&t.levelUp(p,await xp_1.LevelRoles.getUserRoles(e,a)),{...p,levelDifference:l};}Object.defineProperty(exports,"__esModule",{value:!0}),exports.removeLevel=removeLevel,exports.removeXP=removeXP;let xp_1=require("../xp"),xplogs_1=require("./functions/xplogs");
|
package/lib/src/reset.js
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* @returns {Promise<boolean>}
|
|
10
10
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
11
|
*/
|
|
12
|
-
async function reset(e,t,a=!1,s){var o;if(e&&t)return o={guild:t,user:e,xp_rate:xp_1.xp.xp_rate},await xp_1.
|
|
12
|
+
async function reset(e,t,a=!1,s){var o;if(e&&t)return o={guild:t,user:e,xp_rate:xp_1.xp.xp_rate},await xp_1.Database.findOne({collection:"simply-xps",data:o})?(a?await xp_1.Database.deleteOne({collection:"simply-xps",data:o}).catch(e=>{throw new xplogs_1.XpFatal({function:"reset()",message:e});}):await xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:t}},{collection:"simply-xps",data:{...o,level:0,xp:0}}).catch(e=>{throw new xplogs_1.XpFatal({function:"reset()",message:e});}),!0):xp_1.xp.auto_create&&!a&&s?(await xp_1.Database.createOne({collection:"simply-xps",data:o}).catch(e=>{throw new xplogs_1.XpFatal({function:"reset()",message:e.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=reset;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");
|
package/lib/src/set.d.ts
CHANGED
package/lib/src/set.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
10
10
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
11
11
|
*/
|
|
12
|
-
async function setLevel(e,t,l,
|
|
12
|
+
async function setLevel(e,t,l,a){if(!e)throw new xplogs_1.XpFatal({function:"setLevel()",message:"User ID was not provided"});if(!t)throw new xplogs_1.XpFatal({function:"setLevel()",message:"Guild ID was not provided"});if(isNaN(l))throw new xplogs_1.XpFatal({function:"setLevel()",message:"Level was not provided"});if(await xp_1.Database.findOne({collection:"simply-xps",data:{user:e,guild:t}}))return xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:t}},{collection:"simply-xps",data:{user:e,guild:t,level:l,xp:(0,xp_1.convertFrom)(l),xp_rate:xp_1.xp.xp_rate}});if(xp_1.xp.auto_create&&a)return xp_1.Database.createOne({collection:"simply-xps",data:{guild:t,user:e,name:a,level:l,xp:(0,xp_1.convertFrom)(l),xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"});}
|
|
13
13
|
/**
|
|
14
14
|
* Set user XP
|
|
15
15
|
* @async
|
|
@@ -20,4 +20,4 @@ async function setLevel(e,t,l,p){if(!e)throw new xplogs_1.XpFatal({function:"set
|
|
|
20
20
|
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setxp
|
|
21
21
|
* @returns {Promise<XPResult>} - Object of user data on success
|
|
22
22
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
23
|
-
*/async function setXP(e,t,l,
|
|
23
|
+
*/async function setXP(e,t,l,a){var s;if(!e)throw new xplogs_1.XpFatal({function:"setXP()",message:"User ID was not provided"});if(!t)throw new xplogs_1.XpFatal({function:"setXP()",message:"Guild ID was not provided"});if(isNaN(l))throw new xplogs_1.XpFatal({function:"setXP()",message:"XP was not provided"});let p;if(s=await xp_1.Database.findOne({collection:"simply-xps",data:{user:e,guild:t}}))p=await xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:t}},{collection:"simply-xps",data:{name:a||s?.name||e,user:e,guild:t,level:(0,xp_1.convertFrom)(l),xp:l,xp_rate:xp_1.xp.xp_rate}});else{if(!xp_1.xp.auto_create||!a)throw new xplogs_1.XpFatal({function:"setXP()",message:"User does not exist"});p=await xp_1.Database.createOne({collection:"simply-xps",data:{guild:t,user:e,name:a,level:(0,xp_1.convertFrom)(l),xp:l,xp_rate:xp_1.xp.xp_rate}});}return a=xplogs_1.XpEvents.eventCallback,(l=s?.level&&p?.level?p.level!==s.level?p.level-s.level:0:0<p?.level?p.level:0)<0&&a?.levelDown&&"function"==typeof a.levelDown&&a.levelDown(p,await xp_1.LevelRoles.getUserRoles(e,t,{includeNext:!0})),0<l&&a?.levelUp&&"function"==typeof a.levelUp&&a.levelUp(p,await xp_1.LevelRoles.getUserRoles(e,t)),{...p,levelDifference:l};}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setLevel=setLevel,exports.setXP=setXP;let xp_1=require("../xp"),xplogs_1=require("./functions/xplogs");
|
package/lib/src/setFlags.d.ts
CHANGED
package/lib/src/setFlags.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function setFlags(e,s,
|
|
1
|
+
async function setFlags(e,a,s,t){if(!e)throw new xplogs_1.XpFatal({function:"flagUser()",message:"User ID was not provided"});if(!a)throw new xplogs_1.XpFatal({function:"flagUser()",message:"Guild ID was not provided"});if(s&&!Array.isArray(s))throw new xplogs_1.XpFatal({function:"flagUser()",message:"Flags must be an array of numbers or strings"});var l=await xp_1.Database.findOne({collection:"simply-xps",data:{user:e,guild:a}});if(l)return xp_1.Database.updateOne({collection:"simply-xps",data:{user:e,guild:a}},{collection:"simply-xps",data:{flags:s,guild:a,user:e,level:l.level,xp:l.xp,xp_rate:xp_1.xp.xp_rate}});if(console.log("FLAGS => NO USER FOUND LMAO"),xp_1.xp.auto_create&&t)return xp_1.Database.createOne({collection:"simply-xps",data:{flags:s,guild:a,user:e,name:t,level:0,xp:0,xp_rate:xp_1.xp.xp_rate}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"});}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setFlags=setFlags;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");
|