mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
feat: Internal sharding (#2902)
* internal sharding * ready event * the square deal * the new deal * the second new deal * add actual documentation * the new freedom * the great society * federal intervention * some of requested changes * i ran out of things to call these * destroy this * fix: Client#uptime went missing * fix(Client): destroy the client on login failure This may happen duo invalid sharding config / invalid token / user requested destroy * fix(Client): reject login promise when the client is destroyed before ready * fix(WebSocketManager): remove redundancy in destroy method (#2491) * typo(ErrorMessages): duo -> duo to * typo(ErrorMessages): duo -> due * fix: docs and options * docs(WebSocketManager): WebSockethard -> WebSocketShard (#2502) * fix(ClientUser): lazily load to account for extended user structure (#2501) * docs(WebSocketShard): document class to make it visible in documentation (#2504) * fix: WebSocketShard#reconnect * fix: presenceUpdate & userUpdate * presenceUpdate wasn't really being handled at all * userUpdate handled incorrectly because as of v7 in the Discord API, it comes inside presenceUpdate * re-add raw event * member is now part of message create payload * feat: Add functionality to support multiple servers with different shards (#2395) * Added functionallity to spawn multiple sharding managers due to adding start and end shards * Small fixes and limiting shard amount to max recommended * Forgot a check in spawn() * Fixed indentation * Removed optiosn object documentation for totalShards * More fixes and a check that the startShard + amount doesnt go over the recommended shard amount * fix getting max recommended * Removed async from constructor (my fault) * Changed start and end shard to a shardList or "auto" + fixed some brainfarts with isNaN * Changed the loop and totalShard count calculation * shards are actually 0 based * Fixed a problem with the gateway and handled some range errors and type errors * Changed Number.isNan to isNaN and changed a few Integer checks to use Number.isInteger * Added check if shardList contains smth greater than totalShards; made spawn use totalShards again; shardList will be ignored and rebuild if totalShards is 'auto'; fixed docs * ShardingManager#spawn now uses a for..of loop; fixed the if statement inside the new for..of loop to still work as intended; made the totalShards be set to a new amount if smth manual is put into ShardingManager#spawn just like before; Fixed some spelling * internal sharding * ready event * the square deal * the new deal * the second new deal * add actual documentation * the new freedom * the great society * federal intervention * some of requested changes * i ran out of things to call these * destroy this * fix: Client#uptime went missing * fix(Client): destroy the client on login failure This may happen duo invalid sharding config / invalid token / user requested destroy * fix(Client): reject login promise when the client is destroyed before ready * fix(WebSocketManager): remove redundancy in destroy method (#2491) * typo(ErrorMessages): duo -> duo to * typo(ErrorMessages): duo -> due * fix: docs and options * docs(WebSocketManager): WebSockethard -> WebSocketShard (#2502) * fix(ClientUser): lazily load to account for extended user structure (#2501) * docs(WebSocketShard): document class to make it visible in documentation (#2504) * fix: WebSocketShard#reconnect * fix: presenceUpdate & userUpdate * presenceUpdate wasn't really being handled at all * userUpdate handled incorrectly because as of v7 in the Discord API, it comes inside presenceUpdate * Internal Sharding adaptation Adapted to internal sharding Fixed a bug where non ready invalidated sessions wouldnt respawn * Fixed shardCount not retrieving * Fixing style removed unnecessary parenthesis * Fixing and rebasing lets hope i didnt dun hecklered it * Fixing my own retardation * Thanks git rebase * fix: assigning member in message create payload * fix: resumes * fix: IS wont give up reconnecting now * docs: add missing docs mostly * fix: found lost methods * fix: WebSocketManager#broadcast check if shard exists * fix: ShardClientUtil#id returning undefined * feat: handle new session rate limits (#2796) * feat: handle new session rate limits * i have no idea what i was doing last night * fix if statement weirdness * fix: re-add presence parsing from ClientOptions (#2893) * resolve conflicts * typings: missing typings * re-add missing linter rule * fix: replacing ClientUser wrongly * address unecessary performance waste * docs: missing disconnect event * fix(typings): Fix 2 issues with typings (#2909) * (Typings) Update typings to reflect current ClientOptions * fix(Typings) fixes a bug with Websockets and DOM Types * fix travis * feat: allow setting presence per shard * add WebSocketManager#shardX events * adjust typings, docs and performance issues * readjust shard events, now provide shardId parameter instead * fix: ready event should check shardCount, not actualShardCount * fix: re-add replayed parameter of Client#resume * fix(Sharding): fixes several things in Internal Sharding (#2914) * fix(Sharding) fixes several things in Internal Sharding * add default value for shards property * better implement checking for shards array * fix travis & some casing * split shard count into 2 words * update to latest Internal Sharding, fix requested changes * make sure totalShardCount is a number * fix comment * fix small typo * dynamically set totalShardCount if either shards or shardCount is provided * consistency: rename shardID to shardId * remove Client#shardIds * fix: typo in GuildIntegrationsUpdate handler * fix: incorrect packet data being passed in some events (#2919) * fix: edgecase of ShardingManager and totalShardCount (#2918) * fix: Client#userUpdate being passed wrong parameter and fix a potential edgecase of returning null in ClientUser#edit from this event * fix consistency and typings issues * consistency: shardId instances renamed to shardID * typings: fix typings regarding WebSocket * style(.eslintrc): remove additional whitespace * fix(Client): remove ondisconnect handler on timeout * docs(BaseClient): fix typo of Immediate * nitpick: typings, private fields and methods * typo: improve grammar a bit * fix: error assigning client in WebSocketManager * typo: actually spell milliseconds properly
This commit is contained in:
81
typings/index.d.ts
vendored
81
typings/index.d.ts
vendored
@@ -80,17 +80,20 @@ declare module 'discord.js' {
|
||||
|
||||
export class BaseClient extends EventEmitter {
|
||||
constructor(options?: ClientOptions);
|
||||
private _intervals: Set<NodeJS.Timer>;
|
||||
private _timeouts: Set<NodeJS.Timer>;
|
||||
private _intervals: Set<NodeJS.Timer>;
|
||||
private _immediates: Set<NodeJS.Immediate>;
|
||||
private readonly api: object;
|
||||
private rest: object;
|
||||
|
||||
public options: ClientOptions;
|
||||
public clearInterval(interval: NodeJS.Timer): void;
|
||||
public clearTimeout(timeout: NodeJS.Timer): void;
|
||||
public clearImmediate(timeout: NodeJS.Immediate): void;
|
||||
public destroy(): void;
|
||||
public setInterval(fn: Function, delay: number, ...args: any[]): NodeJS.Timer;
|
||||
public setTimeout(fn: Function, delay: number, ...args: any[]): NodeJS.Timer;
|
||||
public setImmediate(fn: Function, delay: number, ...args: any[]): NodeJS.Immediate;
|
||||
public toJSON(...props: { [key: string]: boolean | string }[]): object;
|
||||
}
|
||||
|
||||
@@ -133,31 +136,26 @@ declare module 'discord.js' {
|
||||
|
||||
export class Client extends BaseClient {
|
||||
constructor(options?: ClientOptions);
|
||||
private readonly _pingTimestamp: number;
|
||||
private actions: object;
|
||||
private manager: ClientManager;
|
||||
private voice: object;
|
||||
private ws: object;
|
||||
private _eval(script: string): any;
|
||||
private _pong(startTime: number): void;
|
||||
private _validateOptions(options?: ClientOptions): void;
|
||||
|
||||
public broadcasts: VoiceBroadcast[];
|
||||
public channels: ChannelStore;
|
||||
public readonly emojis: GuildEmojiStore;
|
||||
public guilds: GuildStore;
|
||||
public readonly ping: number;
|
||||
public pings: number[];
|
||||
public readyAt: Date;
|
||||
public readyAt: Date | null;
|
||||
public readonly readyTimestamp: number;
|
||||
public shard: ShardClientUtil;
|
||||
public readonly status: Status;
|
||||
public token: string;
|
||||
public readonly uptime: number;
|
||||
public user: ClientUser;
|
||||
public user: ClientUser | null;
|
||||
public users: UserStore;
|
||||
public readonly voiceConnections: Collection<Snowflake, VoiceConnection>;
|
||||
public ws: WebSocketManager;
|
||||
public createVoiceBroadcast(): VoiceBroadcast;
|
||||
public destroy(): void;
|
||||
public fetchApplication(): Promise<ClientApplication>;
|
||||
public fetchInvite(invite: InviteResolvable): Promise<Invite>;
|
||||
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
||||
@@ -171,7 +169,7 @@ declare module 'discord.js' {
|
||||
public on(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this;
|
||||
public on(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this;
|
||||
public on(event: 'debug' | 'warn', listener: (info: string) => void): this;
|
||||
public on(event: 'disconnect', listener: (event: any) => void): this;
|
||||
public on(event: 'disconnect', listener: (event: any, shardID: number) => void): this;
|
||||
public on(event: 'emojiCreate' | 'emojiDelete', listener: (emoji: GuildEmoji) => void): this;
|
||||
public on(event: 'emojiUpdate', listener: (oldEmoji: GuildEmoji, newEmoji: GuildEmoji) => void): this;
|
||||
public on(event: 'error', listener: (error: Error) => void): this;
|
||||
@@ -189,10 +187,12 @@ declare module 'discord.js' {
|
||||
public on(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this;
|
||||
public on(event: 'presenceUpdate', listener: (oldPresence: Presence | undefined, newPresence: Presence) => void): this;
|
||||
public on(event: 'rateLimit', listener: (rateLimitData: RateLimitData) => void): this;
|
||||
public on(event: 'ready' | 'reconnecting', listener: () => void): this;
|
||||
public on(event: 'resumed', listener: (replayed: number) => void): this;
|
||||
public on(event: 'ready', listener: () => void): this;
|
||||
public on(event: 'reconnecting', listener: (shardID: number) => void): this;
|
||||
public on(event: 'resumed', listener: (replayed: number, shardID: number) => void): this;
|
||||
public on(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this;
|
||||
public on(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this;
|
||||
public on(event: 'shardReady', listener: (shardID: number) => void): this;
|
||||
public on(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
|
||||
public on(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
|
||||
public on(event: 'voiceStateUpdate', listener: (oldState: VoiceState | undefined, newState: VoiceState) => void): this;
|
||||
@@ -203,7 +203,7 @@ declare module 'discord.js' {
|
||||
public once(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this;
|
||||
public once(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this;
|
||||
public once(event: 'debug' | 'warn', listener: (info: string) => void): this;
|
||||
public once(event: 'disconnect', listener: (event: any) => void): this;
|
||||
public once(event: 'disconnect', listener: (event: any, shardID: number) => void): this;
|
||||
public once(event: 'emojiCreate' | 'emojiDelete', listener: (emoji: GuildEmoji) => void): this;
|
||||
public once(event: 'emojiUpdate', listener: (oldEmoji: GuildEmoji, newEmoji: GuildEmoji) => void): this;
|
||||
public once(event: 'error', listener: (error: Error) => void): this;
|
||||
@@ -221,10 +221,12 @@ declare module 'discord.js' {
|
||||
public once(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this;
|
||||
public once(event: 'presenceUpdate', listener: (oldPresence: Presence | undefined, newPresence: Presence) => void): this;
|
||||
public once(event: 'rateLimit', listener: (rateLimitData: RateLimitData) => void): this;
|
||||
public once(event: 'ready' | 'reconnecting', listener: () => void): this;
|
||||
public once(event: 'resumed', listener: (replayed: number) => void): this;
|
||||
public once(event: 'ready', listener: () => void): this;
|
||||
public once(event: 'reconnecting', listener: (shardID: number) => void): this;
|
||||
public once(event: 'resumed', listener: (replayed: number, shardID: number) => void): this;
|
||||
public once(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this;
|
||||
public once(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this;
|
||||
public once(event: 'shardReady', listener: (shardID: number) => void): this;
|
||||
public once(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
|
||||
public once(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
|
||||
public once(event: 'voiceStateUpdate', listener: (oldState: VoiceState | undefined, newState: VoiceState) => void): this;
|
||||
@@ -252,18 +254,11 @@ declare module 'discord.js' {
|
||||
public toString(): string;
|
||||
}
|
||||
|
||||
class ClientManager {
|
||||
constructor(client: Client);
|
||||
public client: Client;
|
||||
public heartbeatInterval: number;
|
||||
public readonly status: number;
|
||||
public connectToWebSocket(token: string, resolve: Function, reject: Function): void;
|
||||
}
|
||||
|
||||
export interface ActivityOptions {
|
||||
name?: string;
|
||||
url?: string;
|
||||
type?: ActivityType | number;
|
||||
shardID?: number | number[];
|
||||
}
|
||||
|
||||
export class ClientUser extends User {
|
||||
@@ -275,7 +270,7 @@ declare module 'discord.js' {
|
||||
public setAFK(afk: boolean): Promise<Presence>;
|
||||
public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise<ClientUser>;
|
||||
public setPresence(data: PresenceData): Promise<Presence>;
|
||||
public setStatus(status: PresenceStatus): Promise<Presence>;
|
||||
public setStatus(status: PresenceStatus, shardID?: number | number[]): Promise<Presence>;
|
||||
public setUsername(username: string): Promise<ClientUser>;
|
||||
}
|
||||
|
||||
@@ -1289,6 +1284,31 @@ declare module 'discord.js' {
|
||||
constructor(id: string, token: string, options?: ClientOptions);
|
||||
}
|
||||
|
||||
export class WebSocketManager {
|
||||
constructor(client: Client);
|
||||
public readonly client: Client;
|
||||
public gateway: string | undefined;
|
||||
public readonly ping: number;
|
||||
public shards: WebSocketShard[];
|
||||
public sessionStartLimit: { total: number; remaining: number; reset_after: number; };
|
||||
public status: Status;
|
||||
public broadcast(packet: any): void;
|
||||
}
|
||||
|
||||
export class WebSocketShard extends EventEmitter {
|
||||
constructor(manager: WebSocketManager, id: number, oldShard?: WebSocketShard);
|
||||
public id: number;
|
||||
public readonly ping: number;
|
||||
public pings: number[];
|
||||
public status: Status;
|
||||
public manager: WebSocketManager;
|
||||
public send(data: object): void;
|
||||
|
||||
public on(event: 'ready', listener: () => void): this;
|
||||
|
||||
public once(event: 'ready', listener: () => void): this;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Stores
|
||||
@@ -1572,9 +1592,9 @@ declare module 'discord.js' {
|
||||
};
|
||||
|
||||
type ClientOptions = {
|
||||
presence?: PresenceData;
|
||||
shardId?: number;
|
||||
shards?: number | number[];
|
||||
shardCount?: number;
|
||||
totalShardCount?: number;
|
||||
messageCacheMaxSize?: number;
|
||||
messageCacheLifetime?: number;
|
||||
messageSweepInterval?: number;
|
||||
@@ -1582,7 +1602,9 @@ declare module 'discord.js' {
|
||||
disableEveryone?: boolean;
|
||||
restWsBridgeTimeout?: number;
|
||||
restTimeOffset?: number;
|
||||
retryLimit?: number,
|
||||
restSweepInterval?: number;
|
||||
retryLimit?: number;
|
||||
presence?: PresenceData;
|
||||
disabledEvents?: WSEventType[];
|
||||
ws?: WebSocketOptions;
|
||||
http?: HTTPOptions;
|
||||
@@ -1982,7 +2004,8 @@ declare module 'discord.js' {
|
||||
name?: string;
|
||||
type?: ActivityType | number;
|
||||
url?: string;
|
||||
}
|
||||
};
|
||||
shardID?: number | number[];
|
||||
};
|
||||
|
||||
type PresenceResolvable = Presence | UserResolvable | Snowflake;
|
||||
|
||||
Reference in New Issue
Block a user