mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
17 lines
809 B
TypeScript
17 lines
809 B
TypeScript
import { GatewayManager } from './gatewayManager.ts';
|
|
|
|
/** Handler used to determine max number of shards to use based upon the max concurrency. */
|
|
export function calculateTotalShards(gateway: GatewayManager): number {
|
|
// Bots under 100k servers do not have access to total shards.
|
|
if (gateway.manager.totalShards < 100) return gateway.manager.totalShards;
|
|
|
|
// Calculate a multiple of `maxConcurrency` which can be used to connect to the gateway.
|
|
return Math.ceil(
|
|
gateway.manager.totalShards /
|
|
// If `maxConcurrency` is 1 we can safely use 16.
|
|
(gateway.gatewayBot.sessionStartLimit.maxConcurrency === 1
|
|
? 16
|
|
: gateway.gatewayBot.sessionStartLimit.maxConcurrency),
|
|
) * gateway.gatewayBot.sessionStartLimit.maxConcurrency;
|
|
}
|