From bb4cda13f5fdc0fe93de489610a3365128f0ef6b Mon Sep 17 00:00:00 2001 From: Ayaka Date: Fri, 29 Jul 2022 00:17:21 +0530 Subject: [PATCH 1/3] update(docs on sharding) --- src/SUMMARY.md | 2 +- src/advanced-guides/sharding.md | 99 +++++++++++++++++++++++++++++++++ src/other/sharding.md | 32 ----------- 3 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 src/advanced-guides/sharding.md delete mode 100644 src/other/sharding.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a462a59c..62c9efd9 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -28,6 +28,7 @@ * [Custom Events](advanced-guides/custom-events.md) * [@akarui/aoi.music](advanced-guides/music.md) * [dbd.express](advanced-guides/dashboard.md) +* [Sharding](advanced-guides/sharding.md "guide on sharding") *** @@ -558,7 +559,6 @@ ## Other * [Hyperlink](other/hyperlink.md) -* [Sharding](other/sharding.md) * [Character Escaping](other/character-escaping.md) * [Embed Errors](other/embed-errors.md) * [Permissions](other/permissions.md) diff --git a/src/advanced-guides/sharding.md b/src/advanced-guides/sharding.md new file mode 100644 index 00000000..30b1c50c --- /dev/null +++ b/src/advanced-guides/sharding.md @@ -0,0 +1,99 @@ +# Sharding + +## Introduction + +aoi.js has `ClientShard` class to handle `Sharding` for your discord bot. + +## Usage + +```ts +const sharder: ClientShard = new ClientShard( + file: string, + sharderOptions?: ShardOption, + spawnOptions?: SpawnOption +) +``` + +### file + + + + + + + + + + + + + + + + + + +
Typestring
DescriptionPath to bot file
Requiredyes
DefaultN/A
+ +### sharderOptions + +|Property|Type|Description|Required|Default| +|--------|----|-----------|--------|-------| +| ***totalShard*** | string \| number | number of total Shards | no | auto | +| ***shardList*** | string \| number[] | List of Shards to spawn | no | auto | +| ***mode*** | process \| worker | type of Sharding Mode (child_process \| worker_threads ) | no | process | +| ***respawn*** | boolean | whether to respawn shards on exiting | no | true | +| token | string | token to use for shard count | no | none | + +### spawnOptions + +|Property|Type|Description|Required|Default| +|--------|----|-----------|--------|-------| +| ***amount*** | string \| number | number of shards to spawn | no | `ClientShard#totalShards` | +| ***delay*** | number | delay for spawning each shard ( `in ms` ) | no | 5500 | +| ***timeout*** | number | The amount in milliseconds to wait until the `Bot` has become ready ( `in ms` ) | no | 30000 | + +## Basic Setup + +```js +//index.js +const { ClientShard } = require("aoi.js"); + +const sharder = new ClientShard("bot.js"); + +sharder.onShardCreate(); + +sharder.shardCreateCommand({ + name: "create Shard Log", + code: + ` + $log[Created Shard ID: $shard[id]] + ` +}); +``` + +```js +//bot.js +const { Bot } = require("aoi.js"); +const bot = new Bot({ + token: "DISCORD BOT TOKEN", + prefix: "DISCORD BOT PREFIX", + intents: [ "guilds", "guildMessages" ], +}); + +bot.onMessage(); + +bot.command({ + name: "ping", + code: + ` + Pong! + WS -> $ping ms + ShardId -> $shardId + ShardPing -> $shardPing[$shardId] + ` +}) +``` + +### NOTE +the ***`new index.js`*** is for ClientShard and ***`bot.js is old index.js`*** \ No newline at end of file diff --git a/src/other/sharding.md b/src/other/sharding.md deleted file mode 100644 index 0ac7045b..00000000 --- a/src/other/sharding.md +++ /dev/null @@ -1,32 +0,0 @@ -# Sharding - -{% hint style="danger" %} -Sharding is only necessary for bots in 2,000+ Guilds -{% endhint %} - -#### How to shard - -```javascript -const bot = new Aoijs.bot({ - sharding: true, - shardAmount: 2, - token: "token", - prefix: "prefix" -}) -``` - -#### Finding current guild's shard ID - -```javascript -bot.command({ - name: "shardID", - code: `Guilds Shard: $shardID` -}) -``` - -{% hint style="danger" %} -Sharding can lead to high ping/response time and depending your host, can use a lot of memory and disk space -{% endhint %} - - - From 51ffcae0bf5cfe9e086516008abcbcb7d583c363 Mon Sep 17 00:00:00 2001 From: Ayaka <73595362+USERSATOSHI@users.noreply.github.com> Date: Fri, 5 Aug 2022 23:52:25 +0530 Subject: [PATCH 2/3] Update sharding.md --- src/advanced-guides/sharding.md | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/advanced-guides/sharding.md b/src/advanced-guides/sharding.md index 30b1c50c..89ddaa87 100644 --- a/src/advanced-guides/sharding.md +++ b/src/advanced-guides/sharding.md @@ -59,17 +59,12 @@ const sharder: ClientShard = new ClientShard( //index.js const { ClientShard } = require("aoi.js"); -const sharder = new ClientShard("bot.js"); - -sharder.onShardCreate(); - -sharder.shardCreateCommand({ - name: "create Shard Log", - code: - ` - $log[Created Shard ID: $shard[id]] - ` +const sharder = new ClientShard("./bot.js",{ + totalShards : "auto", + token: "BOT TOKEN HERE", }); + +sharder.startProcess(); ``` ```js @@ -96,4 +91,4 @@ bot.command({ ``` ### NOTE -the ***`new index.js`*** is for ClientShard and ***`bot.js is old index.js`*** \ No newline at end of file +the ***`new index.js`*** is for ClientShard and ***`bot.js is old index.js`*** From 5bfce0a775cd19f27ea7494f72008695275c1656 Mon Sep 17 00:00:00 2001 From: Ayaka Date: Fri, 19 Aug 2022 18:30:22 +0530 Subject: [PATCH 3/3] updated according to review --- src/advanced-guides/sharding.md | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/advanced-guides/sharding.md b/src/advanced-guides/sharding.md index 30b1c50c..22548ee5 100644 --- a/src/advanced-guides/sharding.md +++ b/src/advanced-guides/sharding.md @@ -37,26 +37,27 @@ const sharder: ClientShard = new ClientShard( ### sharderOptions -|Property|Type|Description|Required|Default| -|--------|----|-----------|--------|-------| -| ***totalShard*** | string \| number | number of total Shards | no | auto | -| ***shardList*** | string \| number[] | List of Shards to spawn | no | auto | -| ***mode*** | process \| worker | type of Sharding Mode (child_process \| worker_threads ) | no | process | -| ***respawn*** | boolean | whether to respawn shards on exiting | no | true | -| token | string | token to use for shard count | no | none | +| Property | Type | Description | Required | Default | +| ---------------- | ------------------ | -------------------------------------------------------- | -------- | ------- | +| **_totalShard_** | string \| number | number of total Shards | no | auto | +| **_shardList_** | string \| number[] | List of Shards to spawn | no | auto | +| **_mode_** | process \| worker | type of Sharding Mode (child_process \| worker_threads ) | no | process | +| **_respawn_** | boolean | whether to respawn shards on exiting | no | true | +| token | string | token to use for shard count | no | none | ### spawnOptions -|Property|Type|Description|Required|Default| -|--------|----|-----------|--------|-------| -| ***amount*** | string \| number | number of shards to spawn | no | `ClientShard#totalShards` | -| ***delay*** | number | delay for spawning each shard ( `in ms` ) | no | 5500 | -| ***timeout*** | number | The amount in milliseconds to wait until the `Bot` has become ready ( `in ms` ) | no | 30000 | +| Property | Type | Description | Required | Default | +| ------------- | ---------------- | ------------------------------------------------------------------------------- | -------- | ------------------------- | +| **_amount_** | string \| number | number of shards to spawn | no | `ClientShard#totalShards` | +| **_delay_** | number | delay for spawning each shard ( `in ms` ) | no | 5500 | +| **_timeout_** | number | The amount in milliseconds to wait until the `Bot` has become ready ( `in ms` ) | no | 30000 | ## Basic Setup +in `index.js` + ```js -//index.js const { ClientShard } = require("aoi.js"); const sharder = new ClientShard("bot.js"); @@ -65,35 +66,35 @@ sharder.onShardCreate(); sharder.shardCreateCommand({ name: "create Shard Log", - code: - ` + code: ` $log[Created Shard ID: $shard[id]] - ` + `, }); ``` +in `bot.js` + ```js -//bot.js const { Bot } = require("aoi.js"); const bot = new Bot({ token: "DISCORD BOT TOKEN", prefix: "DISCORD BOT PREFIX", - intents: [ "guilds", "guildMessages" ], + intents: ["guilds", "guildMessages"], }); bot.onMessage(); bot.command({ name: "ping", - code: - ` + code: ` Pong! WS -> $ping ms ShardId -> $shardId ShardPing -> $shardPing[$shardId] - ` -}) + `, +}); ``` ### NOTE -the ***`new index.js`*** is for ClientShard and ***`bot.js is old index.js`*** \ No newline at end of file + +the **_`new index.js`_** is for ClientShard and **_`bot.js is old index.js`_**