This commit is contained in:
Skillz4Killz
2022-03-31 13:50:25 +00:00
committed by GitHub
51 changed files with 494 additions and 371 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ export function createShard(gateway: GatewayManager, shardId: number) {
return;
case 3063: // Resharded
case 3064: // Resuming
case 3065: // Reidentifying
case 3065: // Re-identifying
case 3066: // Missing ACK
// Will restart shard manually
return gateway.debug("GW CLOSED_RECONNECT", { shardId, payload: event });
+1 -1
View File
@@ -73,7 +73,7 @@ export async function handleOnMessage(gateway: GatewayManager, message: any, sha
// We need to wait for a random amount of time between 1 and 5: https://discord.com/developers/docs/topics/gateway#resuming
await delay(Math.floor((Math.random() * 4 + 1) * 1000));
// When d is false we need to reidentify
// When d is false we need to re-identify
if (!messageData.d) {
await gateway.identify(gateway, shardId, gateway.maxShards);
break;
+1 -1
View File
@@ -7,7 +7,7 @@ export function identify(gateway: GatewayManager, shardId: number, maxShards: nu
// Need to clear the old heartbeat interval
const oldShard = gateway.shards.get(shardId);
if (oldShard) {
gateway.closeWS(oldShard.ws, 3065, "Reidentifying closure of old shard");
gateway.closeWS(oldShard.ws, 3065, "Re-identifying closure of old shard");
clearInterval(oldShard.heartbeat.intervalId);
}
+6 -6
View File
@@ -36,7 +36,7 @@ export async function resharder(
}
// USE ANY CUSTOMIZED OPTIONS FROM OLD GATEWAY
// @ts-ignore TODO: fix this dynamica assignment
// @ts-ignore TODO: fix this dynamical assignment
gateway[key] = oldGateway[key as keyof typeof oldGateway];
}
@@ -83,7 +83,7 @@ export async function resharder(
}) as Promise<GatewayManager>;
}
/** Handler that by default will check all new shards are online in the new gateway. The handler can be overriden if you have multiple servers to communicate through redis pubsub or whatever you prefer. */
/** Handler that by default will check all new shards are online in the new gateway. The handler can be overridden if you have multiple servers to communicate through redis pubsub or whatever you prefer. */
export async function resharderIsPending(
gateway: GatewayManager,
oldGateway: GatewayManager,
@@ -98,7 +98,7 @@ export async function resharderIsPending(
return false;
}
/** Handler that by default closes all shards in the old gateway. Can be overriden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */
/** Handler that by default closes all shards in the old gateway. Can be overridden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */
export async function resharderCloseOldShards(oldGateway: GatewayManager) {
// SHUT DOWN ALL SHARDS IF NOTHING IN QUEUE
oldGateway.shards.forEach((shard) => {
@@ -122,7 +122,7 @@ export async function resharderCloseOldShards(oldGateway: GatewayManager) {
});
}
/** Handler that by default will check to see if resharding should occur. Can be overriden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */
/** Handler that by default will check to see if resharding should occur. Can be overridden if you have multiple servers and you want to communicate through redis pubsub or whatever you prefer. */
export async function startReshardingChecks(gateway: GatewayManager) {
gateway.debug("GW DEBUG", "[Resharding] Checking if resharding is needed.");
@@ -144,9 +144,9 @@ export async function startReshardingChecks(gateway: GatewayManager) {
return gateway.resharding.resharder(gateway, results);
}
/** Handler that by default will save the new shard id for each guild this becomes ready in new gateway. This can be overriden to save the shard ids in a redis cache layer or whatever you prefer. These ids will be used later to update all guilds. */
/** Handler that by default will save the new shard id for each guild this becomes ready in new gateway. This can be overridden to save the shard ids in a redis cache layer or whatever you prefer. These ids will be used later to update all guilds. */
export async function markNewGuildShardId(guildIds: bigint[], shardId: number) {
// PLACEHOLDER TO LET YOU MARK A GUILD ID AND SHARDID FOR LATER USE ONCE RESHARDED
// PLACEHOLDER TO LET YOU MARK A GUILD ID AND SHARD ID FOR LATER USE ONCE RESHARDED
}
/** Handler that by default does not do anything since by default the library will not cache. */
+1 -1
View File
@@ -30,7 +30,7 @@ export interface DiscordenoShard {
/** The id of the interval, useful for stopping the interval if ws closed. */
intervalId: number;
};
/** The items/requestst that are in queue to be sent to this shard websocket. */
/** The items/requests that are in queue to be sent to this shard websocket. */
queue: WebSocketRequest[];
/** Whether or not the queue for this shard is being processed. */
processingQueue: boolean;