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/lib/xp.d.ts CHANGED
@@ -5,14 +5,14 @@ import { MongoClient } from "mongodb";
5
5
  * @property {string} name - The name of the plugin.
6
6
  * @property {Record<string, (arg: number | object | string) => Promise<Array<unknown> | boolean | number | object | string | void>>} functions - The functions to add to the XP client.
7
7
  * @property {Function} initialize - The function to run when the plugin is initialized.
8
- * @property {Array<string>} requiredVersions - Compatible SimplyXP Versions.
8
+ * @property {Array<`${number}` | `${number}.${number}` | `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}.${number}`>} requiredVersions - Compatible SimplyXP Versions.
9
9
  * @returns {Promise<boolean | Error>} - Returns true if the plugin was initialized successfully, otherwise returns an error.
10
10
  */
11
11
  export interface Plugin {
12
12
  name: string;
13
13
  functions?: Record<string, (arg: number | object | string) => Promise<Array<unknown> | boolean | number | object | string | void>>;
14
14
  initialize: (client: XPClient) => Promise<void>;
15
- requiredVersions?: Array<string>;
15
+ requiredVersions?: Array<`${number}` | `${number}.${number}` | `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}.${number}`>;
16
16
  }
17
17
  /**
18
18
  * User object
@@ -41,11 +41,11 @@ export interface XPClient {
41
41
  debug: boolean;
42
42
  notify: boolean;
43
43
  registeredFonts: string[];
44
- version: string;
44
+ version: `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}.${number}`;
45
45
  xp_rate: number;
46
46
  }
47
47
  export { addLevel, addXP } from "./src/add";
48
- export { db } from "./src/functions/database";
48
+ export { Database, db } from "./src/classes/Database";
49
49
  export { charts } from "./src/charts";
50
50
  export { compareCard, leaderboardCard, rankCard } from "./src/cards";
51
51
  export { connect } from "./src/connect";
@@ -54,10 +54,10 @@ export { create } from "./src/create";
54
54
  export { fetch } from "./src/fetch";
55
55
  export { https } from "./src/functions/https";
56
56
  export { leaderboard } from "./src/leaderboard";
57
- export { migrate } from "./src/migrate";
57
+ export { LevelRoles } from "./src/classes/LevelRoles";
58
+ export { Migrate, migrate } from "./src/classes/Migrate";
58
59
  export { removeLevel, removeXP } from "./src/remove";
59
60
  export { reset } from "./src/reset";
60
- export { roleSetup } from "./src/roleSetup";
61
61
  export { setFlags } from "./src/setFlags";
62
62
  export { setLevel, setXP } from "./src/set";
63
63
  export { XpEvents } from "./src/functions/xplogs";
package/lib/xp.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.xp = exports.XpEvents = exports.setXP = exports.setLevel = exports.setFlags = exports.roleSetup = exports.reset = exports.removeXP = exports.removeLevel = exports.migrate = exports.leaderboard = exports.https = exports.create = exports.updateOptions = exports.registerPlugins = exports.registerFont = exports.convertFrom = exports.clean = exports.connect = exports.rankCard = exports.leaderboardCard = exports.compareCard = exports.charts = exports.db = exports.addXP = exports.addLevel = void 0;
3
+ exports.xp = exports.XpEvents = exports.setXP = exports.setLevel = exports.setFlags = exports.reset = exports.removeXP = exports.removeLevel = exports.migrate = exports.Migrate = exports.LevelRoles = exports.leaderboard = exports.https = exports.create = exports.updateOptions = exports.registerPlugins = exports.registerFont = exports.convertFrom = exports.clean = exports.connect = exports.rankCard = exports.leaderboardCard = exports.compareCard = exports.charts = exports.db = exports.Database = exports.addXP = exports.addLevel = void 0;
4
4
  // FUNCTION/CLASS EXPORTS
5
5
  var add_1 = require("./src/add");
6
6
  Object.defineProperty(exports, "addLevel", { enumerable: true, get: function () { return add_1.addLevel; } });
7
7
  Object.defineProperty(exports, "addXP", { enumerable: true, get: function () { return add_1.addXP; } });
8
- var database_1 = require("./src/functions/database");
9
- Object.defineProperty(exports, "db", { enumerable: true, get: function () { return database_1.db; } });
8
+ var Database_1 = require("./src/classes/Database");
9
+ Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return Database_1.Database; } });
10
+ Object.defineProperty(exports, "db", { enumerable: true, get: function () { return Database_1.db; } });
10
11
  var charts_1 = require("./src/charts");
11
12
  Object.defineProperty(exports, "charts", { enumerable: true, get: function () { return charts_1.charts; } });
12
13
  var cards_1 = require("./src/cards");
@@ -29,15 +30,16 @@ var https_1 = require("./src/functions/https");
29
30
  Object.defineProperty(exports, "https", { enumerable: true, get: function () { return https_1.https; } });
30
31
  var leaderboard_1 = require("./src/leaderboard");
31
32
  Object.defineProperty(exports, "leaderboard", { enumerable: true, get: function () { return leaderboard_1.leaderboard; } });
32
- var migrate_1 = require("./src/migrate");
33
- Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migrate_1.migrate; } });
33
+ var LevelRoles_1 = require("./src/classes/LevelRoles");
34
+ Object.defineProperty(exports, "LevelRoles", { enumerable: true, get: function () { return LevelRoles_1.LevelRoles; } });
35
+ var Migrate_1 = require("./src/classes/Migrate");
36
+ Object.defineProperty(exports, "Migrate", { enumerable: true, get: function () { return Migrate_1.Migrate; } });
37
+ Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return Migrate_1.migrate; } });
34
38
  var remove_1 = require("./src/remove");
35
39
  Object.defineProperty(exports, "removeLevel", { enumerable: true, get: function () { return remove_1.removeLevel; } });
36
40
  Object.defineProperty(exports, "removeXP", { enumerable: true, get: function () { return remove_1.removeXP; } });
37
41
  var reset_1 = require("./src/reset");
38
42
  Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
39
- var roleSetup_1 = require("./src/roleSetup");
40
- Object.defineProperty(exports, "roleSetup", { enumerable: true, get: function () { return roleSetup_1.roleSetup; } });
41
43
  var setFlags_1 = require("./src/setFlags");
42
44
  Object.defineProperty(exports, "setFlags", { enumerable: true, get: function () { return setFlags_1.setFlags; } });
43
45
  var set_1 = require("./src/set");
@@ -53,6 +55,6 @@ exports.xp = {
53
55
  debug: false,
54
56
  notify: true,
55
57
  registeredFonts: [],
56
- version: "2.0.0-beta.1",
58
+ version: "2.0.0-beta.3",
57
59
  xp_rate: 0.1
58
60
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simply-xp",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "The easiest way to implement xp system",
5
5
  "main": "lib/xp.js",
6
6
  "scripts": {
@@ -42,16 +42,16 @@
42
42
  "url": "git+https://github.com/Abadima/simply-xp.git"
43
43
  },
44
44
  "dependencies": {
45
- "@napi-rs/canvas": "0.1.83"
45
+ "@napi-rs/canvas": "0.1.88"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@eslint/eslintrc": "^3.3.3",
49
49
  "@types/better-sqlite3": "^7.6.13",
50
- "@types/node": "^24.10.1",
51
- "@typescript-eslint/eslint-plugin": "^8.48.1",
52
- "@typescript-eslint/parser": "^8.48.1",
53
- "better-sqlite3": "12.5.0",
54
- "eslint": "^9.39.1",
50
+ "@types/node": "^25.0.10",
51
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
52
+ "@typescript-eslint/parser": "^8.53.1",
53
+ "better-sqlite3": "^12.6.2",
54
+ "eslint": "^9.39.2",
55
55
  "mongodb": "^7.0.0",
56
56
  "typescript": "^5.9.3",
57
57
  "uglify-js": "^3.19.3"
@@ -1,79 +0,0 @@
1
- /**
2
- * Handle database errors
3
- * @param {Error} error
4
- * @param {string} functionName
5
- * @returns {void}
6
- * @private
7
- */
8
- function handleError(a,e){throw new xplogs_1.XpFatal({function:"db."+e,message:a})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.db=void 0;let xplogs_1=require("./xplogs"),xp_1=require("../../xp");class db{
9
- /**
10
- * Gets a collection from the database.
11
- * @param {collection} collection - The collection to get.
12
- * @link https://simplyxp.js.org/docs/next/handlers/database#getCollection Documentation
13
- * @returns {Collection} The collection.
14
- * @throws {XpFatal} Throws an error if there is no database connection, or database type is invalid.
15
- */
16
- static getCollection(a){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"getCollection()",message:"No database connection"});if("mongodb"!==xp_1.xp.dbType)throw new xplogs_1.XpFatal({function:"getCollection()",message:"MongoDB has to be your database type to use this function."});return xp_1.xp.database.db().collection(a)}
17
- /**
18
- * Creates one document in the database.
19
- *
20
- * @async
21
- * @param {UserOptions | LevelRoleOptions} query - The document to create.
22
- * @link https://simplyxp.js.org/docs/next/handlers/database#createOne Documentation
23
- * @returns {Promise<UserResult | LevelRoleResult>} The created document.
24
- * @throws {XpFatal} Throws an error if there is no database connection.
25
- */static async createOne(a){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"createOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await this.getCollection(a.collection).insertOne({...a.data,lastUpdated:(new Date).toISOString()}).catch(a=>handleError(a,"createOne()"));break;case"sqlite":"simply-xps"===a.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, level, name, lastUpdated, xp, xp_rate, flags) VALUES (?, ?, ?, ?, ?, ?, ?, ?)').run(a.data.user,a.data.guild,a.data.level,a.data?.name,(new Date).toISOString(),a.data.xp,a.data.xp_rate,JSON.stringify(a.data?.flags)):xp_1.xp.database.prepare('INSERT INTO "simply-xp-levelroles" (gid, lvlrole, lastUpdated) VALUES (?, ?, ?)').run(a.data.guild,JSON.stringify(a.data.lvlrole),(new Date).toISOString())}return db.findOne(a)}
26
- /**
27
- * Deletes multiple documents from the database.
28
- * @async
29
- * @param {UserOptions | LevelRoleOptions} query - The documents to delete.
30
- * @link https://simplyxp.js.org/docs/next/handlers/database#deleteMany Documentation
31
- * @returns {Promise<boolean>} `true` if the documents were successfully deleted, otherwise `false`.
32
- * @throws {XpFatal} Throws an error if there is no database connection.
33
- */static async deleteMany(a){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"deleteMany()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=await this.getCollection(a.collection).deleteMany(a.data).catch(a=>handleError(a,"deleteMany()"));break;case"sqlite":e=("simply-xps"===a.collection?xp_1.xp.database.prepare('DELETE FROM "simply-xps" WHERE guild = ?'):xp_1.xp.database.prepare('DELETE FROM "simply-xp-levelroles" WHERE gid = ?')).run(a.data.guild)}return!!e}
34
- /**
35
- * Deletes one document from the database.
36
- *
37
- * @async
38
- * @param {UserOptions | LevelRoleOptions} query - The document to delete.
39
- * @link https://simplyxp.js.org/docs/next/handlers/database#deleteOne Documentation
40
- * @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
41
- * @throws {XpFatal} Throws an error if there is no database connection.
42
- */static async deleteOne(e){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"deleteOne()",message:"No database connection"});let a;switch(xp_1.xp.dbType){case"mongodb":a=await this.getCollection(e.collection).deleteOne(e.data).catch(a=>handleError(a,"deleteOne()"));break;case"sqlite":a="simply-xps"===e.collection?xp_1.xp.database.prepare('DELETE FROM "simply-xps" WHERE guild = ? AND user = ?').run(e.data.guild,e.data.user):(a=(a=await this.find(e.collection,e.data.guild)).filter(a=>a.lvlrole.lvl===e.data.lvlrole.lvl)[0],xp_1.xp.database.prepare('DELETE FROM "simply-xp-levelroles" WHERE gid = ? AND lvlrole = ?').run(e.data.guild,JSON.stringify(a.lvlrole)))}return!!a}
43
- /**
44
- * Finds one document in the database.
45
- *
46
- * @async
47
- * @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
48
- * @link https://simplyxp.js.org/docs/next/handlers/database#findOne Documentation
49
- * @returns {Promise<UserResult | LevelRoleResult>} The found document.
50
- * @throws {XpFatal} Throws an error if there is no database connection.
51
- */static async findOne(e){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"findOne()",message:"No database connection"});let a;switch(xp_1.xp.dbType){case"mongodb":a="simply-xps"===e.collection?await this.getCollection(e.collection).findOne(e.data).catch(a=>handleError(a,"findOne()")):await this.getCollection(e.collection).findOne({guild:e.data.guild,"lvlrole.lvl":e.data.lvlrole.lvl}).catch(a=>handleError(a,"findOne()"));break;case"sqlite":a="simply-xps"===e.collection?xp_1.xp.database.prepare('SELECT * FROM "simply-xps" WHERE guild = ? AND user = ?').get(e.data.guild,e.data.user):(a=await this.find(e.collection,e.data.guild)).filter(a=>a.lvlrole.lvl===e.data.lvlrole.lvl)[0]}return a}
52
- /**
53
- * Finds multiple documents in the database.
54
- *
55
- * @async
56
- * @param {"simply-xps" | "simply-xp-levelroles"} collection - The collection to search for multiple documents.
57
- * @param {string} guild - The guild ID to search for.
58
- * @link https://simplyxp.js.org/docs/next/handlers/database#find Documentation
59
- * @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
60
- * @throws {XpFatal} Throws an error if there is no database connection.
61
- */static async find(a,e){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"find()",message:"No database connection"});let t;switch(xp_1.xp.dbType){case"mongodb":t=xp_1.xp.database.db().collection(a).find({guild:e}).toArray().catch(a=>handleError(a,"find()"));break;case"sqlite":"simply-xps"===a?(t=xp_1.xp.database.prepare('SELECT * FROM "simply-xps" WHERE guild = ?').all(e)).length&&(t=await Promise.all(t.map(async a=>(a.flags=JSON.parse(a.flags),a)))):(t=xp_1.xp.database.prepare('SELECT * FROM "simply-xp-levelroles" WHERE gid = ?').all(e)).length&&(t=await Promise.all(t.map(async a=>(a.lvlrole=JSON.parse(a.lvlrole),a))))}return t}
62
- /**
63
- * Finds all documents in a collection.
64
- * @param {"simply-xps" | "simply-xp-levelroles"} collection - The collection to search for all documents.
65
- * @link https://simplyxp.js.org/docs/next/handlers/database#findAll Documentation
66
- * @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
67
- * @throws {XpFatal} Throws an error if there is no database connection.
68
- */static async findAll(a){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"findAll()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(a).find().toArray().catch(a=>handleError(a,"findAll()"));break;case"sqlite":"simply-xps"===a?(e=xp_1.xp.database.prepare('SELECT * FROM "simply-xps"').all()).length&&(e=await Promise.all(e.map(async a=>(a.flags=JSON.parse(a.flags),a)))):(e=xp_1.xp.database.prepare('SELECT * FROM "simply-xp-levelroles"').all()).length&&(e=await Promise.all(e.map(async a=>(a.lvlrole=JSON.parse(a.lvlrole),a))))}return e}
69
- /**
70
- * Updates one document in the database.
71
- *
72
- * @async
73
- * @param {UserOptions | LevelRoleOptions} filter - The document to update.
74
- * @param {UserOptions | LevelRoleOptions} update - The document update data.
75
- * @param {object} [options] - MongoDB options for updating the document.
76
- * @link https://simplyxp.js.org/docs/next/handlers/database#updateOne Documentation
77
- * @returns {Promise<UserResult | LevelRoleResult>} The updated document.
78
- * @throws {XpFatal} Throws an error if there is no database connection.
79
- */static async updateOne(a,e,t){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"updateOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await this.getCollection(e.collection).updateOne(a.data,{$set:{...e.data,lastUpdated:(new Date).toISOString()}},t).catch(a=>handleError(a,"updateOne()"));break;case"sqlite":if("simply-xps"===a.collection&&"simply-xps"===e.collection){if(!(e.data.user&&e.data.guild&&e.data.level&&e.data.xp&&e.data.xp_rate))throw new xplogs_1.XpFatal({function:"updateOne()",message:"User, guild, level, xp, and xp_rate are required fields for updating a user document."});xp_1.xp.database.prepare(`UPDATE "simply-xps" SET xp_rate = ?, xp = ?, lastUpdated = ?, level = ? ${e.data?.name?", name = ?":""} ${e.data?.flags?", flags = ?":""} WHERE guild = ? AND user = ?`).run(e.data?.name?e.data?.flags?[e.data.xp_rate,e.data.xp,(new Date).toISOString(),e.data.level,e.data.name,JSON.stringify(e.data.flags),a.data.guild,a.data.user]:[e.data.xp_rate,e.data.xp,(new Date).toISOString(),e.data.level,e.data.name,a.data.guild,a.data.user]:e.data?.flags?[e.data.xp_rate,e.data.xp,(new Date).toISOString(),e.data.level,JSON.stringify(e.data.flags),a.data.guild,a.data.user]:[e.data.xp_rate,e.data.xp,(new Date).toISOString(),e.data.level,a.data.guild,a.data.user])}else{if("simply-xp-levelroles"!==a.collection||"simply-xp-levelroles"!==e.collection)throw new xplogs_1.XpFatal({function:"updateOne()",message:"Collection mismatch, expected same collection on both filter and update."});xp_1.xp.database.prepare('UPDATE "simply-xp-levelroles" SET lvlrole = ? WHERE gid = ?').run(JSON.stringify(e.data.lvlrole),a.data.guild)}}return db.findOne(e)}}exports.db=db;
@@ -1,27 +0,0 @@
1
- import { MongoClient } from "mongodb";
2
- import { Database } from "better-sqlite3";
3
- /**
4
- * Migration functions
5
- * @class migrate
6
- */
7
- export declare class migrate {
8
- /**
9
- * Effortlessly migrate from discord-xp to simply-xp.
10
- * @async
11
- * @param {boolean} deleteOld - Delete old data after migration
12
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratediscord_xp
13
- * @returns {Promise<boolean>} - Returns true if migration is successful
14
- * @throws {XpLog.err} - If migration fails.
15
- */
16
- static discord_xp(deleteOld?: boolean): Promise<boolean>;
17
- /**
18
- * Effortlessly migrate from MongoDB to SQLite. (or vice versa)
19
- * @async
20
- * @param {"mongodb"|"sqlite"} dbType
21
- * @param {Database | MongoClient} connection
22
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratefromdb
23
- * @returns {Promise<boolean>} - Returns true if migration is successful
24
- * @throws {XpFatal} - If parameters are not provided correctly
25
- */
26
- static fromDB(dbType: "mongodb" | "sqlite", connection: Database | MongoClient): Promise<boolean>;
27
- }
@@ -1,19 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.migrate=void 0;let xplogs_1=require("./functions/xplogs"),xp_1=require("../xp"),connect_1=require("./connect");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,t=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 {Database | 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 ${t.length} DOCUMENTS`);try{for(a of t)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 t;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! 🎉")}t=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! 🎉")}t=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 ${t.length} RESULTS`),await Promise.all(t.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}}exports.migrate=migrate;
@@ -1,78 +0,0 @@
1
- import { LevelRoleResult } from "./functions/database";
2
- /**
3
- * Get Roles Object
4
- * @property {boolean?} includeNextRoles - Include roles for the next levels.
5
- * @property {boolean?} includePreviousRoles - Include roles for the previous levels.
6
- */
7
- type GetRolesObject = {
8
- includeNextRoles?: boolean;
9
- includePreviousRoles?: boolean;
10
- };
11
- /**
12
- * Role setup object
13
- * @property {string} guild - The guild ID
14
- * @property {number} level - The level number
15
- * @property {string[] | string} role - The role(s) to add
16
- */
17
- export interface RoleSetupObject {
18
- level: number;
19
- role: string[] | string;
20
- }
21
- /**
22
- * Setup roles for levels
23
- * @class roleSetup
24
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup
25
- */
26
- export declare class roleSetup {
27
- /**
28
- * Add a role to the role setup
29
- * @async
30
- * @param {string} guildId - The guild ID
31
- * @param {RoleSetupObject} options - Level/role options
32
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
33
- * @returns {Promise<boolean>} - True if successful
34
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
35
- */
36
- static add(guildId: string, options: RoleSetupObject): Promise<boolean>;
37
- /**
38
- * Get roles for a user's level
39
- * @async
40
- * @param {string} userId - The user ID
41
- * @param {string} guildId - The guild ID
42
- * @param {GetRolesObject} options - Options
43
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupgetRoles
44
- * @returns {Promise<string[]>} - Array of role IDs or empty array if none
45
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
46
- */
47
- static getRoles(userId: string, guildId: string, options?: GetRolesObject): Promise<string[]>;
48
- /**
49
- * Find a role in roleSetup
50
- * @async
51
- * @param {string} guildId - The guild ID
52
- * @param {number} levelNumber - The level number
53
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
54
- * @returns {Promise<LevelRoleResult>} - The level role object
55
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
56
- */
57
- static find(guildId: string, levelNumber: number): Promise<LevelRoleResult>;
58
- /**
59
- * List all level roles in a guild
60
- * @async
61
- * @param {string} guildId - The guild ID
62
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetuplist
63
- * @returns {Promise<LevelRoleResult[]>} - The level role object
64
- * @throws {XpFatal} If there are no roles in the guild.
65
- */
66
- static list(guildId: string): Promise<LevelRoleResult[]>;
67
- /**
68
- * Remove a level from the role setup
69
- * @async
70
- * @param {string} guildId - The guild ID
71
- * @param {number} levelNumber - The level number
72
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
73
- * @returns {Promise<boolean>} - True if successful
74
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
75
- */
76
- static remove(guildId: string, levelNumber: number): Promise<boolean>;
77
- }
78
- export {};
@@ -1,47 +0,0 @@
1
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.roleSetup=void 0;let xp_1=require("../xp"),xplogs_1=require("./functions/xplogs");class roleSetup{
2
- /**
3
- * Add a role to the role setup
4
- * @async
5
- * @param {string} guildId - The guild ID
6
- * @param {RoleSetupObject} options - Level/role options
7
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
8
- * @returns {Promise<boolean>} - True if successful
9
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
10
- */
11
- static async add(e,l){if(!e)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Guild ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Options were not provided"});if(isNaN(l?.level))throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Level must be a number"});if(l?.role)return"string"==typeof l?.role&&(l.role=[l.role]),xp_1.db.createOne({collection:"simply-xp-levelroles",data:{guild:e,lvlrole:{lvl:l.level,role:l.role}}}).then(()=>!0).catch(()=>!1);throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Role was not provided"})}
12
- /**
13
- * Get roles for a user's level
14
- * @async
15
- * @param {string} userId - The user ID
16
- * @param {string} guildId - The guild ID
17
- * @param {GetRolesObject} options - Options
18
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupgetRoles
19
- * @returns {Promise<string[]>} - Array of role IDs or empty array if none
20
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
21
- */static async getRoles(e,l,o={}){if(!e)throw new xplogs_1.XpFatal({function:"roleSetup.getRoles()",message:"User ID was not provided"});if(!l)throw new xplogs_1.XpFatal({function:"roleSetup.getRoles()",message:"Guild ID was not provided"});let t=await xp_1.db.findOne({collection:"simply-xps",data:{user:e,guild:l}}),r=await roleSetup.list(l);if(!t||!t?.level)return[];let s=[];return r.forEach(({lvlrole:{lvl:e,role:l}})=>{l&&(e<t.level&&o?.includePreviousRoles||e>t.level&&o?.includeNextRoles||e===t.level)&&s.push(...Array.isArray(l)?l:[l])}),s}
22
- /**
23
- * Find a role in roleSetup
24
- * @async
25
- * @param {string} guildId - The guild ID
26
- * @param {number} levelNumber - The level number
27
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
28
- * @returns {Promise<LevelRoleResult>} - The level role object
29
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
30
- */static async find(e,l){if(!e)throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Guild ID was not provided"});if(isNaN(l))throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Level Number was not provided"});return xp_1.db.findOne({collection:"simply-xp-levelroles",data:{guild:e,lvlrole:{lvl:l}}})}
31
- /**
32
- * List all level roles in a guild
33
- * @async
34
- * @param {string} guildId - The guild ID
35
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetuplist
36
- * @returns {Promise<LevelRoleResult[]>} - The level role object
37
- * @throws {XpFatal} If there are no roles in the guild.
38
- */static async list(e){if(e)return xp_1.db.find("simply-xp-levelroles",e);throw new xplogs_1.XpFatal({function:"roleSetup.list()",message:"Guild ID was not provided"})}
39
- /**
40
- * Remove a level from the role setup
41
- * @async
42
- * @param {string} guildId - The guild ID
43
- * @param {number} levelNumber - The level number
44
- * @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
45
- * @returns {Promise<boolean>} - True if successful
46
- * @throws {XpFatal} If an invalid type is provided or value is not provided.
47
- */static async remove(e,l){if(!e)throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Guild ID was not provided"});if(isNaN(l))throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Level Number was not provided"});return xp_1.db.deleteOne({collection:"simply-xp-levelroles",data:{guild:e,lvlrole:{lvl:l}}})}}exports.roleSetup=roleSetup;