simply-xp 2.0.0-dev.3-fix.2 → 2.0.0-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/lib/src/Fonts/BalooBhaijaan-Regular.woff2 +0 -0
- package/lib/src/add.d.ts +2 -2
- package/lib/src/add.js +4 -6
- package/lib/src/cards.d.ts +75 -25
- package/lib/src/cards.js +23 -11
- package/lib/src/charts.d.ts +19 -9
- package/lib/src/charts.js +4 -5
- package/lib/src/connect.d.ts +5 -3
- package/lib/src/connect.js +9 -9
- package/lib/src/create.d.ts +1 -1
- package/lib/src/create.js +2 -3
- package/lib/src/deprecated/rank.d.ts +1 -1
- package/lib/src/deprecated/rank.js +2 -3
- package/lib/src/fetch.d.ts +3 -3
- package/lib/src/fetch.js +3 -4
- package/lib/src/functions/database.d.ts +15 -6
- package/lib/src/functions/database.js +17 -10
- package/lib/src/functions/utilities.d.ts +2 -2
- package/lib/src/functions/utilities.js +4 -6
- package/lib/src/leaderboard.d.ts +2 -2
- package/lib/src/leaderboard.js +2 -3
- package/lib/src/migrate.d.ts +2 -2
- package/lib/src/migrate.js +4 -4
- package/lib/src/reset.d.ts +1 -1
- package/lib/src/reset.js +2 -3
- package/lib/src/roleSetup.d.ts +3 -4
- package/lib/src/roleSetup.js +3 -3
- package/lib/src/set.d.ts +2 -2
- package/lib/src/set.js +4 -6
- package/lib/xp.d.ts +1 -1
- package/lib/xp.js +5 -4
- package/package.json +19 -16
- package/lib/src/Fonts/Baloo-Regular.eot +0 -0
package/lib/src/fetch.js
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} userId
|
|
6
6
|
* @param {string} guildId
|
|
7
|
-
* @param {string} username - Username to use if auto_create is enabled
|
|
8
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/fetch
|
|
7
|
+
* @param {string?} username - Username to use if auto_create is enabled
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/fetch
|
|
9
9
|
* @returns {Promise<{name: string | null, user: string, guild: string, level: number, position: number, xp: number}>}
|
|
10
10
|
* @throws {XpFatal} If invalid parameters are provided, or if the user data is not found.
|
|
11
|
-
*/
|
|
12
|
-
async function fetch(userId,guildId,username){if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});var e=await(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db.find({collection:"simply-xps",data:{guild:guildId}}),t=e.find(u=>u.user===userId);if(t)return e=e.sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===userId)+1,{name:t?.name,user:t.user,guild:t.guild,level:t.level,position:e,xp:t.xp};if(xp_1.xp.auto_create&&username)return(await Promise.resolve().then(()=>__importStar(require("./create")))).create(guildId,userId,username);throw new xplogs_1.XpFatal({function:"fetch()",message:"User data not found"})}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,t;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(t in mod)"default"!==t&&Object.prototype.hasOwnProperty.call(mod,t)&&__createBinding(e,mod,t);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetch=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.fetch=fetch;
|
|
11
|
+
*/async function fetch(userId,guildId,username){var e;if(!userId)throw new xplogs_1.XpFatal({function:"create()",message:"User ID was not provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"create()",message:"Guild ID was not provided"});let t=(e=await(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db.find({collection:"simply-xps",data:{guild:guildId}})).find(u=>u.user===userId);if(!t){if(!xp_1.xp.auto_create||!username)throw new xplogs_1.XpFatal({function:"fetch()",message:"User data not found"});t=await(await Promise.resolve().then(()=>__importStar(require("./create")))).create(guildId,userId,username)}return guildId=e.sort((a,b)=>b.xp-a.xp).findIndex(u=>u.user===userId)+1,{name:t?.name,user:t.user,guild:t.guild,level:t.level,position:guildId,xp:t.xp}}var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var e=Object.getOwnPropertyDescriptor(m,k);e&&("get"in e?m.__esModule:!e.writable&&!e.configurable)||(e={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,e)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(o,v){Object.defineProperty(o,"default",{enumerable:!0,value:v})}:function(o,v){o.default=v}),__importStar=this&&this.__importStar||function(mod){var e,t;if(mod&&mod.__esModule)return mod;if(e={},null!=mod)for(t in mod)"default"!==t&&Object.prototype.hasOwnProperty.call(mod,t)&&__createBinding(e,mod,t);return __setModuleDefault(e,mod),e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.fetch=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.fetch=fetch;
|
|
@@ -69,7 +69,7 @@ export declare class db {
|
|
|
69
69
|
/**
|
|
70
70
|
* Gets a collection from the database.
|
|
71
71
|
* @param {collection} collection - The collection to get.
|
|
72
|
-
* @link https://simplyxp.js.org/docs/handlers/database#getCollection Documentation
|
|
72
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#getCollection Documentation
|
|
73
73
|
* @returns {Collection} The collection.
|
|
74
74
|
* @throws {XpFatal} Throws an error if there is no database connection, or database type is invalid.
|
|
75
75
|
*/
|
|
@@ -79,17 +79,26 @@ export declare class db {
|
|
|
79
79
|
*
|
|
80
80
|
* @async
|
|
81
81
|
* @param {UserOptions | LevelRoleOptions} query - The document to create.
|
|
82
|
-
* @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
|
|
82
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#createOne Documentation
|
|
83
83
|
* @returns {Promise<UserResult | LevelRoleResult>} The created document.
|
|
84
84
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
85
85
|
*/
|
|
86
86
|
static createOne(query: UserOptions | LevelRoleOptions): Promise<UserResult | LevelRoleResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Deletes multiple documents from the database.
|
|
89
|
+
* @async
|
|
90
|
+
* @param {UserOptions | LevelRoleOptions} query - The documents to delete.
|
|
91
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#deleteMany Documentation
|
|
92
|
+
* @returns {Promise<boolean>} `true` if the documents were successfully deleted, otherwise `false`.
|
|
93
|
+
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
94
|
+
*/
|
|
95
|
+
static deleteMany(query: UserOptions | LevelRoleOptions): Promise<boolean>;
|
|
87
96
|
/**
|
|
88
97
|
* Deletes one document from the database.
|
|
89
98
|
*
|
|
90
99
|
* @async
|
|
91
100
|
* @param {UserOptions | LevelRoleOptions} query - The document to delete.
|
|
92
|
-
* @link https://simplyxp.js.org/docs/handlers/database#deleteOne Documentation
|
|
101
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#deleteOne Documentation
|
|
93
102
|
* @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
|
|
94
103
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
95
104
|
*/
|
|
@@ -99,7 +108,7 @@ export declare class db {
|
|
|
99
108
|
*
|
|
100
109
|
* @async
|
|
101
110
|
* @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
|
|
102
|
-
* @link https://simplyxp.js.org/docs/handlers/database#findOne Documentation
|
|
111
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#findOne Documentation
|
|
103
112
|
* @returns {Promise<UserResult | LevelRoleResult>} The found document.
|
|
104
113
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
105
114
|
*/
|
|
@@ -109,7 +118,7 @@ export declare class db {
|
|
|
109
118
|
*
|
|
110
119
|
* @async
|
|
111
120
|
* @param {UserOptions | LevelRoleOptions} query - The query to search for multiple documents.
|
|
112
|
-
* @link https://simplyxp.js.org/docs/handlers/database#find Documentation
|
|
121
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#find Documentation
|
|
113
122
|
* @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
|
|
114
123
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
115
124
|
*/
|
|
@@ -121,7 +130,7 @@ export declare class db {
|
|
|
121
130
|
* @param {UserOptions | LevelRoleOptions} filter - The document to update.
|
|
122
131
|
* @param {UserOptions | LevelRoleOptions} update - The document update data.
|
|
123
132
|
* @param {object} [options] - MongoDB options for updating the document.
|
|
124
|
-
* @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
|
|
133
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#updateOne Documentation
|
|
125
134
|
* @returns {Promise<UserResult | LevelRoleResult>} The updated document.
|
|
126
135
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
127
136
|
*/
|
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
* @param {string} functionName
|
|
6
6
|
* @returns {void}
|
|
7
7
|
* @private
|
|
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{
|
|
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{
|
|
10
9
|
/**
|
|
11
10
|
* Gets a collection from the database.
|
|
12
11
|
* @param {collection} collection - The collection to get.
|
|
13
|
-
* @link https://simplyxp.js.org/docs/handlers/database#getCollection Documentation
|
|
12
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#getCollection Documentation
|
|
14
13
|
* @returns {Collection} The collection.
|
|
15
14
|
* @throws {XpFatal} Throws an error if there is no database connection, or database type is invalid.
|
|
16
15
|
*/
|
|
@@ -20,16 +19,24 @@ static getCollection(collection){if(!xp_1.xp.database)throw new xplogs_1.XpFatal
|
|
|
20
19
|
*
|
|
21
20
|
* @async
|
|
22
21
|
* @param {UserOptions | LevelRoleOptions} query - The document to create.
|
|
23
|
-
* @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
|
|
22
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#createOne Documentation
|
|
24
23
|
* @returns {Promise<UserResult | LevelRoleResult>} The created document.
|
|
25
24
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
26
|
-
*/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":
|
|
25
|
+
*/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":xp_1.xp.database.db().collection(query.collection).insertOne(query.data).catch(error=>handleError(error,"createOne()")),e=db.findOne(query);break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('INSERT INTO "simply-xps" (user, guild, name, xp, level) VALUES (?, ?, ?, ?, ?)').run(query.data.user,query.data.guild,query.data?.name,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}
|
|
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(query){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=xp_1.xp.database.db().collection(query.collection).deleteMany(query.data).catch(error=>handleError(error,"deleteMany()"));break;case"sqlite":e=("simply-xps"===query.collection?xp_1.xp.database.prepare('DELETE FROM "simply-xps" WHERE guild = ?'):xp_1.xp.database.prepare('DELETE FROM "simply-xp-levelroles" WHERE guild = ?')).run(query.data.guild)}return!!e}
|
|
27
34
|
/**
|
|
28
35
|
* Deletes one document from the database.
|
|
29
36
|
*
|
|
30
37
|
* @async
|
|
31
38
|
* @param {UserOptions | LevelRoleOptions} query - The document to delete.
|
|
32
|
-
* @link https://simplyxp.js.org/docs/handlers/database#deleteOne Documentation
|
|
39
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#deleteOne Documentation
|
|
33
40
|
* @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
|
|
34
41
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
35
42
|
*/static async deleteOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"deleteOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).deleteOne(query.data).catch(error=>handleError(error,"deleteOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('DELETE FROM "simply-xps" WHERE guild = ? AND user = ?').run(query.data.guild,query.data.user):xp_1.xp.database.prepare('DELETE FROM "simply-xp-levelroles" WHERE guild = ? AND level = ?').run(query.data.guild,query.data.level)}return!!e}
|
|
@@ -38,7 +45,7 @@ static getCollection(collection){if(!xp_1.xp.database)throw new xplogs_1.XpFatal
|
|
|
38
45
|
*
|
|
39
46
|
* @async
|
|
40
47
|
* @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
|
|
41
|
-
* @link https://simplyxp.js.org/docs/handlers/database#findOne Documentation
|
|
48
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#findOne Documentation
|
|
42
49
|
* @returns {Promise<UserResult | LevelRoleResult>} The found document.
|
|
43
50
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
44
51
|
*/static async findOne(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"findOne()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).findOne(query.data).catch(error=>handleError(error,"findOne()"));break;case"sqlite":e="simply-xps"===query.collection?xp_1.xp.database.prepare('SELECT * FROM "simply-xps" WHERE guild = ? AND user = ?').get(query.data.guild,query.data.user):xp_1.xp.database.prepare('SELECT * FROM "simply-xp-levelroles" WHERE guild = ? AND level = ?').get(query.data.guild,query.data.level)}return e}
|
|
@@ -47,7 +54,7 @@ static getCollection(collection){if(!xp_1.xp.database)throw new xplogs_1.XpFatal
|
|
|
47
54
|
*
|
|
48
55
|
* @async
|
|
49
56
|
* @param {UserOptions | LevelRoleOptions} query - The query to search for multiple documents.
|
|
50
|
-
* @link https://simplyxp.js.org/docs/handlers/database#find Documentation
|
|
57
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#find Documentation
|
|
51
58
|
* @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
|
|
52
59
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
53
60
|
*/static async find(query){if(!xp_1.xp.database)throw new xplogs_1.XpFatal({function:"find()",message:"No database connection"});let e;switch(xp_1.xp.dbType){case"mongodb":e=xp_1.xp.database.db().collection(query.collection).find(query.data).toArray().catch(error=>handleError(error,"find()"));break;case"sqlite":e=("simply-xps"===query.collection?xp_1.xp.database.prepare('SELECT * FROM "simply-xps" WHERE guild = ?'):xp_1.xp.database.prepare('SELECT * FROM "simply-xp-levelroles" WHERE guild = ?')).all(query.data.guild)}return e}
|
|
@@ -58,7 +65,7 @@ static getCollection(collection){if(!xp_1.xp.database)throw new xplogs_1.XpFatal
|
|
|
58
65
|
* @param {UserOptions | LevelRoleOptions} filter - The document to update.
|
|
59
66
|
* @param {UserOptions | LevelRoleOptions} update - The document update data.
|
|
60
67
|
* @param {object} [options] - MongoDB options for updating the document.
|
|
61
|
-
* @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
|
|
68
|
+
* @link https://simplyxp.js.org/docs/next/handlers/database#updateOne Documentation
|
|
62
69
|
* @returns {Promise<UserResult | LevelRoleResult>} The updated document.
|
|
63
70
|
* @throws {XpFatal} Throws an error if there is no database connection.
|
|
64
|
-
*/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
|
|
71
|
+
*/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 = ?'+(update.data?.name?", name = ?":"")+" WHERE guild = ? AND user = ?").run(update.data?.name?[update.data.xp,update.data.level,update.data.name,filter.data.guild,filter.data.user]:[update.data.xp,update.data.level,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;
|
|
@@ -25,7 +25,7 @@ interface NewClientOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* @param {number} value.
|
|
27
27
|
* @param {"xp" | "level"} type - Type to convert from (Default: level).
|
|
28
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/utilities/convert
|
|
28
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/utilities/convert
|
|
29
29
|
* @returns {number} - The converted value. (XP to level or level to XP)
|
|
30
30
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
31
31
|
*/
|
|
@@ -33,7 +33,7 @@ export declare function convertFrom(value: number, type?: "xp" | "level"): numbe
|
|
|
33
33
|
/**
|
|
34
34
|
* Updates the options of the XP client.
|
|
35
35
|
* @param {NewClientOptions} clientOptions - The new options to update.
|
|
36
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/utilities/updateOptions
|
|
36
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/utilities/updateOptions
|
|
37
37
|
* @returns {void} - Nothing.
|
|
38
38
|
* @throws {XpFatal} If an invalid option is provided.
|
|
39
39
|
*/
|
|
@@ -4,16 +4,14 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param {number} value.
|
|
6
6
|
* @param {"xp" | "level"} type - Type to convert from (Default: level).
|
|
7
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/utilities/convert
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/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
|
-
*/
|
|
11
|
-
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"})}
|
|
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"})}
|
|
12
11
|
/**
|
|
13
12
|
* Updates the options of the XP client.
|
|
14
13
|
* @param {NewClientOptions} clientOptions - The new options to update.
|
|
15
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/utilities/updateOptions
|
|
14
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/utilities/updateOptions
|
|
16
15
|
* @returns {void} - Nothing.
|
|
17
16
|
* @throws {XpFatal} If an invalid option is provided.
|
|
18
|
-
*/
|
|
19
|
-
function updateOptions(clientOptions){if(!clientOptions)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options were not provided"});if("object"!=typeof clientOptions)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options must be an object"});if(xp_1.xp.auto_create=clientOptions.auto_create,xp_1.xp.auto_purge=clientOptions.auto_purge,xp_1.xp.notify=clientOptions.notify,xp_1.xp.debug=clientOptions.debug,clientOptions.dbOptions&&"object"==typeof clientOptions.dbOptions&&clientOptions.dbOptions.type&&clientOptions.dbOptions.database){var{type:clientOptions,database:t}=clientOptions.dbOptions;if(!(clientOptions&&"mongodb"===clientOptions||"sqlite"===clientOptions))throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid database type provided"});xp_1.xp.dbType=clientOptions,t&&(xp_1.xp.database=t,"mongodb"===xp_1.xp.dbType?(0,connect_1.checkPackageVersion)("mongodb").then(result=>{if(!result)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"MongoDB V4 or higher is required"});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"})})}):"sqlite"===xp_1.xp.dbType&&(0,connect_1.checkPackageVersion)("sqlite").then(result=>{if(!result)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"SQLite V7 or higher is required"});try{xp_1.xp.database.prepare("SELECT 1").get()}catch(t){throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid SQLite connection"})}}))}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateOptions=exports.convertFrom=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp"),connect_1=require("../connect");exports.convertFrom=convertFrom,exports.updateOptions=updateOptions;
|
|
17
|
+
*/function updateOptions(clientOptions){if(!clientOptions)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options were not provided"});if("object"!=typeof clientOptions)throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Options must be an object"});if(xp_1.xp.auto_create=clientOptions.auto_create,xp_1.xp.auto_purge=clientOptions.auto_purge,xp_1.xp.notify=clientOptions.notify,xp_1.xp.debug=clientOptions.debug,clientOptions.dbOptions&&"object"==typeof clientOptions.dbOptions&&clientOptions.dbOptions.type&&clientOptions.dbOptions.database){var{type:clientOptions,database:t}=clientOptions.dbOptions;if(!(clientOptions&&"mongodb"===clientOptions||"sqlite"===clientOptions))throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid database type provided"});if(xp_1.xp.dbType=clientOptions,t){xp_1.xp.database=t;const e="mongodb"===xp_1.xp.dbType?{name:"MongoDB",type:"mongodb",min:4,max:6}:{name:"Better-SQLite3",type:"better-sqlite3",min:7,max:9};(0,connect_1.checkPackageVersion)(e.type,e.min,e.max).then(result=>{if(!result)throw new xplogs_1.XpFatal({function:"updateOptions()",message:`${e.name} V${e.min} up to V${e.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(t){throw new xplogs_1.XpFatal({function:"updateOptions()",message:"Invalid SQLite connection"})}}})}}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateOptions=exports.convertFrom=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp"),connect_1=require("../connect");exports.convertFrom=convertFrom,exports.updateOptions=updateOptions;
|
package/lib/src/leaderboard.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface User {
|
|
|
11
11
|
guild: string;
|
|
12
12
|
user: string;
|
|
13
13
|
name?: string | null;
|
|
14
|
-
position
|
|
14
|
+
position: number;
|
|
15
15
|
level: number;
|
|
16
16
|
xp: number;
|
|
17
17
|
}
|
|
@@ -20,7 +20,7 @@ export interface User {
|
|
|
20
20
|
* @async
|
|
21
21
|
* @param {string} guildId - Guild ID
|
|
22
22
|
* @param {number} limit - Limit of users to return
|
|
23
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/leaderboard
|
|
23
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/leaderboard
|
|
24
24
|
* @returns {Promise<User[]>} Array of all users in the leaderboard
|
|
25
25
|
* @throws {XpFatal} If guild ID is not provided or limit is less than 1
|
|
26
26
|
*/
|
package/lib/src/leaderboard.js
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} guildId - Guild ID
|
|
6
6
|
* @param {number} limit - Limit of users to return
|
|
7
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/leaderboard
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/leaderboard
|
|
8
8
|
* @returns {Promise<User[]>} Array of all users in the leaderboard
|
|
9
9
|
* @throws {XpFatal} If guild ID is not provided or limit is less than 1
|
|
10
|
-
*/
|
|
11
|
-
async function leaderboard(guildId,limit){if(!guildId)throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Guild ID was not provided"});if(limit&&limit<1)throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Limit must be greater than 0"});guildId=(await database_1.db.find({collection:"simply-xps",data:{guild:guildId}})).sort((a,b)=>b.xp-a.xp);return guildId.forEach((user,index)=>user.position=index+1),limit?guildId.slice(0,limit):guildId}Object.defineProperty(exports,"__esModule",{value:!0}),exports.leaderboard=void 0;const xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database");exports.leaderboard=leaderboard;
|
|
10
|
+
*/async function leaderboard(guildId,limit){if(!guildId)throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Guild ID was not provided"});if(!limit||1<=limit)return guildId=(await database_1.db.find({collection:"simply-xps",data:{guild:guildId}})).sort((a,b)=>b.xp-a.xp),await Promise.all(guildId.map(async(user,index)=>(user.position=index+1,user))),guildId.slice(0,limit);throw new xplogs_1.XpFatal({function:"leaderboard()",message:"Limit must be a number greater than 0"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.leaderboard=void 0;const xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database");exports.leaderboard=leaderboard;
|
package/lib/src/migrate.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class migrate {
|
|
|
9
9
|
* Effortlessly migrate from discord-xp to simply-xp.
|
|
10
10
|
* @async
|
|
11
11
|
* @param {boolean} deleteOld - Delete old data after migration
|
|
12
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/migrate
|
|
12
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratediscord_xp
|
|
13
13
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
14
14
|
* @throws {XpLog.err} - If migration fails.
|
|
15
15
|
*/
|
|
@@ -19,7 +19,7 @@ export declare class migrate {
|
|
|
19
19
|
* @async
|
|
20
20
|
* @param {"mongodb"|"sqlite"} dbType
|
|
21
21
|
* @param {Database | MongoClient} connection
|
|
22
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/migrate
|
|
22
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratefromdb
|
|
23
23
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
24
24
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
25
25
|
*/
|
package/lib/src/migrate.js
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
* Effortlessly migrate from discord-xp to simply-xp.
|
|
4
4
|
* @async
|
|
5
5
|
* @param {boolean} deleteOld - Delete old data after migration
|
|
6
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/migrate
|
|
6
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratediscord_xp
|
|
7
7
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
8
8
|
* @throws {XpLog.err} - If migration fails.
|
|
9
9
|
*/
|
|
10
|
-
static async discord_xp(deleteOld=!1){var e=await database_1.db.getCollection("levels").find().toArray();xplogs_1.XpLog.debug("migrate.discord_xp()",`FOUND ${e.length} DOCUMENTS`);try{for(const
|
|
10
|
+
static async discord_xp(deleteOld=!1){var e=await database_1.db.getCollection("levels").find().toArray();xplogs_1.XpLog.debug("migrate.discord_xp()",`FOUND ${e.length} DOCUMENTS`);try{for(const a of e)await database_1.db.findOne({collection:"simply-xps",data:{guild:a.guildID,user:a.userID}})||(await database_1.db.createOne({collection:"simply-xps",data:{guild:a.guildID,user:a.userID,xp:a.xp,level:(0,xp_1.convertFrom)(a.xp,"xp")}}),deleteOld&&await database_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}}
|
|
11
11
|
/**
|
|
12
12
|
* Effortlessly migrate from MongoDB to SQLite. (or vice versa)
|
|
13
13
|
* @async
|
|
14
14
|
* @param {"mongodb"|"sqlite"} dbType
|
|
15
15
|
* @param {Database | MongoClient} connection
|
|
16
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/migrate
|
|
16
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/migrate#migratefromdb
|
|
17
17
|
* @returns {Promise<boolean>} - Returns true if migration is successful
|
|
18
18
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
19
|
-
*/static async fromDB(dbType,connection){if(!dbType)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database type provided"});if(!connection)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database connection provided"});if(xp_1.xp.dbType===dbType)return xplogs_1.XpLog.info("migrate.fromDB()","Same database received, that was unnecessary!");switch(dbType){case"mongodb":try{if(!await(0,connect_1.checkPackageVersion)("mongodb"))return xplogs_1.XpLog.err("migrate.fromDB()","MongoDB V4
|
|
19
|
+
*/static async fromDB(dbType,connection){if(!dbType)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database type provided"});if(!connection)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database connection provided"});if(xp_1.xp.dbType===dbType)return xplogs_1.XpLog.info("migrate.fromDB()","Same database received, that was unnecessary!");let e;switch(dbType){case"mongodb":try{if(!await(0,connect_1.checkPackageVersion)("mongodb",4,6))return xplogs_1.XpLog.err("migrate.fromDB()","MongoDB V4 up to V6 is required");e=await connection.db().collection("simply-xps").find().toArray()}catch(e){return xplogs_1.XpLog.err("migrate.fromDB()",e),!1}break;case"sqlite":try{if(!await(0,connect_1.checkPackageVersion)("better-sqlite3",7,8))return xplogs_1.XpLog.err("migrate.fromDB()","better-sqlite3 V7 up to V8 is required");e=connection.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 ${e.length} RESULTS`),await Promise.all(e.map(async user=>await database_1.db.findOne({collection:"simply-xps",data:{guild:user.guild,user:user.user}})?database_1.db.updateOne({collection:"simply-xps",data:{guild:user.guild,user:user.user}},{collection:"simply-xps",data:{guild:user.guild,user:user.user,name:user.name,xp:user.xp,level:user.level}}):database_1.db.createOne({collection:"simply-xps",data:{guild:user.guild,user:user.user,xp:user.xp,level:user.level}}))),!0}}exports.migrate=migrate;
|
package/lib/src/reset.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @param {string} guildId
|
|
6
6
|
* @param {boolean?} erase - Erase user entry from the database
|
|
7
7
|
* @param {string?} username - Username to use if auto_create is enabled
|
|
8
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/reset
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/reset
|
|
9
9
|
* @returns {Promise<boolean>}
|
|
10
10
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
11
11
|
*/
|
package/lib/src/reset.js
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {boolean?} erase - Erase user entry from the database
|
|
8
8
|
* @param {string?} username - Username to use if auto_create is enabled
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/reset
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/reset
|
|
10
10
|
* @returns {Promise<boolean>}
|
|
11
11
|
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
12
|
-
*/
|
|
13
|
-
async function reset(userId,guildId,erase=!1,username){var e;if(userId&&guildId)return e={guild:guildId,user:userId},await database_1.db.findOne({collection:"simply-xps",data:e})?(erase?await database_1.db.deleteOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{...e,level:0,xp:0}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}),!0):xp_1.xp.auto_create&&!erase&&username?(await database_1.db.createOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error.stack})}),!0):xplogs_1.XpLog.info("reset()","User was not found, we did not know what to do without a username.");throw new xplogs_1.XpFatal({function:"reset()",message:"Invalid parameters provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.reset=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp"),database_1=require("./functions/database");exports.reset=reset;
|
|
12
|
+
*/async function reset(userId,guildId,erase=!1,username){var e;if(userId&&guildId)return e={guild:guildId,user:userId},await database_1.db.findOne({collection:"simply-xps",data:e})?(erase?await database_1.db.deleteOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):await database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{...e,level:0,xp:0}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}),!0):xp_1.xp.auto_create&&!erase&&username?(await database_1.db.createOne({collection:"simply-xps",data:e}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error.stack})}),!0):xplogs_1.XpLog.info("reset()","User was not found, we did not know what to do without a username.");throw new xplogs_1.XpFatal({function:"reset()",message:"Invalid parameters provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.reset=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp"),database_1=require("./functions/database");exports.reset=reset;
|
package/lib/src/roleSetup.d.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @property {string[] | string} roles - The role(s) to add
|
|
6
6
|
*/
|
|
7
7
|
export interface RoleSetupObject {
|
|
8
|
-
guild?: string;
|
|
9
8
|
level: number;
|
|
10
9
|
roles: string[] | string;
|
|
11
10
|
}
|
|
@@ -19,7 +18,7 @@ export declare class roleSetup {
|
|
|
19
18
|
* @async
|
|
20
19
|
* @param {string} guildId - The guild ID
|
|
21
20
|
* @param {RoleSetupObject} options - Level/role options
|
|
22
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
21
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
|
|
23
22
|
* @returns {Promise<boolean>} - True if successful
|
|
24
23
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
25
24
|
*/
|
|
@@ -29,7 +28,7 @@ export declare class roleSetup {
|
|
|
29
28
|
* @async
|
|
30
29
|
* @param {string} guildId - The guild ID
|
|
31
30
|
* @param {number} levelNumber - The level number
|
|
32
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
31
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
|
|
33
32
|
* @returns {Promise<RoleSetupObject>} - The level role object
|
|
34
33
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
35
34
|
*/
|
|
@@ -39,7 +38,7 @@ export declare class roleSetup {
|
|
|
39
38
|
* @async
|
|
40
39
|
* @param {string} guildId - The guild ID
|
|
41
40
|
* @param {number} levelNumber - The level number
|
|
42
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
41
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
|
|
43
42
|
* @returns {Promise<boolean>} - True if successful
|
|
44
43
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
45
44
|
*/
|
package/lib/src/roleSetup.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @async
|
|
5
5
|
* @param {string} guildId - The guild ID
|
|
6
6
|
* @param {RoleSetupObject} options - Level/role options
|
|
7
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupadd
|
|
8
8
|
* @returns {Promise<boolean>} - True if successful
|
|
9
9
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
10
10
|
*/
|
|
@@ -14,7 +14,7 @@ static async add(guildId,options){if(!guildId)throw new xplogs_1.XpFatal({functi
|
|
|
14
14
|
* @async
|
|
15
15
|
* @param {string} guildId - The guild ID
|
|
16
16
|
* @param {number} levelNumber - The level number
|
|
17
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
17
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupfind
|
|
18
18
|
* @returns {Promise<RoleSetupObject>} - The level role object
|
|
19
19
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
20
20
|
*/static async find(guildId,levelNumber){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Guild ID was not provided"});if(isNaN(levelNumber))throw new xplogs_1.XpFatal({function:"roleSetup.find()",message:"Level Number was not provided"});return xp_1.db.findOne({collection:"simply-xp-levelroles",data:{guild:guildId,level:levelNumber,timestamp:(new Date).toISOString()}})}
|
|
@@ -23,7 +23,7 @@ static async add(guildId,options){if(!guildId)throw new xplogs_1.XpFatal({functi
|
|
|
23
23
|
* @async
|
|
24
24
|
* @param {string} guildId - The guild ID
|
|
25
25
|
* @param {number} levelNumber - The level number
|
|
26
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup
|
|
26
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/classes/roleSetup#roleSetupremove
|
|
27
27
|
* @returns {Promise<boolean>} - True if successful
|
|
28
28
|
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
29
29
|
*/static async remove(guildId,levelNumber){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Guild ID was not provided"});if(isNaN(levelNumber))throw new xplogs_1.XpFatal({function:"roleSetup.remove()",message:"Level Number was not provided"});return xp_1.db.deleteOne({collection:"simply-xp-levelroles",data:{guild:guildId,level:levelNumber,timestamp:(new Date).toISOString()}})}}exports.roleSetup=roleSetup;
|
package/lib/src/set.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { UserResult } from "./functions/database";
|
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {number} level
|
|
8
8
|
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/setlevel
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setlevel
|
|
10
10
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
11
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
12
|
*/
|
|
@@ -25,7 +25,7 @@ interface XPResult extends UserResult {
|
|
|
25
25
|
* @param {string} guildId
|
|
26
26
|
* @param {number} xpData
|
|
27
27
|
* @param {string} username - Username to use if auto_create is enabled
|
|
28
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/setxp
|
|
28
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setxp
|
|
29
29
|
* @returns {Promise<XPResult>} - Object of user data on success
|
|
30
30
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
31
31
|
*/
|
package/lib/src/set.js
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* @param {string} guildId
|
|
7
7
|
* @param {number} level
|
|
8
8
|
* @param {string} username - Username to use if auto_create is enabled
|
|
9
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/setlevel
|
|
9
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setlevel
|
|
10
10
|
* @returns {Promise<UserResult>} - Object of user data on success
|
|
11
11
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
12
|
-
*/
|
|
13
|
-
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"})}
|
|
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"})}
|
|
14
13
|
/**
|
|
15
14
|
* Set user XP
|
|
16
15
|
* @async
|
|
@@ -18,8 +17,7 @@ async function setLevel(userId,guildId,level,username){if(!userId)throw new xplo
|
|
|
18
17
|
* @param {string} guildId
|
|
19
18
|
* @param {number} xpData
|
|
20
19
|
* @param {string} username - Username to use if auto_create is enabled
|
|
21
|
-
* @link `Documentation:` https://simplyxp.js.org/docs/setxp
|
|
20
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/next/functions/setxp
|
|
22
21
|
* @returns {Promise<XPResult>} - Object of user data on success
|
|
23
22
|
* @throws {XpFatal} - If parameters are not provided correctly
|
|
24
|
-
*/
|
|
25
|
-
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;
|
|
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/lib/xp.d.ts
CHANGED
|
@@ -11,13 +11,13 @@ export interface XPClient {
|
|
|
11
11
|
export { addLevel, addXP } from "./src/add";
|
|
12
12
|
export { db } from "./src/functions/database";
|
|
13
13
|
export { charts } from "./src/charts";
|
|
14
|
+
export { compareCard, leaderboardCard, rankCard } from "./src/cards";
|
|
14
15
|
export { connect } from "./src/connect";
|
|
15
16
|
export { convertFrom, updateOptions } from "./src/functions/utilities";
|
|
16
17
|
export { create } from "./src/create";
|
|
17
18
|
export { fetch } from "./src/fetch";
|
|
18
19
|
export { leaderboard } from "./src/leaderboard";
|
|
19
20
|
export { migrate } from "./src/migrate";
|
|
20
|
-
export { rankCard, leaderboardCard } from "./src/cards";
|
|
21
21
|
export { reset } from "./src/reset";
|
|
22
22
|
export { roleSetup } from "./src/roleSetup";
|
|
23
23
|
export { setLevel, setXP } from "./src/set";
|
package/lib/xp.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rank = exports.xp = exports.setXP = exports.setLevel = exports.roleSetup = exports.reset = exports.
|
|
3
|
+
exports.rank = exports.xp = exports.setXP = exports.setLevel = exports.roleSetup = exports.reset = exports.migrate = exports.leaderboard = exports.fetch = exports.create = exports.updateOptions = exports.convertFrom = exports.connect = exports.rankCard = exports.leaderboardCard = exports.compareCard = exports.charts = exports.db = exports.addXP = exports.addLevel = void 0;
|
|
4
4
|
// EXPORTS
|
|
5
5
|
var add_1 = require("./src/add");
|
|
6
6
|
Object.defineProperty(exports, "addLevel", { enumerable: true, get: function () { return add_1.addLevel; } });
|
|
@@ -9,6 +9,10 @@ var database_1 = require("./src/functions/database");
|
|
|
9
9
|
Object.defineProperty(exports, "db", { enumerable: true, get: function () { return database_1.db; } });
|
|
10
10
|
var charts_1 = require("./src/charts");
|
|
11
11
|
Object.defineProperty(exports, "charts", { enumerable: true, get: function () { return charts_1.charts; } });
|
|
12
|
+
var cards_1 = require("./src/cards");
|
|
13
|
+
Object.defineProperty(exports, "compareCard", { enumerable: true, get: function () { return cards_1.compareCard; } });
|
|
14
|
+
Object.defineProperty(exports, "leaderboardCard", { enumerable: true, get: function () { return cards_1.leaderboardCard; } });
|
|
15
|
+
Object.defineProperty(exports, "rankCard", { enumerable: true, get: function () { return cards_1.rankCard; } });
|
|
12
16
|
var connect_1 = require("./src/connect");
|
|
13
17
|
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connect_1.connect; } });
|
|
14
18
|
var utilities_1 = require("./src/functions/utilities");
|
|
@@ -22,9 +26,6 @@ var leaderboard_1 = require("./src/leaderboard");
|
|
|
22
26
|
Object.defineProperty(exports, "leaderboard", { enumerable: true, get: function () { return leaderboard_1.leaderboard; } });
|
|
23
27
|
var migrate_1 = require("./src/migrate");
|
|
24
28
|
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migrate_1.migrate; } });
|
|
25
|
-
var cards_1 = require("./src/cards");
|
|
26
|
-
Object.defineProperty(exports, "rankCard", { enumerable: true, get: function () { return cards_1.rankCard; } });
|
|
27
|
-
Object.defineProperty(exports, "leaderboardCard", { enumerable: true, get: function () { return cards_1.leaderboardCard; } });
|
|
28
29
|
var reset_1 = require("./src/reset");
|
|
29
30
|
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
|
|
30
31
|
var roleSetup_1 = require("./src/roleSetup");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simply-xp",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.5",
|
|
4
4
|
"description": "The easiest way to implement xp system",
|
|
5
5
|
"main": "lib/xp.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"author": "Abadima",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"amaribot",
|
|
17
|
+
"canvacord",
|
|
17
18
|
"charts",
|
|
19
|
+
"compare",
|
|
20
|
+
"compete",
|
|
18
21
|
"discord",
|
|
19
22
|
"discord.js",
|
|
20
23
|
"discord-xp",
|
|
@@ -22,14 +25,15 @@
|
|
|
22
25
|
"fun",
|
|
23
26
|
"guilded",
|
|
24
27
|
"leaderboard",
|
|
25
|
-
"level
|
|
26
|
-
"
|
|
28
|
+
"level",
|
|
29
|
+
"leveling",
|
|
27
30
|
"mee6",
|
|
28
31
|
"mongodb",
|
|
29
32
|
"package",
|
|
30
33
|
"simply",
|
|
31
34
|
"simply-djs",
|
|
32
35
|
"simplydjs",
|
|
36
|
+
"slack",
|
|
33
37
|
"sqlite",
|
|
34
38
|
"system",
|
|
35
39
|
"xp"
|
|
@@ -37,33 +41,32 @@
|
|
|
37
41
|
"license": "Apache-2.0",
|
|
38
42
|
"repository": {
|
|
39
43
|
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/
|
|
44
|
+
"url": "git+https://github.com/Abadima/simply-xp.git"
|
|
41
45
|
},
|
|
42
46
|
"dependencies": {
|
|
43
|
-
"@napi-rs/canvas": "^0.1.
|
|
47
|
+
"@napi-rs/canvas": "^0.1.44"
|
|
44
48
|
},
|
|
45
49
|
"devDependencies": {
|
|
46
|
-
"@types/better-sqlite3": "^7.6.
|
|
47
|
-
"@types/node": "^20.
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
49
|
-
"@typescript-eslint/parser": "^6.
|
|
50
|
-
"better-sqlite3": "
|
|
51
|
-
"discord.js": "^14.
|
|
52
|
-
"eslint": "^8.
|
|
50
|
+
"@types/better-sqlite3": "^7.6.5",
|
|
51
|
+
"@types/node": "^20.8.6",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
53
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
54
|
+
"better-sqlite3": "^9.0.0",
|
|
55
|
+
"discord.js": "^14.13.0",
|
|
56
|
+
"eslint": "^8.51.0",
|
|
53
57
|
"jsdoc-to-markdown": "^8.0.0",
|
|
54
|
-
"mongodb": "^
|
|
55
|
-
"typescript": "^5.
|
|
58
|
+
"mongodb": "^6.1.0",
|
|
59
|
+
"typescript": "^5.2.2",
|
|
56
60
|
"uglify-js": "^3.17.4"
|
|
57
61
|
},
|
|
58
62
|
"engines": {
|
|
59
63
|
"node": ">=15.5.0"
|
|
60
64
|
},
|
|
61
65
|
"bugs": {
|
|
62
|
-
"url": "https://github.com/
|
|
66
|
+
"url": "https://github.com/Abadima/simply-xp/issues"
|
|
63
67
|
},
|
|
64
68
|
"homepage": "https://simplyxp.js.org",
|
|
65
69
|
"directories": {
|
|
66
|
-
"doc": "Mini_Docs",
|
|
67
70
|
"lib": "lib"
|
|
68
71
|
}
|
|
69
72
|
}
|
|
Binary file
|