mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import { getGatewayBot } from "../helpers/misc/get_gateway_bot.ts";
|
|
import { ws } from "./ws.ts";
|
|
|
|
/** The handler to automatically reshard when necessary. */
|
|
export async function resharder() {
|
|
ws.botGatewayData = await getGatewayBot();
|
|
|
|
const percentage =
|
|
((ws.botGatewayData.shards - ws.maxShards) / ws.maxShards) * 100;
|
|
// Less than necessary% being used so do nothing
|
|
if (percentage < ws.reshardPercentage) return;
|
|
|
|
// Don't have enough identify rate limits to reshard
|
|
if (
|
|
ws.botGatewayData.sessionStartLimit.remaining < ws.botGatewayData.shards
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// Begin resharding
|
|
ws.maxShards = ws.botGatewayData.shards;
|
|
// If more than 100K servers, begin switching to 16x sharding
|
|
if (ws.maxShards && ws.useOptimalLargeBotSharding) {
|
|
ws.maxShards = Math.ceil(
|
|
ws.maxShards /
|
|
(ws.botGatewayData.sessionStartLimit.maxConcurrency === 1
|
|
? 16
|
|
: ws.botGatewayData.sessionStartLimit.maxConcurrency),
|
|
);
|
|
}
|
|
|
|
ws.spawnShards(ws.firstShardId);
|
|
}
|