buncord-hybrid-sharding 1.0.0
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/.gitattributes +2 -0
- package/LICENSE +28 -0
- package/README.md +91 -0
- package/bun.lock +88 -0
- package/package.json +39 -0
- package/src/Core/Cluster.ts +414 -0
- package/src/Core/ClusterClient.ts +329 -0
- package/src/Core/ClusterManager.ts +545 -0
- package/src/Core/DashboardServer.ts +84 -0
- package/src/Plugins/AutoResharderSystem.ts +382 -0
- package/src/Plugins/HeartbeatSystem.ts +56 -0
- package/src/Plugins/QueueManager.ts +49 -0
- package/src/Plugins/ReCluster.ts +101 -0
- package/src/Structures/Child.ts +109 -0
- package/src/Structures/Data.ts +33 -0
- package/src/Structures/IPCHandler.ts +154 -0
- package/src/Structures/IPCMessage.ts +101 -0
- package/src/Structures/ManagerHooks.ts +9 -0
- package/src/Structures/PromiseHandler.ts +63 -0
- package/src/Structures/Queue.ts +84 -0
- package/src/Util/RedisClient.ts +77 -0
- package/src/Util/Util.ts +62 -0
- package/src/index.ts +17 -0
- package/src/types/shared.ts +164 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Removed node:child_process import
|
|
2
|
+
import { Client } from "discord.js";
|
|
3
|
+
|
|
4
|
+
import { Cluster } from "../Core/Cluster.js";
|
|
5
|
+
import { ClusterClient } from "../Core/ClusterClient.js";
|
|
6
|
+
import { ClusterManager } from "../Core/ClusterManager.js";
|
|
7
|
+
import { ChildProcessOptions } from "../Structures/Child.js";
|
|
8
|
+
import { BaseMessage, IPCMessage } from "../Structures/IPCMessage.js";
|
|
9
|
+
|
|
10
|
+
export const Events = {
|
|
11
|
+
ERROR: 'warn',
|
|
12
|
+
WARN: 'error',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const DefaultOptions = {
|
|
16
|
+
http: {
|
|
17
|
+
api: 'https://discord.com/api',
|
|
18
|
+
version: '10',
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const Endpoints = {
|
|
23
|
+
botGateway: '/gateway/bot',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export enum messageType {
|
|
27
|
+
'MISSING_TYPE',
|
|
28
|
+
'CUSTOM_REQUEST',
|
|
29
|
+
'CUSTOM_MESSAGE',
|
|
30
|
+
'CUSTOM_REPLY',
|
|
31
|
+
'HEARTBEAT',
|
|
32
|
+
'HEARTBEAT_ACK',
|
|
33
|
+
'CLIENT_BROADCAST_REQUEST',
|
|
34
|
+
'CLIENT_BROADCAST_RESPONSE',
|
|
35
|
+
'CLIENT_RESPAWN',
|
|
36
|
+
'CLIENT_RESPAWN_ALL',
|
|
37
|
+
'CLIENT_MAINTENANCE',
|
|
38
|
+
'CLIENT_MAINTENANCE_ENABLE',
|
|
39
|
+
'CLIENT_MAINTENANCE_DISABLE',
|
|
40
|
+
'CLIENT_MAINTENANCE_ALL',
|
|
41
|
+
'CLIENT_SPAWN_NEXT_CLUSTER',
|
|
42
|
+
'CLIENT_READY',
|
|
43
|
+
'CLIENT_EVAL_REQUEST',
|
|
44
|
+
'CLIENT_EVAL_RESPONSE',
|
|
45
|
+
'CLIENT_MANAGER_EVAL_REQUEST',
|
|
46
|
+
'CLIENT_MANAGER_EVAL_RESPONSE',
|
|
47
|
+
'MANAGER_BROADCAST_REQUEST',
|
|
48
|
+
'MANAGER_BROADCAST_RESPONSE',
|
|
49
|
+
'CLIENT_AUTORESHARDER_SENDDATA',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface evalOptions<T = object> {
|
|
53
|
+
cluster?: number | number[];
|
|
54
|
+
shard?: number;
|
|
55
|
+
guildId?: string;
|
|
56
|
+
context?: T;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
_type?: messageType;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type Awaitable<T> = T | PromiseLike<T>;
|
|
62
|
+
|
|
63
|
+
export type Serialized<T> = T extends symbol | bigint | (() => any)
|
|
64
|
+
? never
|
|
65
|
+
: T extends number | string | boolean | undefined
|
|
66
|
+
? T
|
|
67
|
+
: T extends { toJSON(): infer R }
|
|
68
|
+
? R
|
|
69
|
+
: T extends ReadonlyArray<infer V>
|
|
70
|
+
? Serialized<V>[]
|
|
71
|
+
: T extends ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
|
|
72
|
+
? {}
|
|
73
|
+
: { [K in keyof T]: Serialized<T[K]> };
|
|
74
|
+
|
|
75
|
+
export interface ClusterSpawnOptions {
|
|
76
|
+
delay?: number;
|
|
77
|
+
timeout?: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ClusterManagerSpawnOptions extends ClusterSpawnOptions {
|
|
81
|
+
amount?: number | 'auto';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ClusterManagerOptions {
|
|
85
|
+
/** The token of the discord bot */
|
|
86
|
+
token?: string;
|
|
87
|
+
/** Number of total internal shards or "auto" */
|
|
88
|
+
totalShards?: number | 'auto';
|
|
89
|
+
/** Number of total Clusters\Process to spawn*/
|
|
90
|
+
totalClusters?: number | 'auto';
|
|
91
|
+
/** Number of shards per cluster*/
|
|
92
|
+
shardsPerClusters?: number;
|
|
93
|
+
/** Arguments to pass to the clustered script when spawning (only available when using the `process` mode)*/
|
|
94
|
+
shardArgs?: string[];
|
|
95
|
+
/** Arguments to pass to the clustered script executable when spawning*/
|
|
96
|
+
execArgv?: string[];
|
|
97
|
+
/** Whether clusters should automatically respawn upon exiting */
|
|
98
|
+
respawn?: boolean;
|
|
99
|
+
/** Which mode to use for clustering */
|
|
100
|
+
mode?: 'worker' | 'process';
|
|
101
|
+
/** An Array of Internal Shards Ids, which should get spawned */
|
|
102
|
+
shardList?: number[];
|
|
103
|
+
/** An Array of Ids to assign to the spawned Clusters, when the default id scheme is not wanted */
|
|
104
|
+
clusterList?: number[];
|
|
105
|
+
/** Restart options */
|
|
106
|
+
restarts?: ClusterRestartOptions;
|
|
107
|
+
/** Control the Spawn Queue */
|
|
108
|
+
queue?: QueueOptions;
|
|
109
|
+
/** Options to pass to the spawn,respawn method */
|
|
110
|
+
spawnOptions?: ClusterManagerSpawnOptions;
|
|
111
|
+
/** Data, which is passed to the Cluster */
|
|
112
|
+
clusterData?: object;
|
|
113
|
+
/** @deprecated keepAlive is not supported anymore on and above v1.6.0. Import it as plugin ("HeartbeatManager") */
|
|
114
|
+
keepAlive?: boolean;
|
|
115
|
+
/** Options, which is passed when forking a child or creating a thread */
|
|
116
|
+
clusterOptions?: ChildProcessOptions;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ClusterRestartOptions {
|
|
120
|
+
/** Maximum amount of restarts a cluster can have in the interval */
|
|
121
|
+
max: number;
|
|
122
|
+
/** Interval in milliseconds on which the current restarts amount of a cluster will be resetted */
|
|
123
|
+
interval: number;
|
|
124
|
+
/** Current Amount of restarts */
|
|
125
|
+
current?: number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface QueueOptions {
|
|
129
|
+
/** Whether the spawn queue be automatically managed */
|
|
130
|
+
auto: boolean;
|
|
131
|
+
/** Time to wait until next item */
|
|
132
|
+
timeout?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ClusterKillOptions {
|
|
136
|
+
reason?: string;
|
|
137
|
+
force: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface Plugin {
|
|
141
|
+
build(manager: ClusterManager): void;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Events
|
|
145
|
+
export interface ClusterManagerEvents {
|
|
146
|
+
clusterCreate: [cluster: Cluster];
|
|
147
|
+
clusterReady: [cluster: Cluster];
|
|
148
|
+
debug: [debugMessage: string];
|
|
149
|
+
clientRequest: [message: IPCMessage];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ClusterEvents {
|
|
153
|
+
message: [message: BaseMessage | any];
|
|
154
|
+
death: [cluster: Cluster, thread: any | undefined | null];
|
|
155
|
+
error: [error: Error];
|
|
156
|
+
spawn: [thread: any | undefined | null];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface ClusterClientEvents<DiscordClient> {
|
|
160
|
+
message: [message: BaseMessage | any];
|
|
161
|
+
ready: [clusterClient: ClusterClient<DiscordClient>];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type DjsDiscordClient = Client;
|