Skip to content

Commit

Permalink
adding description to function
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenedtzjs committed Jun 11, 2024
1 parent 92391eb commit 14746c3
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<a href="https://github.com/skick1234/CyraTeam/discord-afk-js" target="_blank" rel="noopener noreferrer">
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/CyraTeam/discord-afk-js">
</a>
<a href="https://discord.gg/qpT2AeYZRN" target="_blank" rel="noopener noreferrer">
<a href="https://discord.gg/yyaxUHTRSa" target="_blank" rel="noopener noreferrer">
<img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=CyraTeam&logo=discord">
</a>
<a href="https://github.com/CyraTeam/discord-afk-js" target="_blank" rel="noopener noreferrer">
Expand All @@ -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.

<!-- Section for system requirements -->

# Requirements

- [NodeJS](https://nodejs.org) 16.9.0 or higher
- [NodeJS] 16.9.0 or higher

<!-- Section for installation instructions -->

Expand All @@ -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]

<!-- Section for usage examples -->

Expand Down Expand Up @@ -122,3 +123,7 @@ This project is open-source and is licensed under the Apache 2.0 License. Find m
<a href="https://discord.gg/qpT2AeYZRN" target="_blank" rel="noopener noreferrer">
<img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=CyraTeam&logo=discord">
</a>

[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
58 changes: 55 additions & 3 deletions dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<void> {
const { token = '', log = true } = options;
try {
Expand All @@ -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<void> {
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<void> {
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<boolean> {
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<string | undefined> {
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;
// ================================================================
Expand Down
28 changes: 28 additions & 0 deletions dist/options/index.ts
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 14746c3

Please sign in to comment.