From 14746c3d46b54cf95180ce935dd1391e18eeaf30 Mon Sep 17 00:00:00 2001 From: rio Date: Tue, 11 Jun 2024 15:58:06 +0700 Subject: [PATCH] adding description to function --- README.md | 13 +++++++--- dist/index.ts | 58 ++++++++++++++++++++++++++++++++++++++++--- dist/options/index.ts | 28 +++++++++++++++++++++ package.json | 2 +- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 034ae6ff..827e9031 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ GitHub Repo stars - + Discord @@ -43,13 +43,13 @@ # discord-afk-js -**[discord-afk-js@database](https://www.npmjs.com/package/discord-afk-js?activeTab=readme)** is an npm package designed for Discord bot developers. It facilitates efficient AFK user management with seamless integration capabilities for external databases. +**[discord-afk-js]** is an npm package designed for Discord bot developers. It facilitates efficient AFK user management with seamless integration capabilities for external databases. # Requirements -- [NodeJS](https://nodejs.org) 16.9.0 or higher +- [NodeJS] 16.9.0 or higher @@ -58,8 +58,9 @@ To use **discord-afk-js** with database versions, install it through npm, the Node.js package manager. Run the following command in your terminal: ```bash -npm install discord-afk-js@database +npm install discord-afk-js@[database version] ``` +Note: you can get database versions from [Here] @@ -122,3 +123,7 @@ This project is open-source and is licensed under the Apache 2.0 License. Find m Discord + +[Here]: https://www.npmjs.com/package/discord-afk-js/v/10.0.0?activeTab=versions +[NodeJS]: https://nodejs.org +[discord-afk-js]: https://www.npmjs.com/package/discord-afk-js?activeTab=readme \ No newline at end of file diff --git a/dist/index.ts b/dist/index.ts index 70aee22f..75707992 100644 --- a/dist/index.ts +++ b/dist/index.ts @@ -57,7 +57,7 @@ import { * afk.connect({ token: 'token', log: 'false' }); * * // Add a user to AFK status - * afk.addUser("user123", "Away from keyboard"); + * afk.addUser({ id: "user123", reason: "Away from keyboard" }); * * // Check if a user is AFK * const isUserAFK = afk.findUser("user123"); @@ -108,6 +108,19 @@ import { class AfkClient { private isConnected: boolean = false; + /** + * Connect to a MongoDB database. + * + * This method connects to a MongoDB database using the provided connection options. + * If the connection is successful, the client will be marked as connected. + * + * @param options - An object containing the database connection token and a log flag. + * The token must be a valid MongoDB connection string. + * The log flag determines whether connection logs are printed to the console. + * @throws AfkDbError - Thrown if the provided token is not a valid MongoDB URL. + * @throws AfkTimeout - Thrown if the MongoDB connection times out. + * @throws AfkConnectionError - Thrown for other MongoDB connection errors. + */ async connect(options: ConnectionOptions): Promise { const { token = '', log = true } = options; try { @@ -129,31 +142,70 @@ class AfkClient { }; }; + /** + * Add a user to the AFK (Away From Keyboard) status list. + * + * Use this method to mark a user as AFK, providing their ID and an optional reason. + * + * @param options - An object containing the user ID and the reason for being AFK. + * The ID is a unique identifier for the user. + * The reason is an optional string explaining why the user is AFK. + */ async addUser(options: UserOptions): Promise { const { id = '', reason = '' } = options; await setUser(id, reason); }; + /** + * Remove a user from the AFK status list. + * + * Use this method to mark a user as no longer AFK by providing their unique ID. + * + * @param id - The unique identifier for the user to be removed from the AFK status list. + */ async removeUser(id: string): Promise { await deleteUser(id); }; + /** + * Check if a user is currently marked as AFK. + * + * This method checks whether a user, identified by their unique ID, is currently marked + * as AFK (Away From Keyboard). It returns a boolean value indicating the user's AFK status. + * + * @param id - The unique identifier for the user to check. + * @returns boolean - `true` if the user is AFK, `false` otherwise. + */ async findUser(id: string): Promise { return searchUser(id); }; + /** + * Retrieve the reason why a user is marked as AFK. + * + * This method returns the reason why a user, identified by their ID, is marked as AFK. + * + * @param id - The unique identifier of the user. + * @returns string | undefined - The reason for the AFK status, or `undefined` if no reason is found. + */ async findMessage(id: string): Promise { return getUser(id); }; }; // ================================================================ /** - * Check update before notify to console. + * Check for updates and notify the console if an update is available. + * + * This function checks for updates to the `discord-afk-js` library and logs a message to + * the console if an update is available. This ensures users are aware of the latest version. */ checkUpdate(); // ================================================================ /** - * The version of the `discord-afk-js` library that you are currently using. + * The version of the `discord-afk-js` library you are currently using. + * + * This constant contains the version number of the `discord-afk-js` library in use. + * It can be used for logging, debugging, or ensuring compatibility with other parts of your project. */ declare const versions: string; // ================================================================ diff --git a/dist/options/index.ts b/dist/options/index.ts index da03a5b4..29463388 100644 --- a/dist/options/index.ts +++ b/dist/options/index.ts @@ -1,10 +1,38 @@ export declare interface ConnectionOptions { + /** + * MongoDB connection token. + * + * This token should be a valid MongoDB connection string. It is used to + * authenticate and establish a connection to the MongoDB database. + */ token?: string; + + /** + * Enable or disable connection logs. + * + * When set to `true`, detailed logs of the connection process will be printed to the console. + * This can be useful for debugging connection issues. Defaults to `true`. + * + * @default true + */ log?: boolean; }; export declare interface UserOptions { + /** + * Unique user identifier. + * + * This is the unique ID used to identify a user in the AFK system. It can be + * any string that uniquely represents the user. + */ id?: string; + + /** + * Reason for AFK status. + * + * This is an optional string that provides the reason why the user is marked as AFK. + * It helps other users understand why the user is not available. + */ reason?: string; }; diff --git a/package.json b/package.json index 3dd9b29e..66ee635d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-afk-js", - "version": "1.0.0", + "version": "10.0.1", "description": "discord-afk-js package is a convenient tool for creating AFK commands (with database)", "main": "./dist/index.js", "types": "./dist/index.ts",