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