simply-xp 1.3.5-beta-7 → 2.0.0-dev.1

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.
Files changed (65) hide show
  1. package/FUNDING.yml +2 -2
  2. package/README.md +69 -57
  3. package/lib/src/add.d.ts +28 -0
  4. package/lib/src/add.js +23 -0
  5. package/lib/src/cards.d.ts +91 -0
  6. package/lib/src/cards.js +23 -0
  7. package/lib/src/charts.d.ts +17 -0
  8. package/lib/src/charts.js +10 -0
  9. package/lib/src/connect.d.ts +26 -0
  10. package/lib/src/connect.js +47 -0
  11. package/lib/src/create.d.ts +12 -0
  12. package/lib/src/create.js +11 -0
  13. package/lib/src/deprecated/rank.d.ts +18 -0
  14. package/lib/src/deprecated/rank.js +12 -0
  15. package/lib/src/fetch.d.ts +12 -0
  16. package/lib/src/fetch.js +11 -0
  17. package/lib/src/functions/database.d.ts +111 -0
  18. package/lib/src/functions/database.js +56 -0
  19. package/lib/src/functions/utilities.d.ts +41 -0
  20. package/lib/src/functions/utilities.js +17 -0
  21. package/lib/src/functions/xplogs.d.ts +59 -0
  22. package/lib/src/functions/xplogs.js +1 -0
  23. package/lib/src/leaderboard.d.ts +27 -0
  24. package/lib/src/leaderboard.js +10 -0
  25. package/lib/src/migrate.d.ts +25 -0
  26. package/lib/src/migrate.js +19 -0
  27. package/lib/src/reset.d.ts +12 -0
  28. package/lib/src/reset.js +12 -0
  29. package/lib/src/roleSetup.d.ts +47 -0
  30. package/lib/src/roleSetup.js +29 -0
  31. package/lib/src/set.d.ts +25 -0
  32. package/lib/src/set.js +23 -0
  33. package/lib/xp.d.ts +25 -0
  34. package/lib/xp.js +45 -0
  35. package/package.json +70 -53
  36. package/.eslintrc.json +0 -29
  37. package/.github/CODE_OF_CONDUCT.md +0 -128
  38. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  39. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  40. package/.github/SECURITY.md +0 -25
  41. package/.github/pull_request_template.md +0 -8
  42. package/.github/workflows/codeql-analysis.yml +0 -71
  43. package/.idea/discord.xml +0 -7
  44. package/.idea/misc.xml +0 -6
  45. package/.idea/modules.xml +0 -8
  46. package/.idea/simply-xp.iml +0 -9
  47. package/.idea/vcs.xml +0 -6
  48. package/index.d.ts +0 -107
  49. package/simplyxp.js +0 -31
  50. package/src/addLevel.js +0 -66
  51. package/src/addXP.js +0 -104
  52. package/src/charts.js +0 -92
  53. package/src/connect.js +0 -22
  54. package/src/create.js +0 -28
  55. package/src/fetch.js +0 -74
  56. package/src/leaderboard.js +0 -52
  57. package/src/lvlRole.js +0 -53
  58. package/src/models/level.js +0 -10
  59. package/src/models/lvlrole.js +0 -8
  60. package/src/rank.js +0 -295
  61. package/src/reset.js +0 -22
  62. package/src/roleSetup.js +0 -121
  63. package/src/setLevel.js +0 -70
  64. package/src/setXP.js +0 -51
  65. /package/{src → lib/src}/Fonts/Baloo-Regular.ttf +0 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Options for creating a user document.
3
+ * @property {string} collection - The collection to create the document in.
4
+ * @property {object} data - The data to create the document with.
5
+ * @property {string} data.guild - The guild ID.
6
+ * @property {string} [data.user] - The user ID.
7
+ * @property {string} [data.name] - The username.
8
+ * @property {number} [data.level] - The level.
9
+ * @property {number} [data.xp] - The XP.
10
+ */
11
+ export interface UserOptions {
12
+ collection: "simply-xps";
13
+ data: {
14
+ guild: string;
15
+ user?: string;
16
+ name?: string;
17
+ level?: number;
18
+ xp?: number;
19
+ };
20
+ }
21
+ export type UserResult = {
22
+ _id?: string;
23
+ user: string;
24
+ name?: string;
25
+ guild: string;
26
+ level: number;
27
+ xp: number;
28
+ };
29
+ /**
30
+ * Options for creating a level role document.
31
+ * @property {string} collection - The collection to create the document in.
32
+ * @property {object} data - The data to create the document with.
33
+ * @property {string} data.guild - The guild ID.
34
+ * @property {number} [data.level] - The level to assign the role at.
35
+ * @property {string | Array<string>} [data.roles] - The role(s) to assign.
36
+ * @property {string} data.timestamp - The timestamp of when the document was created.
37
+ */
38
+ export interface LevelRoleOptions {
39
+ collection: "simply-xp-levelroles";
40
+ data: {
41
+ guild: string;
42
+ level?: number;
43
+ roles?: string | Array<string>;
44
+ timestamp: string;
45
+ };
46
+ }
47
+ export type LevelRoleResult = {
48
+ _id?: string;
49
+ guild: string;
50
+ level: number;
51
+ roles: Array<string>;
52
+ timestamp: string;
53
+ };
54
+ /**
55
+ * Database class providing methods to interact with the database.
56
+ * @class db
57
+ */
58
+ export declare class db {
59
+ /**
60
+ * Creates one document in the database.
61
+ *
62
+ * @async
63
+ * @param {UserOptions | LevelRoleOptions} query - The document to create.
64
+ * @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
65
+ * @returns {Promise<UserResult | LevelRoleResult>} The created document.
66
+ * @throws {XpFatal} Throws an error if there is no database connection.
67
+ */
68
+ static createOne(query: UserOptions | LevelRoleOptions): Promise<UserResult | LevelRoleResult>;
69
+ /**
70
+ * Deletes one document from the database.
71
+ *
72
+ * @async
73
+ * @param {UserOptions | LevelRoleOptions} query - The document to delete.
74
+ * @link https://simplyxp.js.org/docs/handlers/database#deleteOne Documentation
75
+ * @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
76
+ * @throws {XpFatal} Throws an error if there is no database connection.
77
+ */
78
+ static deleteOne(query: UserOptions | LevelRoleOptions): Promise<boolean>;
79
+ /**
80
+ * Finds one document in the database.
81
+ *
82
+ * @async
83
+ * @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
84
+ * @link https://simplyxp.js.org/docs/handlers/database#findOne Documentation
85
+ * @returns {Promise<UserResult | LevelRoleResult>} The found document.
86
+ * @throws {XpFatal} Throws an error if there is no database connection.
87
+ */
88
+ static findOne(query: UserOptions | LevelRoleOptions): Promise<UserResult | LevelRoleResult>;
89
+ /**
90
+ * Finds multiple documents in the database.
91
+ *
92
+ * @async
93
+ * @param {UserOptions | LevelRoleOptions} query - The query to search for multiple documents.
94
+ * @link https://simplyxp.js.org/docs/handlers/database#find Documentation
95
+ * @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
96
+ * @throws {XpFatal} Throws an error if there is no database connection.
97
+ */
98
+ static find(query: UserOptions | LevelRoleOptions): Promise<UserResult[] | LevelRoleResult[]>;
99
+ /**
100
+ * Updates one document in the database.
101
+ *
102
+ * @async
103
+ * @param {UserOptions | LevelRoleOptions} filter - The document to update.
104
+ * @param {UserOptions | LevelRoleOptions} update - The document update data.
105
+ * @param {object} [options] - MongoDB options for updating the document.
106
+ * @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
107
+ * @returns {Promise<UserResult | LevelRoleResult>} The updated document.
108
+ * @throws {XpFatal} Throws an error if there is no database connection.
109
+ */
110
+ static updateOne(filter: UserOptions | LevelRoleOptions, update: UserOptions | LevelRoleOptions, options?: object): Promise<UserResult | LevelRoleResult>;
111
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * Handle database errors
4
+ * @param {Error} error
5
+ * @param {string} functionName
6
+ * @returns {void}
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{
9
+ /**
10
+ * Creates one document in the database.
11
+ *
12
+ * @async
13
+ * @param {UserOptions | LevelRoleOptions} query - The document to create.
14
+ * @link https://simplyxp.js.org/docs/handlers/database#createOne Documentation
15
+ * @returns {Promise<UserResult | LevelRoleResult>} The created document.
16
+ * @throws {XpFatal} Throws an error if there is no database connection.
17
+ */
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
+ /**
20
+ * Deletes one document from the database.
21
+ *
22
+ * @async
23
+ * @param {UserOptions | LevelRoleOptions} query - The document to delete.
24
+ * @link https://simplyxp.js.org/docs/handlers/database#deleteOne Documentation
25
+ * @returns {Promise<boolean>} `true` if the document was successfully deleted, otherwise `false`.
26
+ * @throws {XpFatal} Throws an error if there is no database connection.
27
+ */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}
28
+ /**
29
+ * Finds one document in the database.
30
+ *
31
+ * @async
32
+ * @param {UserOptions | LevelRoleOptions} query - The query to search for the document.
33
+ * @link https://simplyxp.js.org/docs/handlers/database#findOne Documentation
34
+ * @returns {Promise<UserResult | LevelRoleResult>} The found document.
35
+ * @throws {XpFatal} Throws an error if there is no database connection.
36
+ */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}
37
+ /**
38
+ * Finds multiple documents in the database.
39
+ *
40
+ * @async
41
+ * @param {UserOptions | LevelRoleOptions} query - The query to search for multiple documents.
42
+ * @link https://simplyxp.js.org/docs/handlers/database#find Documentation
43
+ * @returns {Promise<UserResult[] | LevelRoleResult[]>} An array of found documents.
44
+ * @throws {XpFatal} Throws an error if there is no database connection.
45
+ */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}
46
+ /**
47
+ * Updates one document in the database.
48
+ *
49
+ * @async
50
+ * @param {UserOptions | LevelRoleOptions} filter - The document to update.
51
+ * @param {UserOptions | LevelRoleOptions} update - The document update data.
52
+ * @param {object} [options] - MongoDB options for updating the document.
53
+ * @link https://simplyxp.js.org/docs/handlers/database#updateOne Documentation
54
+ * @returns {Promise<UserResult | LevelRoleResult>} The updated document.
55
+ * @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;
@@ -0,0 +1,41 @@
1
+ import { MongoClient } from "mongodb";
2
+ import { Database } from "better-sqlite3";
3
+ /**
4
+ * Options for the XP client.
5
+ * @property {boolean} auto_create - Whether to automatically create a user if they don't exist in the database.
6
+ * @property {boolean} auto_purge - Whether to automatically purge inactive users.
7
+ * @property {object} dbOptions - The database options.
8
+ * @property {"mongodb" | "sqlite"} dbOptions.type
9
+ * @property {MongoClient | Database} dbOptions.database
10
+ * @property {boolean} notify - Enable/Disable console notifications.
11
+ * @property {boolean} debug - Whether to enable debug logs.
12
+ */
13
+ interface NewClientOptions {
14
+ auto_create: boolean;
15
+ auto_purge: boolean;
16
+ dbOptions: {
17
+ type: "mongodb" | "sqlite";
18
+ database: MongoClient | Database;
19
+ };
20
+ notify: boolean;
21
+ debug: boolean;
22
+ }
23
+ /**
24
+ * Convert XP to level and vice versa.
25
+ *
26
+ * @param {"xp" | "level"} type - Type to coreFunctions from. Use either "xp" or "level".
27
+ * @param {number} value - Value to coreFunctions.
28
+ * @link `Documentation:` https://simplyxp.js.org/docs/convert
29
+ * @returns {number} - The converted value. (XP to level or level to XP)
30
+ * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
31
+ */
32
+ export declare function convert(type: "xp" | "level", value: number): number;
33
+ /**
34
+ * Updates the options of the XP client.
35
+ * @param {NewClientOptions} clientOptions - The new options to update.
36
+ * @link `Documentation:` https://simplyxp.js.org/docs/updateOptions
37
+ * @returns {void} - Nothing.
38
+ * @throws {XpFatal} If an invalid option is provided.
39
+ */
40
+ export declare function updateOptions(clientOptions: NewClientOptions): void;
41
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Convert XP to level and vice versa.
4
+ *
5
+ * @param {"xp" | "level"} type - Type to coreFunctions from. Use either "xp" or "level".
6
+ * @param {number} value - Value to coreFunctions.
7
+ * @link `Documentation:` https://simplyxp.js.org/docs/convert
8
+ * @returns {number} - The converted value. (XP to level or level to XP)
9
+ * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
10
+ */function convert(type,value){if("xp"!==type&&"level"!==type)throw new xplogs_1.XpFatal({function:"convert()",message:"Invalid type provided"});if(!value)throw new xplogs_1.XpFatal({function:"coreFunctions()",message:"Value was not 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:"coreFunctions()",message:"Invalid type provided"})}
11
+ /**
12
+ * Updates the options of the XP client.
13
+ * @param {NewClientOptions} clientOptions - The new options to update.
14
+ * @link `Documentation:` https://simplyxp.js.org/docs/updateOptions
15
+ * @returns {void} - Nothing.
16
+ * @throws {XpFatal} If an invalid option is provided.
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"});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.convert=void 0;const xplogs_1=require("./xplogs"),xp_1=require("../../xp"),connect_1=require("../connect");exports.convert=convert,exports.updateOptions=updateOptions;
@@ -0,0 +1,59 @@
1
+ type errOptions = {
2
+ function: string;
3
+ message: string | Error;
4
+ };
5
+ /**
6
+ * Emits a fatal error message
7
+ * @class XpFatal
8
+ */
9
+ export declare class XpFatal extends Error {
10
+ /**
11
+ * Emits a simple error message
12
+ * @param {errOptions} options
13
+ * @private
14
+ */
15
+ constructor(options: errOptions);
16
+ }
17
+ /**
18
+ * Emits a log message
19
+ * @class XpLog
20
+ */
21
+ export declare class XpLog {
22
+ /**
23
+ * Emits a log message with the specified level
24
+ * @param {("debug" | "error" | "info" | "warn")} level - The log level (e.g., 'info', 'error', 'warn')
25
+ * @param {string} command - The command or context of the log message
26
+ * @param {string} message - The log message
27
+ * @private
28
+ */
29
+ static log(level: ("debug" | "error" | "info" | "warn"), command: string, message: string): void;
30
+ /**
31
+ * Emits a debug log
32
+ * @param {string} command - The command or context of the log message
33
+ * @param {string} message - The log message
34
+ * @private
35
+ */
36
+ static debug(command: string, message: string): void;
37
+ /**
38
+ * Emits an info log
39
+ * @param {string} command - The command or context of the log message
40
+ * @param {string} message - The log message
41
+ * @private
42
+ */
43
+ static info(command: string, message: string): void;
44
+ /**
45
+ * Emits an error log
46
+ * @param {string} command - The command or context of the log message
47
+ * @param {string} message - The log message
48
+ * @private
49
+ */
50
+ static err(command: string, message: string): void;
51
+ /**
52
+ * Emits a warning log
53
+ * @param {string} command - The command or context of the log message
54
+ * @param {string} message - The log message
55
+ * @private
56
+ */
57
+ static warn(command: string, message: string): void;
58
+ }
59
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.XpLog=exports.XpFatal=void 0;const xp_1=require("../../xp");class XpFatal extends Error{constructor(options){super(options.function+": "+options.message)}}exports.XpFatal=XpFatal,Object.defineProperty(XpFatal.prototype,"name",{value:"SimplyXpFatal"});class XpLog{static log(level,command,message){var e=level.toUpperCase(),command=command.toUpperCase();console.log(`[SIMPLY XP] ${{debug:"",info:"",error:"",warn:""}[level]}(${e}) ${command}: `+message)}static debug(command,message){xp_1.xp.debug&&XpLog.log("debug",command,message)}static info(command,message){xp_1.xp.notify&&XpLog.log("info",command,message)}static err(command,message){XpLog.log("error",command,message)}static warn(command,message){XpLog.log("warn",command,message)}}exports.XpLog=XpLog;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * User object
3
+ * @property {string} guild - Guild ID
4
+ * @property {string} user - User ID
5
+ * @property {string} name - Username
6
+ * @property {number} position - Position in leaderboard
7
+ * @property {number} level - User level
8
+ * @property {number} xp - User XP
9
+ */
10
+ export interface User {
11
+ guild: string;
12
+ user: string;
13
+ name?: string | null;
14
+ position?: number;
15
+ level: number;
16
+ xp: number;
17
+ }
18
+ /**
19
+ * Get array of all users in the leaderboard
20
+ * @async
21
+ * @param {string} guildId - Guild ID
22
+ * @param {number} limit - Limit of users to return
23
+ * @link `Documentation:` https://simplyxp.js.org/docs/leaderboard
24
+ * @returns {Promise<User[]>} Array of all users in the leaderboard
25
+ * @throws {XpFatal} If guild ID is not provided or limit is less than 1
26
+ */
27
+ export declare function leaderboard(guildId: string, limit?: number): Promise<User[]>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * Get array of all users in the leaderboard
4
+ * @async
5
+ * @param {string} guildId - Guild ID
6
+ * @param {number} limit - Limit of users to return
7
+ * @link `Documentation:` https://simplyxp.js.org/docs/leaderboard
8
+ * @returns {Promise<User[]>} Array of all users in the leaderboard
9
+ * @throws {XpFatal} If guild ID is not provided or limit is less than 1
10
+ */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"});return(guildId=(await database_1.db.find({collection:"simply-xps",data:{guild:guildId}})).sort((a,b)=>b.xp-a.xp)).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;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Migration functions
3
+ * @class migrate
4
+ */
5
+ export declare class migrate {
6
+ /**
7
+ * Effortlessly migrate from discord-xp to simply-xp.
8
+ * @async
9
+ * @param {URL} dbUrl - MongoDB URL
10
+ * @param {boolean} deleteOld - Delete old data after migration
11
+ * @link `Documentation:` https://simplyxp.js.org/docs/migrate/discord_xp
12
+ * @returns {Promise<boolean>} - Returns true if migration is successful
13
+ * @throws {XpFatal} - If parameters are not provided correctly
14
+ */
15
+ static discord_xp(dbUrl: URL, deleteOld: boolean): Promise<boolean>;
16
+ /**
17
+ * Effortlessly migrate from MongoDB to SQLite. (or vice versa)
18
+ * @async
19
+ * @param {"mongodb"|"sqlite"} from
20
+ * @link `Documentation:` https://simplyxp.js.org/docs/migrate/database
21
+ * @returns {Promise<boolean>} - Returns true if migration is successful
22
+ * @throws {XpFatal} - If parameters are not provided correctly
23
+ */
24
+ static database(from: "mongodb" | "sqlite"): Promise<void>;
25
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";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.migrate=void 0;const xplogs_1=require("./functions/xplogs"),database_1=require("./functions/database");class migrate{
2
+ /**
3
+ * Effortlessly migrate from discord-xp to simply-xp.
4
+ * @async
5
+ * @param {URL} dbUrl - MongoDB URL
6
+ * @param {boolean} deleteOld - Delete old data after migration
7
+ * @link `Documentation:` https://simplyxp.js.org/docs/migrate/discord_xp
8
+ * @returns {Promise<boolean>} - Returns true if migration is successful
9
+ * @throws {XpFatal} - If parameters are not provided correctly
10
+ */
11
+ static async discord_xp(dbUrl,deleteOld){try{await Promise.resolve().then(()=>__importStar(require("discord-xp"))).setURL(dbUrl);var e=await Promise.resolve().then(()=>__importStar(require("discord.js/package.json")));xplogs_1.XpLog.debug("migrate.discord_xp()",`Discord.JS v${e.version} detected.`);const t=await Promise.resolve().then(()=>__importStar(require("discord-xp/models/levels")));return await t.find({}).then(async data=>{for(const e of data)await database_1.db.findOne({collection:"simply-xps",data:{guild:e.guildID,user:e.userID}})||(await database_1.db.createOne({collection:"simply-xps",data:{guild:e.guildID,user:e.userID,xp:e.xp,level:e.level}}),deleteOld&&await t.deleteOne({userID:e.userID,guildID:e.guildID}))}),!0}catch(e){throw new xplogs_1.XpFatal({function:"migrate.discord_xp()",message:"Unfortunately this function requires discord-xp to be installed, you can uninstall it after using this function!"})}}
12
+ /**
13
+ * Effortlessly migrate from MongoDB to SQLite. (or vice versa)
14
+ * @async
15
+ * @param {"mongodb"|"sqlite"} from
16
+ * @link `Documentation:` https://simplyxp.js.org/docs/migrate/database
17
+ * @returns {Promise<boolean>} - Returns true if migration is successful
18
+ * @throws {XpFatal} - If parameters are not provided correctly
19
+ */static async database(from){if(from)throw new xplogs_1.XpFatal({function:"migrate.database()",message:"This function is not yet implemented, please wait for the next dev release!"});throw new xplogs_1.XpFatal({function:"migrate.database()",message:"No database type provided"})}}exports.migrate=migrate;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Reset user levels to 0 in a guild
3
+ * @async
4
+ * @param {string} userId
5
+ * @param {string} guildId
6
+ * @param {string} username
7
+ * @param {boolean?} erase - Erase user entry from database
8
+ * @link `Documentation:` https://simplyxp.js.org/docs/reset
9
+ * @returns {Promise<boolean>}
10
+ * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
11
+ */
12
+ export declare function reset(userId: string, guildId: string, username: string, erase?: boolean): Promise<boolean>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /**
3
+ * Reset user levels to 0 in a guild
4
+ * @async
5
+ * @param {string} userId
6
+ * @param {string} guildId
7
+ * @param {string} username
8
+ * @param {boolean?} erase - Erase user entry from database
9
+ * @link `Documentation:` https://simplyxp.js.org/docs/reset
10
+ * @returns {Promise<boolean>}
11
+ * @throws {XpFatal} If an invalid type is provided or if the value is not provided.
12
+ */async function reset(userId,guildId,username,erase=!1){if(!userId)throw new xplogs_1.XpFatal({function:"reset()",message:"No User ID Provided"});if(!guildId)throw new xplogs_1.XpFatal({function:"reset()",message:"No Guild ID Provided"});if(username)return!(await(username=(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db).findOne({collection:"simply-xps",data:{guild:guildId,user:userId}})||(xp_1.xp.auto_create&&!erase&&await username.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,level:0,xp:0}}).then(()=>!0).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error.stack})}),!erase))||(erase?username.deleteOne({collection:"simply-xps",data:{guild:guildId,user:userId}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):username.updateOne({collection:"simply-xps",data:{guild:guildId,user:userId}},{collection:"simply-xps",data:{guild:guildId,user:userId,level:0,xp:0}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}));throw new xplogs_1.XpFatal({function:"reset()",message:"No Username Provided"})}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.reset=void 0;const xplogs_1=require("./functions/xplogs"),xp_1=require("../xp");exports.reset=reset;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Role setup object
3
+ * @property {string} guild - The guild ID
4
+ * @property {number} level - The level number
5
+ * @property {string[] | string} roles - The role(s) to add
6
+ */
7
+ export interface RoleSetupObject {
8
+ guild?: string;
9
+ level: number;
10
+ roles: string[] | string;
11
+ }
12
+ /**
13
+ * Setup roles for levels
14
+ * @class roleSetup
15
+ */
16
+ export declare class roleSetup {
17
+ /**
18
+ * Add a role to the role setup
19
+ * @async
20
+ * @param {string} guildId - The guild ID
21
+ * @param {RoleSetupObject} options - Level/role options
22
+ * @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/add
23
+ * @returns {Promise<boolean>} - True if successful
24
+ * @throws {XpFatal} If an invalid type is provided or value is not provided.
25
+ */
26
+ static add(guildId: string, options: RoleSetupObject): Promise<boolean>;
27
+ /**
28
+ * Find a role in roleSetup
29
+ * @async
30
+ * @param {string} guildId - The guild ID
31
+ * @param {number} levelNumber - The level number
32
+ * @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/find
33
+ * @returns {Promise<RoleSetupObject>} - The level role object
34
+ * @throws {XpFatal} If an invalid type is provided or value is not provided.
35
+ */
36
+ static find(guildId: string, levelNumber: number): Promise<RoleSetupObject>;
37
+ /**
38
+ * Remove a level from the role setup
39
+ * @async
40
+ * @param {string} guildId - The guild ID
41
+ * @param {number} levelNumber - The level number
42
+ * @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/remove
43
+ * @returns {Promise<boolean>} - True if successful
44
+ * @throws {XpFatal} If an invalid type is provided or value is not provided.
45
+ */
46
+ static remove(guildId: string, levelNumber: number): Promise<boolean>;
47
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.roleSetup=void 0;const 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/roleSetup/add
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(guildId,options){if(!guildId)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Guild ID was not provided"});if(!options)throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Options were not provided"});if(isNaN(options?.level))throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Level must be a number"});if(options?.roles)return"string"==typeof options?.roles&&(options.roles=[options.roles]),xp_1.db.createOne({collection:"simply-xp-levelroles",data:{guild:guildId,level:options.level,roles:options.roles,timestamp:(new Date).toISOString()}});throw new xplogs_1.XpFatal({function:"roleSetup.add()",message:"Role was not provided"})}
12
+ /**
13
+ * Find a role in roleSetup
14
+ * @async
15
+ * @param {string} guildId - The guild ID
16
+ * @param {number} levelNumber - The level number
17
+ * @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/find
18
+ * @returns {Promise<RoleSetupObject>} - The level role object
19
+ * @throws {XpFatal} If an invalid type is provided or value is not provided.
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()}})}
21
+ /**
22
+ * Remove a level from the role setup
23
+ * @async
24
+ * @param {string} guildId - The guild ID
25
+ * @param {number} levelNumber - The level number
26
+ * @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/remove
27
+ * @returns {Promise<boolean>} - True if successful
28
+ * @throws {XpFatal} If an invalid type is provided or value is not provided.
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;
@@ -0,0 +1,25 @@
1
+ import { UserResult } from "./functions/database";
2
+ /**
3
+ * Set user level
4
+ * @async
5
+ * @param {string} userId
6
+ * @param {string} guildId
7
+ * @param {number} level
8
+ * @param {string} username - Username to use if auto_create is enabled
9
+ * @link `Documentation:` https://simplyxp.js.org/docs/setlevel
10
+ * @returns {Promise<UserResult>} - Object of user data on success
11
+ * @throws {XpFatal} - If parameters are not provided correctly
12
+ */
13
+ export declare function setLevel(userId: string, guildId: string, level: number, username?: string): Promise<UserResult>;
14
+ /**
15
+ * Set user XP
16
+ * @async
17
+ * @param {string} userId
18
+ * @param {string} guildId
19
+ * @param {number} xpData
20
+ * @param {string} username - Username to use if auto_create is enabled
21
+ * @link `Documentation:` https://simplyxp.js.org/docs/setxp
22
+ * @returns {Promise<UserResult>} - Object of user data on success
23
+ * @throws {XpFatal} - If parameters are not provided correctly
24
+ */
25
+ export declare function setXP(userId: string, guildId: string, xpData: number, username?: string): Promise<UserResult>;
package/lib/src/set.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * Set user level
4
+ * @async
5
+ * @param {string} userId
6
+ * @param {string} guildId
7
+ * @param {number} level
8
+ * @param {string} username - Username to use if auto_create is enabled
9
+ * @link `Documentation:` https://simplyxp.js.org/docs/setlevel
10
+ * @returns {Promise<UserResult>} - Object of user data on success
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.convert)("level",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.convert)("level",level)}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"User does not exist"})}
13
+ /**
14
+ * Set user XP
15
+ * @async
16
+ * @param {string} userId
17
+ * @param {string} guildId
18
+ * @param {number} xpData
19
+ * @param {string} username - Username to use if auto_create is enabled
20
+ * @link `Documentation:` https://simplyxp.js.org/docs/setxp
21
+ * @returns {Promise<UserResult>} - Object of user data on success
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"});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:(0,utilities_1.convert)("xp",xpData),xp:xpData}});if(xp_1.xp.auto_create&&username)return database_1.db.createOne({collection:"simply-xps",data:{guild:guildId,user:userId,name:username,level:(0,utilities_1.convert)("xp",xpData),xp:xpData}});throw new xplogs_1.XpFatal({function:"setXP()",message:"User does not exist"})}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 ADDED
@@ -0,0 +1,25 @@
1
+ import { Database } from "better-sqlite3";
2
+ import { MongoClient } from "mongodb";
3
+ export interface XPClient {
4
+ dbType: "mongodb" | "sqlite";
5
+ database: MongoClient | Database | undefined;
6
+ auto_create: boolean;
7
+ auto_purge: boolean;
8
+ notify: boolean;
9
+ debug: boolean;
10
+ }
11
+ export { addLevel, addXP } from "./src/add";
12
+ export { db } from "./src/functions/database";
13
+ export { charts } from "./src/charts";
14
+ export { connect } from "./src/connect";
15
+ export { convert, updateOptions } from "./src/functions/utilities";
16
+ export { create } from "./src/create";
17
+ export { fetch } from "./src/fetch";
18
+ export { leaderboard } from "./src/leaderboard";
19
+ export { migrate } from "./src/migrate";
20
+ export { rankCard, leaderboardCard } from "./src/cards";
21
+ export { reset } from "./src/reset";
22
+ export { roleSetup } from "./src/roleSetup";
23
+ export { setLevel, setXP } from "./src/set";
24
+ export declare const xp: XPClient;
25
+ export { rank } from "./src/deprecated/rank";
package/lib/xp.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rank = exports.xp = exports.setXP = exports.setLevel = exports.roleSetup = exports.reset = exports.leaderboardCard = exports.rankCard = exports.migrate = exports.leaderboard = exports.fetch = exports.create = exports.updateOptions = exports.convert = exports.connect = exports.charts = exports.db = exports.addXP = exports.addLevel = void 0;
4
+ // EXPORTS
5
+ var add_1 = require("./src/add");
6
+ Object.defineProperty(exports, "addLevel", { enumerable: true, get: function () { return add_1.addLevel; } });
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; } });
10
+ var charts_1 = require("./src/charts");
11
+ Object.defineProperty(exports, "charts", { enumerable: true, get: function () { return charts_1.charts; } });
12
+ var connect_1 = require("./src/connect");
13
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return connect_1.connect; } });
14
+ var utilities_1 = require("./src/functions/utilities");
15
+ Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return utilities_1.convert; } });
16
+ Object.defineProperty(exports, "updateOptions", { enumerable: true, get: function () { return utilities_1.updateOptions; } });
17
+ var create_1 = require("./src/create");
18
+ Object.defineProperty(exports, "create", { enumerable: true, get: function () { return create_1.create; } });
19
+ var fetch_1 = require("./src/fetch");
20
+ Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
21
+ var leaderboard_1 = require("./src/leaderboard");
22
+ Object.defineProperty(exports, "leaderboard", { enumerable: true, get: function () { return leaderboard_1.leaderboard; } });
23
+ var migrate_1 = require("./src/migrate");
24
+ 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
+ var reset_1 = require("./src/reset");
29
+ Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
30
+ var roleSetup_1 = require("./src/roleSetup");
31
+ Object.defineProperty(exports, "roleSetup", { enumerable: true, get: function () { return roleSetup_1.roleSetup; } });
32
+ var set_1 = require("./src/set");
33
+ Object.defineProperty(exports, "setLevel", { enumerable: true, get: function () { return set_1.setLevel; } });
34
+ Object.defineProperty(exports, "setXP", { enumerable: true, get: function () { return set_1.setXP; } });
35
+ exports.xp = {
36
+ auto_create: false,
37
+ auto_purge: false,
38
+ database: undefined,
39
+ debug: false,
40
+ dbType: "mongodb",
41
+ notify: true
42
+ };
43
+ // DEPRECATED
44
+ var rank_1 = require("./src/deprecated/rank");
45
+ Object.defineProperty(exports, "rank", { enumerable: true, get: function () { return rank_1.rank; } });