simply-xp 1.3.5-beta-7 → 2.0.0-dev.0-fix.2
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/FUNDING.yml +2 -2
- package/README.md +68 -57
- package/lib/src/add.d.ts +35 -0
- package/lib/src/add.js +21 -0
- package/lib/src/cards.d.ts +86 -0
- package/lib/src/cards.js +23 -0
- package/lib/src/charts.d.ts +17 -0
- package/lib/src/charts.js +10 -0
- package/lib/src/connect.d.ts +17 -0
- package/lib/src/connect.js +40 -0
- package/lib/src/create.d.ts +11 -0
- package/lib/src/create.js +11 -0
- package/lib/src/deprecated/rank.d.ts +18 -0
- package/lib/src/deprecated/rank.js +12 -0
- package/lib/src/fetch.d.ts +17 -0
- package/lib/src/fetch.js +10 -0
- package/lib/src/functions/convert.d.ts +10 -0
- package/lib/src/functions/convert.js +10 -0
- package/lib/src/functions/database.d.ts +90 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +18 -0
- package/lib/src/leaderboard.js +10 -0
- package/lib/src/migrate.d.ts +25 -0
- package/lib/src/migrate.js +19 -0
- package/lib/src/reset.d.ts +11 -0
- package/lib/src/reset.js +11 -0
- package/lib/src/roleSetup.d.ts +41 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +32 -0
- package/lib/src/set.js +21 -0
- package/lib/xp.d.ts +24 -0
- package/lib/xp.js +44 -0
- package/package.json +70 -53
- package/.eslintrc.json +0 -29
- package/.github/CODE_OF_CONDUCT.md +0 -128
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/SECURITY.md +0 -25
- package/.github/pull_request_template.md +0 -8
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.idea/discord.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/simply-xp.iml +0 -9
- package/.idea/vcs.xml +0 -6
- package/index.d.ts +0 -107
- package/simplyxp.js +0 -31
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -104
- package/src/charts.js +0 -92
- package/src/connect.js +0 -22
- package/src/create.js +0 -28
- package/src/fetch.js +0 -74
- package/src/leaderboard.js +0 -52
- package/src/lvlRole.js +0 -53
- package/src/models/level.js +0 -10
- package/src/models/lvlrole.js +0 -8
- package/src/rank.js +0 -295
- package/src/reset.js +0 -22
- package/src/roleSetup.js +0 -121
- package/src/setLevel.js +0 -70
- package/src/setXP.js +0 -51
- /package/{src → lib/src}/Fonts/Baloo-Regular.ttf +0 -0
|
@@ -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,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(`[35m[SIMPLY XP][0m ${{debug:"[36m",info:"[34m",error:"[31m",warn:"[33m"}[level]}(${e})[0m ${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,18 @@
|
|
|
1
|
+
export type User = {
|
|
2
|
+
guild: string;
|
|
3
|
+
user: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
position?: number;
|
|
6
|
+
level: number;
|
|
7
|
+
xp: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Get array of all users in the leaderboard
|
|
11
|
+
* @async
|
|
12
|
+
* @param {string} guildId - Guild ID
|
|
13
|
+
* @param {number} limit - Limit of users to return
|
|
14
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/leaderboard
|
|
15
|
+
* @returns {Promise<User[]>} Array of all users in the leaderboard
|
|
16
|
+
* @throws {XpFatal} If guild ID is not provided or limit is less than 1
|
|
17
|
+
*/
|
|
18
|
+
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,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reset user levels to 0 in a guild
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} userId
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {boolean} erase - Erase user entry from database
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/reset
|
|
8
|
+
* @returns {Promise<boolean>}
|
|
9
|
+
* @throws {XpFatal} If an invalid type is provided or if the value is not provided.
|
|
10
|
+
*/
|
|
11
|
+
export declare function reset(userId: string, guildId: string, erase: boolean): Promise<boolean>;
|
package/lib/src/reset.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 {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
|
+
*/async function reset(userId,guildId,erase){if(!userId)throw new xplogs_1.XpFatal({function:"reset()",message:"No User ID Provided"});var e;if(guildId)return e=(await Promise.resolve().then(()=>__importStar(require("./functions/database")))).db,erase?e.deleteOne({collection:"simply-xps",data:{guild:guildId,user:userId}}).catch(error=>{throw new xplogs_1.XpFatal({function:"reset()",message:error})}):e.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 Guild ID 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");exports.reset=reset;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type RoleSetupObject = {
|
|
2
|
+
guild?: string;
|
|
3
|
+
level: number;
|
|
4
|
+
roles: string[] | string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Setup roles for levels
|
|
8
|
+
* @class roleSetup
|
|
9
|
+
*/
|
|
10
|
+
export declare class roleSetup {
|
|
11
|
+
/**
|
|
12
|
+
* Add a role to the role setup
|
|
13
|
+
* @async
|
|
14
|
+
* @param {string} guildId - The guild ID
|
|
15
|
+
* @param {RoleSetupObject} options - Level/role options
|
|
16
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/add
|
|
17
|
+
* @returns {Promise<boolean>} - True if successful
|
|
18
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
19
|
+
*/
|
|
20
|
+
static add(guildId: string, options: RoleSetupObject): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* Find a role in roleSetup
|
|
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/find
|
|
27
|
+
* @returns {Promise<RoleSetupObject>} - The level role object
|
|
28
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
29
|
+
*/
|
|
30
|
+
static find(guildId: string, levelNumber: number): Promise<RoleSetupObject>;
|
|
31
|
+
/**
|
|
32
|
+
* Remove a level from the role setup
|
|
33
|
+
* @async
|
|
34
|
+
* @param {string} guildId - The guild ID
|
|
35
|
+
* @param {number} levelNumber - The level number
|
|
36
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/roleSetup/remove
|
|
37
|
+
* @returns {Promise<boolean>} - True if successful
|
|
38
|
+
* @throws {XpFatal} If an invalid type is provided or value is not provided.
|
|
39
|
+
*/
|
|
40
|
+
static remove(guildId: string, levelNumber: number): Promise<boolean>;
|
|
41
|
+
}
|
|
@@ -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}});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}})}
|
|
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}})}}exports.roleSetup=roleSetup;
|
package/lib/src/set.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set user level
|
|
3
|
+
* @async
|
|
4
|
+
* @param {string} userId
|
|
5
|
+
* @param {string} guildId
|
|
6
|
+
* @param {number} level
|
|
7
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/setlevel
|
|
8
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success
|
|
9
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
10
|
+
*/
|
|
11
|
+
export declare function setLevel(userId: string, guildId: string, level: number): Promise<{
|
|
12
|
+
user: string;
|
|
13
|
+
guild: string;
|
|
14
|
+
level: number;
|
|
15
|
+
xp: number;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Set user XP
|
|
19
|
+
* @async
|
|
20
|
+
* @param {string} userId
|
|
21
|
+
* @param {string} guildId
|
|
22
|
+
* @param {number} xp
|
|
23
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/setxp
|
|
24
|
+
* @returns {Promise<object>} - Object of user data on success
|
|
25
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
26
|
+
*/
|
|
27
|
+
export declare function setXP(userId: string, guildId: string, xp: number): Promise<{
|
|
28
|
+
user: string;
|
|
29
|
+
guild: string;
|
|
30
|
+
level: number;
|
|
31
|
+
xp: number;
|
|
32
|
+
}>;
|
package/lib/src/set.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Set user level
|
|
4
|
+
* @async
|
|
5
|
+
* @param {string} userId
|
|
6
|
+
* @param {string} guildId
|
|
7
|
+
* @param {number} level
|
|
8
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/setlevel
|
|
9
|
+
* @returns {Promise<{user: string, guild: string, level: number, xp: number}>} - Object of user data on success
|
|
10
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
11
|
+
*/async function setLevel(userId,guildId,level){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)return await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}})?database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,convert_1.convert)("level",level)}}):database_1.db.createOne({collection:"simply-xps",data:{user:userId,guild:guildId,level:level,xp:(0,convert_1.convert)("level",level)}});throw new xplogs_1.XpFatal({function:"setLevel()",message:"Level was not provided"})}
|
|
12
|
+
/**
|
|
13
|
+
* Set user XP
|
|
14
|
+
* @async
|
|
15
|
+
* @param {string} userId
|
|
16
|
+
* @param {string} guildId
|
|
17
|
+
* @param {number} xp
|
|
18
|
+
* @link `Documentation:` https://simplyxp.js.org/docs/setxp
|
|
19
|
+
* @returns {Promise<object>} - Object of user data on success
|
|
20
|
+
* @throws {XpFatal} - If parameters are not provided correctly
|
|
21
|
+
*/async function setXP(userId,guildId,xp){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(xp)return await database_1.db.findOne({collection:"simply-xps",data:{user:userId,guild:guildId}})?database_1.db.updateOne({collection:"simply-xps",data:{user:userId,guild:guildId}},{collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,convert_1.convert)("xp",xp),xp:xp}}):database_1.db.createOne({collection:"simply-xps",data:{user:userId,guild:guildId,level:(0,convert_1.convert)("xp",xp),xp:xp}});throw new xplogs_1.XpFatal({function:"setXP()",message:"XP was not provided"})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setXP=exports.setLevel=void 0;const xplogs_1=require("./functions/xplogs"),convert_1=require("./functions/convert"),database_1=require("./functions/database");exports.setLevel=setLevel,exports.setXP=setXP;
|
package/lib/xp.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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_purge: boolean;
|
|
7
|
+
notify: boolean;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
}
|
|
10
|
+
export { addLevel, addXP } from "./src/add";
|
|
11
|
+
export { db } from "./src/functions/database";
|
|
12
|
+
export { charts } from "./src/charts";
|
|
13
|
+
export { connect } from "./src/connect";
|
|
14
|
+
export { convert } from "./src/functions/convert";
|
|
15
|
+
export { create } from "./src/create";
|
|
16
|
+
export { fetch } from "./src/fetch";
|
|
17
|
+
export { leaderboard } from "./src/leaderboard";
|
|
18
|
+
export { migrate } from "./src/migrate";
|
|
19
|
+
export { rankCard, leaderboardCard } from "./src/cards";
|
|
20
|
+
export { reset } from "./src/reset";
|
|
21
|
+
export { roleSetup } from "./src/roleSetup";
|
|
22
|
+
export { setLevel, setXP } from "./src/set";
|
|
23
|
+
export declare const xp: XPClient;
|
|
24
|
+
export { rank } from "./src/deprecated/rank";
|
package/lib/xp.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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.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 convert_1 = require("./src/functions/convert");
|
|
15
|
+
Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return convert_1.convert; } });
|
|
16
|
+
var create_1 = require("./src/create");
|
|
17
|
+
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return create_1.create; } });
|
|
18
|
+
var fetch_1 = require("./src/fetch");
|
|
19
|
+
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
|
|
20
|
+
var leaderboard_1 = require("./src/leaderboard");
|
|
21
|
+
Object.defineProperty(exports, "leaderboard", { enumerable: true, get: function () { return leaderboard_1.leaderboard; } });
|
|
22
|
+
var migrate_1 = require("./src/migrate");
|
|
23
|
+
Object.defineProperty(exports, "migrate", { enumerable: true, get: function () { return migrate_1.migrate; } });
|
|
24
|
+
var cards_1 = require("./src/cards");
|
|
25
|
+
Object.defineProperty(exports, "rankCard", { enumerable: true, get: function () { return cards_1.rankCard; } });
|
|
26
|
+
Object.defineProperty(exports, "leaderboardCard", { enumerable: true, get: function () { return cards_1.leaderboardCard; } });
|
|
27
|
+
var reset_1 = require("./src/reset");
|
|
28
|
+
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return reset_1.reset; } });
|
|
29
|
+
var roleSetup_1 = require("./src/roleSetup");
|
|
30
|
+
Object.defineProperty(exports, "roleSetup", { enumerable: true, get: function () { return roleSetup_1.roleSetup; } });
|
|
31
|
+
var set_1 = require("./src/set");
|
|
32
|
+
Object.defineProperty(exports, "setLevel", { enumerable: true, get: function () { return set_1.setLevel; } });
|
|
33
|
+
Object.defineProperty(exports, "setXP", { enumerable: true, get: function () { return set_1.setXP; } });
|
|
34
|
+
exports.xp = {
|
|
35
|
+
auto_purge: false,
|
|
36
|
+
database: undefined,
|
|
37
|
+
debug: false,
|
|
38
|
+
dbType: "mongodb",
|
|
39
|
+
notify: true
|
|
40
|
+
};
|
|
41
|
+
// DEPRECATED
|
|
42
|
+
var rank_1 = require("./src/deprecated/rank");
|
|
43
|
+
Object.defineProperty(exports, "rank", { enumerable: true, get: function () { return rank_1.rank; } });
|
|
44
|
+
//# sourceMappingURL=xp.js.map
|
package/package.json
CHANGED
|
@@ -1,53 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "simply-xp",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"discord",
|
|
20
|
-
"discord
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
],
|
|
37
|
-
"license": "Apache-2.0",
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "https://github.com/Rahuletto/simply-xp"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"@napi-rs/canvas": "^0.1.41"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "simply-xp",
|
|
3
|
+
"version": "2.0.0-dev.0-fix.2",
|
|
4
|
+
"description": "The easiest way to implement xp system",
|
|
5
|
+
"main": "lib/xp.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"beta": "node Tests/clean.mjs && pnpm update && npm publish --tag beta",
|
|
8
|
+
"clean": "node Tests/clean.mjs",
|
|
9
|
+
"dev": "node Tests/clean.mjs && pnpm update && npm publish --tag dev",
|
|
10
|
+
"docs": "node Tests/jsdocs.cjs",
|
|
11
|
+
"latest": "node Tests/clean.mjs && pnpm update && npm publish",
|
|
12
|
+
"test": "node Tests/clean.mjs && node Tests/test.cjs"
|
|
13
|
+
},
|
|
14
|
+
"author": "Rahuletto",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"amaribot",
|
|
17
|
+
"charts",
|
|
18
|
+
"discord",
|
|
19
|
+
"discord.js",
|
|
20
|
+
"discord-xp",
|
|
21
|
+
"easy",
|
|
22
|
+
"fun",
|
|
23
|
+
"guilded",
|
|
24
|
+
"leaderboard",
|
|
25
|
+
"level role",
|
|
26
|
+
"level up",
|
|
27
|
+
"mee6",
|
|
28
|
+
"mongodb",
|
|
29
|
+
"package",
|
|
30
|
+
"simply",
|
|
31
|
+
"simply-djs",
|
|
32
|
+
"simplydjs",
|
|
33
|
+
"sqlite",
|
|
34
|
+
"system",
|
|
35
|
+
"xp"
|
|
36
|
+
],
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/Rahuletto/simply-xp.git"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@napi-rs/canvas": "^0.1.41"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/better-sqlite3": "^7.6.4",
|
|
47
|
+
"@types/node": "^20.4.5",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
49
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
50
|
+
"better-sqlite3": "8.5.0",
|
|
51
|
+
"discord.js": "^14.12.1",
|
|
52
|
+
"eslint": "^8.46.0",
|
|
53
|
+
"guilded.ts": "^0.20.2",
|
|
54
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
55
|
+
"mongodb": "5.7.0",
|
|
56
|
+
"typescript": "^5.1.6",
|
|
57
|
+
"uglify-js": "^3.17.4"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=15.5.0"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/Rahuletto/simply-xp/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://simplyxp.js.org",
|
|
66
|
+
"directories": {
|
|
67
|
+
"doc": "Mini_Docs",
|
|
68
|
+
"lib": "lib"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/.eslintrc.json
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"commonjs": true,
|
|
4
|
-
"es2021": true,
|
|
5
|
-
"node": true
|
|
6
|
-
},
|
|
7
|
-
"extends": "eslint:recommended",
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": "latest"
|
|
10
|
-
},
|
|
11
|
-
"rules": {
|
|
12
|
-
"indent": [
|
|
13
|
-
"error",
|
|
14
|
-
"tab"
|
|
15
|
-
],
|
|
16
|
-
"linebreak-style": [
|
|
17
|
-
"error",
|
|
18
|
-
"unix"
|
|
19
|
-
],
|
|
20
|
-
"quotes": [
|
|
21
|
-
"error",
|
|
22
|
-
"single"
|
|
23
|
-
],
|
|
24
|
-
"semi": [
|
|
25
|
-
"error",
|
|
26
|
-
"always"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|