Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
"lint:fix": "eslint src --fix",
"prepack": "pnpm run build"
},
"dependencies": {
"@discordjs/ws": "^2.0.4"
},
"devDependencies": {
"@discordjs/ws": "^2.0.4",
"@types/node": "^25.9.1",
"@types/ws": "^8.18.1",
"discord.js": "^14.26.4",
Expand Down
3 changes: 2 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/client/ShardClientUtil.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import EventEmitter from "node:events";
import process from "node:process";
import { clearTimeout } from "node:timers";
import type { WebSocketManager } from "@discordjs/ws";
import type { Client } from "discord.js";
import type { Indomitable } from "../Indomitable.js";
import type { AbortableData, InternalOpsData, Message, SessionObject, Transportable } from "../Util.js";
import { EnvProcessData, MakeAbortableRequest, InternalOps } from "../Util.js";
import { ClientWorker } from "../ipc/ClientWorker.js";
import type { IndomitableShardingStrategyInterface } from "../strategies/IndomitableShardingStrategyInterface.js";

export interface ShardClientUtilEvents {
message: [message: Message];
Expand Down Expand Up @@ -53,6 +55,15 @@ export class ShardClientUtil extends EventEmitter<ShardClientUtilEvents> {
return Number(BigInt(end) - start);
}

/**
* Returns the current WebSocket sharding strategy.
*/
public get strategy(): IndomitableShardingStrategyInterface {
// @ts-expect-error internal field
// eslint-disable-next-line @typescript-eslint/dot-notation
return (this.client.ws["_ws"] as WebSocketManager).strategy;
}

/**
* Evaluates a script or function on all clusters in the context of the client
*
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./client/ShardClient.js";
export * from "./client/ShardClientUtil.js";
export * from "./concurrency/ConcurrencyManager.js";
export * from "./strategies/IndomitableWorkerShardingStrategy.js";
export * from "./ipc/BaseIpc.js";
export * from "./ipc/MainWorker.js";
export * from "./ipc/BaseWorker.js";
Expand Down
14 changes: 14 additions & 0 deletions src/strategies/IndomitableShardingStrategyInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* This file is adapted from discord.js and includes additional modifications.
*
* Original Apache 2.0 license:
* https://github.com/discordjs/discord.js/blob/3d6121589f9c0d91f7cf4976307e8be07053a277/LICENSE
*/
import type { IShardingStrategy, WebSocketShardDestroyOptions } from "@discordjs/ws";
import type { Awaitable } from "discord.js";
import type { WebsocketShardState } from "./IndomitableWorkerShardingStrategy";

export interface IndomitableShardingStrategyInterface extends Omit<IShardingStrategy, "fetchStatus"> {
destroyShards(shardIds: number[], options?: WebSocketShardDestroyOptions): Awaitable<void>;
fetchStatus(): Awaitable<Map<number, WebsocketShardState>>;
}
Loading
Loading