simply-xp 2.0.0-beta.1 → 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.
@@ -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;
@@ -23,7 +23,7 @@ export declare function connect(uri: string, options?: ConnectionOptions): Promi
23
23
  * @param {string} type - NPM Package Name (lowercase)
24
24
  * @param {number} min - Minimum Major Version Number
25
25
  * @param {number} max - Maximum Major Version Number (Optional)
26
- * @returns {Promise<boolean>}
26
+ * @returns {Promise<"too_low" | "ok" | "too_high">} - Version Status
27
27
  * @throws {XpFatal} If the package version is not supported
28
28
  */
29
- export declare function checkPackageVersion(type: string, min: number, max?: number): Promise<boolean>;
29
+ export declare function checkPackageVersion(type: string, min: number, max?: number): Promise<"too_low" | "ok" | "too_high">;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Connect to a database (MongoDB, SQLite)
4
3
  *
@@ -8,35 +7,44 @@
8
7
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/connect
9
8
  * @returns {Promise<boolean>}
10
9
  * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
11
- */async function connect(e,t={type:void 0}){var a,{type:o,auto_create:n,auto_clean:r,notify:s,debug:c,xp_rate:i}=t;if(!i||"slow"!==i&&"normal"!==i&&"fast"!==i&&isNaN(i)||(xp_1.xp.xp_rate="slow"===i?.05:"normal"===i?.1:"fast"===i?.5:i),!e)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===s&&(xp_1.xp.notify=!1),n&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_clean=!0),c&&(xp_1.xp.debug=!0),o||(t.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),o){case"mongodb":if(a=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb",3,6))return xplogs_1.XpLog.err("connect()","MongoDB Version 3 to 6 is required");a=await a.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{var[p,l]=await Promise.all([Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),checkPackageVersion("better-sqlite3",7,9)]);if(!l)return xplogs_1.XpLog.err("connect()","better-sqlite3 Version 7 to 9 is required");xp_1.xp.database=new p.default(e),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xps"
12
- (
13
- user TEXT NOT NULL,
14
- guild TEXT NOT NULL,
15
- name TEXT NOT NULL DEFAULT user,
16
- level INTEGER NOT NULL DEFAULT 0,
17
- flags TEXT DEFAULT NULL,
18
- xp INTEGER NOT NULL DEFAULT 0,
19
- voice_xp INTEGER DEFAULT 0,
20
- voice_time INTEGER DEFAULT 0,
21
- lastUpdated DATE NOT NULL,
22
- xp_rate INTEGER DEFAULT 0.1
23
- )`),xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xp-levelroles"
24
- (
25
- gid TEXT NOT NULL,
26
- lvlrole TEXT NOT NULL,
27
- lastUpdated TEXT NOT NULL
28
- )`)}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.db.findAll("simply-xps").then(e=>{e.filter(e=>e?.xp_rate!==xp_1.xp.xp_rate).map(e=>{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:(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)}
10
+ */
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;
29
12
  /**
30
13
  * Returns the package manager used
31
14
  * @private
32
15
  * @returns {Promise<"yarn" | "npm" | "pnpm">}
33
- */async function getPackageManager(){const t=(await Promise.resolve().then(()=>__importStar(require("fs")))).existsSync;var e=["yarn.lock","pnpm-lock.yaml","pnpm-lock.json","package-lock.json"].filter(e=>t(e));if(1===e.length){if("yarn.lock"===e[0])return xplogs_1.XpLog.debug("getPackageManager()","Using YARN"),"yarn";if("pnpm-lock.yaml"===e[0]||"pnpm-lock.json"===e[0])return xplogs_1.XpLog.debug("getPackageManager()","Using PNPM"),"pnpm"}return xplogs_1.XpLog.debug("getPackageManager()","Using NPM"),"npm"}
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
37
45
  * @param {string} type - NPM Package Name (lowercase)
38
46
  * @param {number} min - Minimum Major Version Number
39
47
  * @param {number} max - Maximum Major Version Number (Optional)
40
- * @returns {Promise<boolean>}
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,a){try{var o=await Promise.resolve(e+"/package.json").then(e=>__importStar(require(e)));return parseInt(o.version.substring(0,1))>=t&&(!a||parseInt(o.version.substring(0,1))<=a)}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(1)}}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||function(e){var t,a;if(e&&e.__esModule)return e;if(t={},null!=e)for(a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkPackageVersion=exports.connect=void 0;const xplogs_1=require("./functions/xplogs"),child_process_1=require("child_process"),xp_1=require("../xp");exports.connect=connect,exports.checkPackageVersion=checkPackageVersion;
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");
@@ -1,4 +1,4 @@
1
- import { UserResult } from "./functions/database";
1
+ import { UserResult } from "./classes/Database";
2
2
  /**
3
3
  * Create a new user in the database
4
4
  * @async
package/lib/src/create.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Create a new user in the database
4
3
  * @async
@@ -8,4 +7,5 @@
8
7
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/create
9
8
  * @returns {Promise<UserResult>}
10
9
  * @throws {XpFatal} If invalid parameters are provided
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("./functions/database")))).db).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 i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,i)}: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||function(e){var t,r;if(e&&e.__esModule)return e;if(t={},null!=e)for(r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.create=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.create=create;
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 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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Fetch user data
4
3
  * @async
@@ -8,4 +7,5 @@
8
7
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/fetch
9
8
  * @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
10
9
  * @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
11
- */async function fetch(t,e,r){var i;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 n=(i=await(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db.find("simply-xps",e)).find(e=>e.user===t);if(!n){if(!xp_1.xp.auto_create||!r)throw new xplogs_1.XpFatal({function:"fetch()",message:"User data not found"});n=await(await Promise.resolve().then(()=>__importStar(require("./create")))).create(e,t,r),i.push(n)}return e=i.sort((e,t)=>t.xp-e.xp).findIndex(e=>e.user===t)+1,{flags:n?.flags,guild:n.guild,user:n.user,name:n?.name,level:n.level,position:e,xp:n.xp}}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=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,i,n)}:function(e,t,r,i){e[i=void 0===i?r:i]=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||function(e){var t,r;if(e&&e.__esModule)return e;if(t={},null!=e)for(r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetch=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.fetch=fetch;
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 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");
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  interface HttpsOptions {
3
2
  body?: object;
4
3
  endpoint?: string;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Send HTTPS Request.
4
3
  * @param {string} url
@@ -12,4 +11,5 @@
12
11
  * @param {number} [options.timeout] - Request Timeout in Milliseconds
13
12
  * @returns {Promise<Object|Buffer|string>} - Returns the response from the request.
14
13
  * @throws {PromiseRejectedResult} - If the request fails.
15
- */function https(e,o={}){return new Promise((s,r)=>{const t=(0,https_1.request)({agent:new https_1.Agent({keepAlive:!0}),headers:o?.headers||{"Content-Type":"application/json"},hostname:new url_1.URL(e).hostname,method:o?.method||"GET",path:o?.endpoint||new url_1.URL(e).pathname},t=>{const e=[];t.on("error",r),t.on("data",t=>e.push(Buffer.from(t))),t.on("end",()=>{o?.statusCode&&t.statusCode!==o?.statusCode&&r({error:"Unexpected Status Code",status:t.statusCode});try{switch(o?.responseType||"json"){case"json":s(JSON.parse(Buffer.concat(e).toString()));break;case"stream":s(Buffer.concat(e));break;default:s(Buffer.concat(e).toString())}}catch(t){r(t)}})}).on("error",r);t.setTimeout(o?.timeout||5e3,()=>{t.destroy(),r({error:"Request Timed Out",status:408})}),o?.body&&t.write(JSON.stringify(o.body)),t.end()})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.https=void 0;const https_1=require("https"),url_1=require("url");exports.https=https;
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");
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Helps to clean the database and cache, more in the future, maybe.
4
3
  * @param {CleanOptions} [options={}] - The options.
@@ -6,7 +5,8 @@
6
5
  * @link `Documentation:` https://simplyxp.js.org/docs/next/clean
7
6
  * @returns {void} - Nothing.
8
7
  * @throws {XpFatal} If an error occurs.
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")}
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");}
10
10
  /**
11
11
  * Convert XP to level and vice versa.
12
12
  *
@@ -15,7 +15,7 @@
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 @@
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.forEach(async t=>{let a=!1,p=!0;if(t?.initialize&&t?.name||(p=!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=>{parseInt(e)?p=!(!parseInt(e)||1!==e.length||xp_1.xp.version.split(".")[0]!==e):e.match(/\d\.\d\.\d/)||p||(a=!0,p=!0)}),a&&xplogs_1.XpLog.warn("registerPlugins()",t.name.toUpperCase()+" PLUGIN FAILED VERSION CHECKS, ANYWAYS..."),p||a||xplogs_1.XpLog.warn("registerPlugins()",t.name.toUpperCase()+" PLUGIN NOT INITIALIZED: Requires: v"+t.requiredVersions.join(", v"))),p)try{await t.initialize(xp_1.xp).then(()=>{xplogs_1.XpLog.info("registerPlugins()",t.name.toUpperCase()+" PLUGIN INITIALIZED")})}catch(e){throw new xplogs_1.XpFatal({function:"registerPlugins()",message:`Failed to initialize plugin: ${t.name}
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;const p="mongodb"===xp_1.xp.dbType?{name:"MongoDB",type:"mongodb",min:3,max:6}:{name:"Better-SQLite3",type:"better-sqlite3",min:7,max:9};(0,connect_1.checkPackageVersion)(p.type,p.min,p.max).then(e=>{if(!e)throw new xplogs_1.XpFatal({function:"updateOptions()",message:`${p.name} V${p.min} up to V${p.max} is required.`});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.updateOptions=exports.registerPlugins=exports.registerFont=exports.convertFrom=exports.clean=void 0;const connect_1=require("../connect"),canvas_1=require("@napi-rs/canvas"),xp_1=require("../../xp"),xplogs_1=require("./xplogs");exports.clean=clean,exports.convertFrom=convertFrom,exports.registerFont=registerFont,exports.registerPlugins=registerPlugins,exports.updateOptions=updateOptions;
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,4 +1,4 @@
1
- import { UserResult } from "./database";
1
+ import { UserResult } from "../classes/Database";
2
2
  type errOptions = {
3
3
  function: string;
4
4
  message: string | Error;
@@ -1,15 +1,15 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpEvents=exports.XpLog=exports.XpFatal=void 0;const 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],r=e.toUpperCase(),a=t.toUpperCase();p&&"function"==typeof p?p(t,o):console.log(`[SIMPLY XP] ${{debug:"",info:"",error:"",warn:""}[e]}(${r}) ${a}: `+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(`[SIMPLY XP] ${{debug:"",info:"",error:"",warn:""}[e]}(${a}) ${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;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Get array of all users in the leaderboard
4
3
  * @async
@@ -7,4 +6,5 @@
7
6
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/leaderboard
8
7
  * @returns {Promise<User[]>} Array of all users in the leaderboard
9
8
  * @throws {XpFatal} If guild ID is not provided or limit is less than 1
10
- */async function leaderboard(e,r){if(r&&!(1<=r))throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Limit must be a number greater than 0"});const a=new Set;return e=e?(await xp_1.db.find("simply-xps",e)).sort((e,r)=>r.xp-e.xp):(await xp_1.db.findAll("simply-xps")).sort((e,r)=>r.xp-e.xp).filter(e=>!a.has(e.user)&&(a.add(e.user),!0)),await Promise.all(e.map(async(e,r)=>(e.position=r+1,e))),e.slice(0,r)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.leaderboard=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.leaderboard=leaderboard;
9
+ */
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");
@@ -1,4 +1,4 @@
1
- import { UserResult } from "./functions/database";
1
+ import { UserResult } from "./classes/Database";
2
2
  import { XPResult } from "./add";
3
3
  /**
4
4
  * Add XP to a user
package/lib/src/remove.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Add XP to a user
4
3
  * @async
@@ -9,7 +8,8 @@
9
8
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/addlevel
10
9
  * @returns {Promise<UserResult>} - Object of user data on success
11
10
  * @throws {XpFatal} - If parameters are not provided correctly
12
- */async function removeLevel(e,o,t,l){if(!e)throw new xplogs_1.XpFatal({function:"removeLevel()",message:"User ID was not provided"});if(!o)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 a=await xp_1.db.findOne({collection:"simply-xps",data:{user:e,guild:o}});if(a)return xp_1.db.updateOne({collection:"simply-xps",data:{user:e,guild:o}},{collection:"simply-xps",data:{name:l||a?.name||e,user:e,guild:o,level:a.level-t,xp:(0,xp_1.convertFrom)(a.level-t),xp_rate:xp_1.xp.xp_rate}});if(xp_1.xp.auto_create&&l)return xp_1.db.createOne({collection:"simply-xps",data:{guild:o,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"})}
11
+ */
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 @@
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,o,t,l){var a;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(!o)throw new xplogs_1.XpFatal({function:"removeXP()",message:"Guild ID was not provided"});let p;if(a=await xp_1.db.findOne({collection:"simply-xps",data:{user:e,guild:o}}))p=await xp_1.db.updateOne({collection:"simply-xps",data:{user:e,guild:o}},{collection:"simply-xps",data:{user:e,guild:o,name:l||a?.name||e,level:(0,xp_1.convertFrom)(a.xp-t,"xp"),xp:a.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.db.createOne({collection:"simply-xps",data:{guild:o,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=a?.level&&p?.level?p.level!==a.level?p.level-a.level:0:0<p?.level?p.level:0)<0&&t?.levelDown&&"function"==typeof t.levelDown&&t.levelDown(p,await xp_1.roleSetup.getRoles(e,o,{includeNextRoles:!0})),0<l&&t?.levelUp&&"function"==typeof t.levelUp&&t.levelUp(p,await xp_1.roleSetup.getRoles(e,o)),{...p,levelDifference:l}}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;
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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Reset user levels to 0 in a guild
4
3
  * @async
@@ -9,4 +8,5 @@
9
8
  * @link `Documentation:` https://simplyxp.js.org/docs/next/functions/reset
10
9
  * @returns {Promise<boolean>}
11
10
  * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
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.db.findOne({collection:"simply-xps",data:o})?(a?await xp_1.db.deleteOne({collection:"simply-xps",data:o}).catch(e=>{throw new xplogs_1.XpFatal({function:"reset()",message:e})}):await xp_1.db.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.db.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=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.reset=reset;
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.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
@@ -1,4 +1,4 @@
1
- import { UserResult } from "./functions/database";
1
+ import { UserResult } from "./classes/Database";
2
2
  import { XPResult } from "./add";
3
3
  /**
4
4
  * Set user level