mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 12:36:08 +00:00
feat: workerClient.calculateShardId
This commit is contained in:
parent
b4324f9487
commit
23c9c2a710
@ -1,7 +1,14 @@
|
||||
import { type UUID, randomUUID } from 'node:crypto';
|
||||
import { ApiHandler, Logger } from '..';
|
||||
import { WorkerAdapter } from '../cache';
|
||||
import { type DeepPartial, LogLevels, type MakeRequired, type When, lazyLoadPackage } from '../common';
|
||||
import {
|
||||
type DeepPartial,
|
||||
LogLevels,
|
||||
type MakeRequired,
|
||||
type When,
|
||||
calculateShardId,
|
||||
lazyLoadPackage,
|
||||
} from '../common';
|
||||
import { EventHandler } from '../events';
|
||||
import type { GatewayDispatchPayload, GatewaySendPayload } from '../types';
|
||||
import { Shard, type ShardManagerOptions, ShardSocketCloseCodes, type WorkerData, properties } from '../websocket';
|
||||
@ -377,12 +384,18 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
||||
return this.onPacket(packet, shardId);
|
||||
};
|
||||
}
|
||||
workerData.totalShards = data.totalShards;
|
||||
workerData.shards = [...this.shards.keys()];
|
||||
this.resharding.clear();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
calculateShardId(guildId: string) {
|
||||
return calculateShardId(guildId, this.workerData.totalShards);
|
||||
}
|
||||
|
||||
private generateNonce(): UUID {
|
||||
const uuid = randomUUID();
|
||||
if (this.promises.has(uuid)) return this.generateNonce();
|
||||
@ -553,7 +566,7 @@ export function generateShardInfo(shard: Shard): WorkerShardInfo {
|
||||
};
|
||||
}
|
||||
|
||||
interface WorkerClientOptions extends BaseClientOptions {
|
||||
export interface WorkerClientOptions extends BaseClientOptions {
|
||||
commands?: NonNullable<Client['options']>['commands'];
|
||||
handlePayload?: ShardManagerOptions['handlePayload'];
|
||||
gateway?: ClientOptions['gateway'];
|
||||
|
@ -288,6 +288,7 @@ export class WorkerManager extends Map<
|
||||
for (const [id] of this.entries()) {
|
||||
this.postMessage(id, {
|
||||
type: 'CONNECT_ALL_SHARDS_RESHARDING',
|
||||
totalShards: this.options.totalShards,
|
||||
} satisfies ConnnectAllShardsResharding);
|
||||
}
|
||||
this.forEach(w => {
|
||||
@ -656,7 +657,12 @@ export type ManagerSpawnShardsResharding = CreateManagerMessage<
|
||||
Pick<ShardOptions, 'info' | 'properties' | 'compress'>
|
||||
>;
|
||||
export type DisconnectAllShardsResharding = CreateManagerMessage<'DISCONNECT_ALL_SHARDS_RESHARDING'>;
|
||||
export type ConnnectAllShardsResharding = CreateManagerMessage<'CONNECT_ALL_SHARDS_RESHARDING'>;
|
||||
export type ConnnectAllShardsResharding = CreateManagerMessage<
|
||||
'CONNECT_ALL_SHARDS_RESHARDING',
|
||||
{
|
||||
totalShards: number;
|
||||
}
|
||||
>;
|
||||
export type ManagerSendPayload = CreateManagerMessage<
|
||||
'SEND_PAYLOAD',
|
||||
GatewaySendPayload & { shardId: number; nonce: string }
|
||||
|
Loading…
x
Reference in New Issue
Block a user