mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 04:56:07 +00:00
fix(Watcher): partial types
This commit is contained in:
parent
e38957ca55
commit
0cef3a9f6f
@ -111,7 +111,6 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
this.gateway = new ShardManager({
|
||||
token,
|
||||
info: await this.proxy.gateway.bot.get(),
|
||||
getInfo: () => this.proxy.gateway.bot.get(),
|
||||
intents,
|
||||
handlePayload: async (shardId, packet) => {
|
||||
await this.options?.handlePayload?.(shardId, packet);
|
||||
@ -128,6 +127,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
},
|
||||
compress: this.options?.gateway?.compress,
|
||||
resharding: {
|
||||
getInfo: () => this.proxy.gateway.bot.get(),
|
||||
interval: this.options?.resharding?.interval ?? 0,
|
||||
percentage: this.options?.resharding?.percentage ?? 0,
|
||||
reloadGuilds: ids => {
|
||||
|
@ -14,6 +14,8 @@ export interface WatcherOptions
|
||||
| 'totalShards'
|
||||
| 'url'
|
||||
| 'version'
|
||||
| 'resharding'
|
||||
| 'debug'
|
||||
> {
|
||||
filePath: string;
|
||||
transpileCommand: string;
|
||||
|
@ -21,7 +21,7 @@ export type DeepPartial<T> = {
|
||||
? DeepPartial<T[K]>
|
||||
: T[K] extends (infer I)[]
|
||||
? DeepPartial<I>[]
|
||||
: T[K];
|
||||
: Partial<T[K]>;
|
||||
};
|
||||
|
||||
export type OmitInsert<T, K extends keyof T, I> = I extends [] ? Omit<T, K> & I[number] : Omit<T, K> & I;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import type { DeepPartial } from '../../common';
|
||||
import type { GatewayDispatchPayload } from '../../types';
|
||||
import type { ShardManagerOptions, WorkerManagerOptions } from '../discord';
|
||||
|
||||
@ -9,7 +10,7 @@ const properties = {
|
||||
device: 'Seyfert',
|
||||
};
|
||||
|
||||
const ShardManagerDefaults: Partial<ShardManagerOptions> = {
|
||||
const ShardManagerDefaults: DeepPartial<ShardManagerOptions> = {
|
||||
totalShards: 1,
|
||||
spawnShardDelay: 5300,
|
||||
debug: false,
|
||||
@ -32,7 +33,7 @@ const ShardManagerDefaults: Partial<ShardManagerOptions> = {
|
||||
},
|
||||
};
|
||||
|
||||
const WorkerManagerDefaults: Partial<WorkerManagerOptions> = {
|
||||
const WorkerManagerDefaults: DeepPartial<WorkerManagerOptions> = {
|
||||
...ShardManagerDefaults,
|
||||
shardsPerWorker: 16,
|
||||
handlePayload: (_shardId: number, _workerId: number, _packet: GatewayDispatchPayload): void => {},
|
||||
|
@ -56,7 +56,7 @@ export class ShardManager extends Map<number, Shard> {
|
||||
if (this.options.resharding.interval <= 0) return;
|
||||
setInterval(async () => {
|
||||
this.debugger?.debug('Checking if reshard is needed');
|
||||
const info = await this.options.getInfo();
|
||||
const info = await this.options.resharding.getInfo();
|
||||
if (info.shards <= this.totalShards) return this.debugger?.debug('Resharding not needed');
|
||||
//https://github.com/discordeno/discordeno/blob/6a5f446c0651b9fad9f1550ff1857fe7a026426b/packages/gateway/src/manager.ts#L106C8-L106C94
|
||||
const percentage = (info.shards / ((this.totalShards * 2500) / 1000)) * 100;
|
||||
@ -104,6 +104,8 @@ export class ShardManager extends Map<number, Shard> {
|
||||
const resharder = new ShardManager({
|
||||
...this.options,
|
||||
resharding: {
|
||||
// getInfo mock, we don't need it
|
||||
getInfo: () => ({}) as any,
|
||||
interval: 0,
|
||||
percentage: 0,
|
||||
reloadGuilds() {},
|
||||
|
@ -8,7 +8,6 @@ import type { Awaitable, DeepPartial, Logger } from '../../common';
|
||||
import type { IdentifyProperties } from '../constants';
|
||||
|
||||
export interface ShardManagerOptions extends ShardDetails {
|
||||
getInfo(): Promise<APIGatewayBotInfo>;
|
||||
/** Important data which is used by the manager to connect shards to the gateway. */
|
||||
info: APIGatewayBotInfo;
|
||||
/**
|
||||
@ -38,6 +37,10 @@ export interface ShardManagerOptions extends ShardDetails {
|
||||
|
||||
compress?: boolean;
|
||||
resharding?: {
|
||||
/**
|
||||
* @returns the gateway connection info
|
||||
*/
|
||||
getInfo(): Promise<APIGatewayBotInfo>;
|
||||
interval: number;
|
||||
percentage: number;
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user