3.0.2 • Published 2 years ago

kurasuta v3.0.2

Weekly downloads
126
License
MIT
Repository
github
Last release
2 years ago

Kurasuta

About

Kurasuta is a powerful sharding manager for the discord.js library. It uses Node.js's cluster module to spread shards evenly among all cores.

Installation and Usage

To download Kurasuta, run npm install kurasuta If you use Yarn, run yarn add kurasuta

To use Kurasuta, you can take a look at example

ShardingManager

Important Note Your Sharder file is also executed by each cluster to access the client, client options and ipcsocket properties. You should make sure to wrap all the code what should only run on the Master process in a if statement checking if the current process is the Master process. This does not include ShardingManager#spawn.

Example:

const { isPrimary } = require('cluster');

if (isPrimary) {
	// Code to run on the Master process here
}
NameDescription
pathpath to a file that exports a class extending Cluster. The class must contain a method called launch.
options.clientOptionsAn object of client options you want to pass to the Discord.js client constructor.
options.clusterCountThe number of how many clusters you want. Defaults to the amount of cores.
options.shardCountThe number of how many shards you want. Defaults to the amount that the gateway recommends, taking options.guildsPerShardinto account.
options.developmentBoolean to enable development mode.
options.clientClass extending the Discord.js client you want to use for your clusters (useful for Frameworks like Commando, Klasa, or Akairo). Defaults to Discord.js client.
options.guildsPerShardNumber to calculate how many guilds per shard. Defaults to 1000. Ignored if you set shardCount.
options.respawnBoolean indicating if exited Clusters should always get restarted. Defaults to true .
options.ipcSocketPath to Socket or Port that should be used for IPC connections. Defaults to Port 9999.
options.tokenToken that should be used to fetch the recommend Shard count if no Shard count was provided.
options.timeoutTime per shard to wait before assuming that a Cluster can't get ready in ms. Defaults to 30000
option.retryBoolean indicating if Clusters which fail to start but not exit should be restarted. Defaults to true

Events

NameArgument(s)Description
debugmessage: stringEmitted for debug messages
messagemessage: unknownEmitted for custom messages sent from Cluster to Manager
readycluster: ClusterEmitted when a Cluster becomes ready
spawncluster: ClusterEmitted when a Cluster spawns
shardReadyshardID: numberEmitted when a Shard becomes ready
shardReconnectshardID: numberEmitted when a Shard reconnects
shardResumereplayed: number, shardID: numberEmitted when a Shard resumes
shardDisconnectcloseEvent: CloseEvent, shardID: numberEmitted when a Shard disconnects

Cluster

In every cluster when your code is loaded, you get access to this.client and this.id. this.client is an instance of the Client you provided with nearly no modifications besides the shard property, Discord.js' build-in ShardClientUtil is replaced by Kurasuta's.

ShardClientUtil

MethodExampleDescriptionReturns
broadcastEvalclient.shard.broadcastEval(script);Evals a script on all clusters in context of the Client.Promise<unkown[]>
masterEvalclient.shard.masterEval(script);Evals a script on the master process in context of the ShardingManager.Promise<unkown>
fetchClientValuesclient.shard.fetchClientValues(prop);Fetch a Client value on all clusters.Promise<unkown[]>
restartAllclient.shard.restartAll();Sends a message to the master process to kill & restart all clusters.Promise<void>
restartclient.shard.restart(clusterID);Restart a specific cluster by id.Promise<void>
sendclient.shard.send(data, options);send a message to the master process.Promise<void>

Example

Directory Tree

In this example our setup looks like this:

Project/
├── node-modules/
│   └── kurasuta/
|
└── src/
    ├── main.js
    └── index.js

Example of main.js

const { BaseCluster } = require('kurasuta');

module.exports = class extends BaseCluster {
	launch() {
		this.client.login('YOUR_TOKEN_HERE');
	}
};

Example of index.js

const { ShardingManager } = require('kurasuta');
const { join } = require('path');
const sharder = new ShardingManager(join(__dirname, 'main'), {
	// your options here
});

sharder.spawn();
3.0.2

2 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

5 years ago

1.1.3-next2

5 years ago

1.1.3-next

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.2.18

5 years ago

0.2.17

5 years ago

0.2.16

5 years ago

0.2.15

5 years ago

0.2.14

5 years ago

0.2.13

5 years ago

0.2.12

5 years ago

0.2.11

5 years ago

0.2.10

5 years ago

0.2.9

5 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago