simply-xp 2.0.0-dev.2 → 2.0.0-dev.2-fix.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/src/add.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * @link `Documentation:` https://simplyxp.js.org/docs/addlevel
10
10
  * @returns {Promise<UserResult>} - Object of user data on success
11
11
  * @throws {XpFatal} - If parameters are not provided correctly
12
- */async function addLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"Guild ID was not provided"});if(!level)throw new xplogs_1.XpFatal({function:"addLevel()",message:"Level was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(e)return database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:e.level+level,xp:(0,utilities_1.convertFrom)(level+e.level)}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,utilities_1.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"User does not exist"})}
12
+ */async function addLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"addLevel()",message:"Guild ID was not provided"});if(isNaN(level))throw new xplogs_1.XpFatal({function:"addLevel()",message:"Level was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});if(e)return database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:e.level+level,xp:(0,utilities_1.convertFrom)(level+e.level)}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,utilities_1.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"addLevel()",message:"User does not exist"})}
13
13
  /**
14
14
  * Add XP to a user.
15
15
  * @async
@@ -10,28 +10,15 @@
10
10
  * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
11
11
  */async function connect(uri,options={type:void 0}){var e,{type:t,auto_create:o,auto_purge:r,notify:a,debug:n}=options;if(!uri)throw new xplogs_1.XpFatal({function:"connect()",message:"No URI Provided"});switch(!1===a&&(xp_1.xp.notify=!1),o&&(xp_1.xp.auto_create=!0),r&&(xp_1.xp.auto_purge=!0),n&&(xp_1.xp.debug=!0),t||(options.type="mongodb",xplogs_1.XpLog.warn("connect()","Database type not provided, defaulting to MongoDB")),t){case"mongodb":if(e=(await Promise.resolve().then(()=>__importStar(require("mongodb")))).MongoClient,!await checkPackageVersion("mongodb"))return xplogs_1.XpLog.err("connect()","MongoDB V4 or higher is required");e=await e.connect(uri).catch(error=>{throw new xplogs_1.XpFatal({function:"connect()",message:error.message})}),xp_1.xp.dbType="mongodb",xp_1.xp.database=e||void 0;break;case"sqlite":try{var[s,i]=await Promise.all([Promise.resolve().then(()=>__importStar(require("better-sqlite3"))),checkPackageVersion("sqlite")]);if(!i)return xplogs_1.XpLog.err("connect()","better-sqlite3 V7 or higher is required");xp_1.xp.database=new s.default(uri),xp_1.xp.dbType="sqlite",xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xps"
12
12
  (
13
- user
14
- TEXT
15
- UNIQUE,
16
- guild
17
- TEXT,
18
- xp
19
- INTEGER
20
- DEFAULT
21
- 0,
22
- level
23
- INTEGER
24
- DEFAULT
25
- 0
13
+ user TEXT UNIQUE,
14
+ guild TEXT,
15
+ name TEXT DEFAULT NULL,
16
+ level INTEGER DEFAULT 0,
17
+ xp INTEGER DEFAULT 0
26
18
  )`),xp_1.xp.database.exec(`CREATE TABLE IF NOT EXISTS "simply-xp-levelroles"
27
19
  (
28
- gid
29
- TEXT
30
- UNIQUE,
31
- lvlrole
32
- TEXT
33
- NOT
34
- NULL
20
+ gid TEXT UNIQUE,
21
+ lvlrole TEXT NOT NULL
35
22
  )`)}catch(t){if("object"==typeof t&&null!==t&&void 0!==(e=t).code&&"MODULE_NOT_FOUND"!==e.code)throw new xplogs_1.XpFatal({function:"connect()",message:e.message})}break;default:throw new xplogs_1.XpFatal({function:"connect()",message:"DATABASE TYPE NOT PROVIDED OR INVALID"})}return!!xp_1.xp.database&&(xplogs_1.XpLog.info("connect()","Connected to database!"),!0)}
36
23
  /**
37
24
  * Returns the package manager used
@@ -5,7 +5,8 @@
5
5
  * @param {string} functionName
6
6
  * @returns {void}
7
7
  * @private
8
- */function handleError(error,functionName){throw new xplogs_1.XpFatal({function:"db."+functionName,message:error})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.db=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp");class db{
8
+ */
9
+ function handleError(error,functionName){throw new xplogs_1.XpFatal({function:"db."+functionName,message:error})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.db=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp");class db{
9
10
  /**
10
11
  * Creates one document in the database.
11
12
  *
@@ -15,7 +16,7 @@
15
16
  * @returns {Promise<UserResult | LevelRoleResult>} The created document.
16
17
  * @throws {XpFatal} Throws an error if there is no database connection.
17
18
  */
18
- static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"createOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).insertOne(query.data).catch(error=>handleError(error,"createOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, xp, level) VALUES (?, ?, ?, ?)').run(query.data.user,query.data.guild,query.data.xp,query.data.level):xp_1.xp.database.prepare('INSERT INTO "simply-xp-levelroles" (guild, level, role) VALUES (?, ?, ?)').run(query.data.guild,query.data.level,query.data.roles)}return e}
19
+ static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"createOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).insertOne(query.data).catch(error=>handleError(error,"createOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, xp, level, name) VALUES (?, ?, ?, ?, ?)').run(query.data.user,query.data.guild,query.data.xp,query.data.level,query.data?.name):xp_1.xp.database.prepare('INSERT INTO "simply-xp-levelroles" (guild, level, role) VALUES (?, ?, ?)').run(query.data.guild,query.data.level,query.data.roles)}return e}
19
20
  /**
20
21
  * Deletes one document from the database.
21
22
  *
@@ -53,4 +54,4 @@ static async createOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({f
53
54
  * @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
54
55
  * @returns {Promise<UserResult | LevelRoleResult>} The updated document.
55
56
  * @throws {XpFatal} Throws an error if there is no database connection.
56
- */static async updateOne(filter,update,options){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"updateOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await xp_1.xp.database.db().collection(update.collection).updateOne(filter.data,{$set:update.data},options).catch(error=>handleError(error,"updateOne()"));break;case"sqlite":if("simply-xps"===filter.collection&&"simply-xps"===update.collection&&xp_1.xp.database.prepare('UPDATE "simply-xps" SET xp = ?, level = ? WHERE guild = ? AND user = ?').run(update.data.xp,update.data.level,filter.data.guild,filter.data.user),"simply-xps"!==filter.collection||"simply-xp-levelroles"!==update.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 role = ? WHERE guild = ? AND level = ?').run(update.data.roles,filter.data.guild,filter.data.level)}return db.findOne(update)}}exports.db=db;
57
+ */static async updateOne(filter,update,options){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"updateOne()",message:"No database connection"});switch(xp_1.xp.dbType){case"mongodb":await xp_1.xp.database.db().collection(update.collection).updateOne(filter.data,{$set:update.data},options).catch(error=>handleError(error,"updateOne()"));break;case"sqlite":if("simply-xps"===filter.collection&&"simply-xps"===update.collection)xp_1.xp.database.prepare('UPDATE "simply-xps" SET xp = ?, level = ?, name = ? WHERE guild = ? AND user = ?').run(update.data.xp,update.data.level,update.data?.name,filter.data.guild,filter.data?.user);else{if("simply-xp-levelroles"!==filter.collection||"simply-xp-levelroles"!==update.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 role = ? WHERE guild = ? AND level = ?').run(update.data.roles,filter.data.guild,filter.data.level)}}return db.findOne(update)}}exports.db=db;
@@ -7,7 +7,7 @@
7
7
  * @link `Documentation:` https://simplyxp.js.org/docs/utilities/convert
8
8
  * @returns {number} - The converted value. (XP to level or level to XP)
9
9
  * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
10
- */function convertFrom(value,type="level"){if(!value)throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Value was not provided"});if("xp"!==type&&"level"!==type)throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"});if("level"===type)return Math.pow(value/.1,2);if("xp"===type)return Math.floor(.1*Math.sqrt(value));throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Invalid type provided"})}
10
+ */function convertFrom(value,type="level"){if(isNaN(value))throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Value was not provided"});if("xp"!==type&&"level"!==type)throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"});if("level"===type)return Math.pow(value/.1,2);if("xp"===type)return Math.floor(.1*Math.sqrt(value));throw new xplogs_1.XpFatal({function:"convertFrom()",message:"Invalid type provided"})}
11
11
  /**
12
12
  * Updates the options of the XP client.
13
13
  * @param {NewClientOptions} clientOptions - The new options to update.
package/lib/src/set.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * @link `Documentation:` https://simplyxp.js.org/docs/setlevel
10
10
  * @returns {Promise<UserResult>} - Object of user data on success
11
11
  * @throws {XpFatal} - If parameters are not provided correctly
12
- */async function setLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"Guild ID was not provided"});if(!level)throw new xplogs_1.XpFatal({function:"setLevel()",message:"Level was not provided"});if(await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))return database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,utilities_1.convertFrom)(level)}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,utilities_1.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"})}
12
+ */async function setLevel(userId,guildId,level,username){if(!userId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setLevel()",message:"Guild ID was not provided"});if(isNaN(level))throw new xplogs_1.XpFatal({function:"setLevel()",message:"Level was not provided"});if(await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}}))return database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,utilities_1.convertFrom)(level)}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:level,xp:(0,utilities_1.convertFrom)(level)}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"})}
13
13
  /**
14
14
  * Set user XP
15
15
  * @async
@@ -20,4 +20,4 @@
20
20
  * @link `Documentation:` https://simplyxp.js.org/docs/setxp
21
21
  * @returns {Promise<XPResult>} - Object of user data on success
22
22
  * @throws {XpFatal} - If parameters are not provided correctly
23
- */async function setXP(userId,guildId,xpData,username){if(!userId)throw new xplogs_1.XpFatal({function:"setXP()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setXP()",message:"Guild ID was not provided"});if(!xpData)throw new xplogs_1.XpFatal({function:"setXP()",message:"XP was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});let s;if(e)s=await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,utilities_1.convertFrom)(xpData),xp:xpData}});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"setXP()",message:"User does not exist"});s=await database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convertFrom)(xpData),xp:xpData}})}return{...s,hasLevelledUp:s.level>e.level}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setXP=exports.setLevel=void 0;const xplogs_1=require("./functions/xplogs"),utilities_1=require("./functions/utilities"),database_1=require("./functions/database"),xp_1=require("../xp");exports.setLevel=setLevel,exports.setXP=setXP;
23
+ */async function setXP(userId,guildId,xpData,username){if(!userId)throw new xplogs_1.XpFatal({function:"setXP()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"setXP()",message:"Guild ID was not provided"});if(isNaN(xpData))throw new xplogs_1.XpFatal({function:"setXP()",message:"XP was not provided"});var e=await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}});let s;if(e)s=await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,utilities_1.convertFrom)(xpData),xp:xpData}});else{if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"setXP()",message:"User does not exist"});s=await database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convertFrom)(xpData),xp:xpData}})}return{...s,hasLevelledUp:s.level>e.level}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setXP=exports.setLevel=void 0;const xplogs_1=require("./functions/xplogs"),utilities_1=require("./functions/utilities"),database_1=require("./functions/database"),xp_1=require("../xp");exports.setLevel=setLevel,exports.setXP=setXP;
package/package.json CHANGED
@@ -1,70 +1,70 @@
1
- {
2
- "name": "simply-xp",
3
- "version": "2.0.0-dev.2",
4
- "description": "The easiest way to implement xp system",
5
- "main": "lib/xp.js",
6
- "scripts": {
7
- "beta": "node Tests/clean.mjs && pnpm update && npm publish --tag beta",
8
- "clean": "node Tests/clean.mjs",
9
- "dev": "node Tests/clean.mjs && pnpm update && npm publish --tag dev",
10
- "docs": "node Tests/jsdocs.cjs",
11
- "latest": "node Tests/clean.mjs && pnpm update && npm publish",
12
- "test": "node Tests/clean.mjs && node Tests/test.cjs"
13
- },
14
- "author": "Abadima",
15
- "keywords": [
16
- "amaribot",
17
- "charts",
18
- "discord",
19
- "discord.js",
20
- "discord-xp",
21
- "easy",
22
- "fun",
23
- "guilded",
24
- "leaderboard",
25
- "level role",
26
- "level up",
27
- "mee6",
28
- "mongodb",
29
- "package",
30
- "simply",
31
- "simply-djs",
32
- "simplydjs",
33
- "sqlite",
34
- "system",
35
- "xp"
36
- ],
37
- "license": "Apache-2.0",
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/Rahuletto/simply-xp.git"
41
- },
42
- "dependencies": {
43
- "@napi-rs/canvas": "^0.1.41"
44
- },
45
- "devDependencies": {
46
- "@types/better-sqlite3": "^7.6.4",
47
- "@types/node": "^20.4.8",
48
- "@typescript-eslint/eslint-plugin": "^6.2.1",
49
- "@typescript-eslint/parser": "^6.2.1",
50
- "better-sqlite3": "8.5.0",
51
- "discord.js": "^14.12.1",
52
- "eslint": "^8.46.0",
53
- "guilded.ts": "^0.20.2",
54
- "jsdoc-to-markdown": "^8.0.0",
55
- "mongodb": "5.7.0",
56
- "typescript": "^5.1.6",
57
- "uglify-js": "^3.17.4"
58
- },
59
- "engines": {
60
- "node": ">=15.5.0"
61
- },
62
- "bugs": {
63
- "url": "https://github.com/Rahuletto/simply-xp/issues"
64
- },
65
- "homepage": "https://simplyxp.js.org",
66
- "directories": {
67
- "doc": "Mini_Docs",
68
- "lib": "lib"
69
- }
70
- }
1
+ {
2
+ "name": "simply-xp",
3
+ "version": "2.0.0-dev.2-fix.0",
4
+ "description": "The easiest way to implement xp system",
5
+ "main": "lib/xp.js",
6
+ "scripts": {
7
+ "beta": "node Tests/clean.mjs && pnpm update && npm publish --tag beta",
8
+ "clean": "node Tests/clean.mjs",
9
+ "dev": "node Tests/clean.mjs && pnpm update && npm publish --tag dev",
10
+ "docs": "node Tests/jsdocs.cjs",
11
+ "latest": "node Tests/clean.mjs && pnpm update && npm publish",
12
+ "test": "node Tests/clean.mjs && node Tests/test.cjs"
13
+ },
14
+ "author": "Abadima",
15
+ "keywords": [
16
+ "amaribot",
17
+ "charts",
18
+ "discord",
19
+ "discord.js",
20
+ "discord-xp",
21
+ "easy",
22
+ "fun",
23
+ "guilded",
24
+ "leaderboard",
25
+ "level role",
26
+ "level up",
27
+ "mee6",
28
+ "mongodb",
29
+ "package",
30
+ "simply",
31
+ "simply-djs",
32
+ "simplydjs",
33
+ "sqlite",
34
+ "system",
35
+ "xp"
36
+ ],
37
+ "license": "Apache-2.0",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/Rahuletto/simply-xp.git"
41
+ },
42
+ "dependencies": {
43
+ "@napi-rs/canvas": "^0.1.41"
44
+ },
45
+ "devDependencies": {
46
+ "@types/better-sqlite3": "^7.6.4",
47
+ "@types/node": "^20.4.8",
48
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
49
+ "@typescript-eslint/parser": "^6.3.0",
50
+ "better-sqlite3": "8.5.0",
51
+ "discord.js": "^14.12.1",
52
+ "eslint": "^8.46.0",
53
+ "guilded.ts": "^0.20.2",
54
+ "jsdoc-to-markdown": "^8.0.0",
55
+ "mongodb": "5.7.0",
56
+ "typescript": "^5.1.6",
57
+ "uglify-js": "^3.17.4"
58
+ },
59
+ "engines": {
60
+ "node": ">=15.5.0"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/Rahuletto/simply-xp/issues"
64
+ },
65
+ "homepage": "https://simplyxp.js.org",
66
+ "directories": {
67
+ "doc": "Mini_Docs",
68
+ "lib": "lib"
69
+ }
70
+ }