mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 08:50:07 +00:00
Merge pull request #777 from itohatweb/fix-ready-thing
fix(handlers): ready
This commit is contained in:
@@ -13,7 +13,6 @@ export let eventHandlers: EventHandlers = {};
|
||||
|
||||
export let botGatewayData: DiscordGetGatewayBot;
|
||||
export let proxyWSURL = `wss://gateway.discord.gg`;
|
||||
export let lastShardId = 0;
|
||||
|
||||
export const identifyPayload = {
|
||||
token: "",
|
||||
@@ -58,8 +57,7 @@ export async function startBot(config: BotConfig) {
|
||||
: next),
|
||||
0,
|
||||
);
|
||||
lastShardId = botGatewayData.shards;
|
||||
identifyPayload.shard = [0, lastShardId];
|
||||
identifyPayload.shard = [0, botGatewayData.shards];
|
||||
|
||||
ws.spawnShards();
|
||||
}
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
import {
|
||||
eventHandlers,
|
||||
lastShardId,
|
||||
setApplicationId,
|
||||
setBotId,
|
||||
} from "../../bot.ts";
|
||||
import { eventHandlers, setApplicationId, setBotId } from "../../bot.ts";
|
||||
import { cache, cacheHandlers } from "../../cache.ts";
|
||||
import { initialMemberLoadQueue } from "../../structures/guild.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import { DiscordReady } from "../../types/gateway/ready.ts";
|
||||
import { delay, snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
export async function handleReady(
|
||||
@@ -73,7 +68,7 @@ async function loaded(shardId: number) {
|
||||
shard.ready = true;
|
||||
|
||||
// If it is the last shard we can go full ready
|
||||
if (shardId === lastShardId - 1) {
|
||||
if (shardId === ws.lastShardId - 1) {
|
||||
// Still some shards are loading so wait another 2 seconds for them
|
||||
if (ws.shards.some((shard) => !shard.ready)) {
|
||||
setTimeout(() => loaded(shardId), 2000);
|
||||
@@ -86,7 +81,7 @@ async function loaded(shardId: number) {
|
||||
await Promise.allSettled(
|
||||
members.map(async (member) => {
|
||||
const memberStruct = await structures.createMemberStruct(
|
||||
member,
|
||||
snakeKeysToCamelCase(member),
|
||||
guildId,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts";
|
||||
import { DiscordenoShard } from "./ws.ts";
|
||||
|
||||
/** The handler for logging different actions happening inside the ws. User can override and put custom handling per event. */
|
||||
@@ -35,7 +36,7 @@ export function log(
|
||||
): unknown;
|
||||
export function log(
|
||||
type: "INVALID_SESSION",
|
||||
data: { shardId: number; payload: DiscordPayload },
|
||||
data: { shardId: number; payload: DiscordGatewayPayload },
|
||||
): unknown;
|
||||
export function log(type: "RAW", data: Record<string, unknown>): unknown;
|
||||
export function log(type: "RECONNECT", data: { shardId: number }): unknown;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts";
|
||||
import { ws } from "./ws.ts";
|
||||
|
||||
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
||||
export async function handleDiscordPayload(
|
||||
data: DiscordPayload,
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number,
|
||||
) {
|
||||
await fetch(ws.url, {
|
||||
|
||||
@@ -15,6 +15,7 @@ export async function identify(shardId: number, maxShards: number) {
|
||||
sessionId: "",
|
||||
previousSequenceNumber: 0,
|
||||
resuming: false,
|
||||
ready: false,
|
||||
unavailableGuildIds: new Set(),
|
||||
heartbeat: {
|
||||
lastSentAt: 0,
|
||||
|
||||
@@ -28,6 +28,7 @@ export async function resume(shardId: number) {
|
||||
sessionId,
|
||||
previousSequenceNumber,
|
||||
resuming: false,
|
||||
ready: false,
|
||||
unavailableGuildIds: new Set(),
|
||||
heartbeat: {
|
||||
lastSentAt: 0,
|
||||
|
||||
@@ -116,6 +116,8 @@ export interface DiscordenoShard {
|
||||
previousSequenceNumber: number | null;
|
||||
/** Whether the shard is currently resuming. */
|
||||
resuming: boolean;
|
||||
/** Whether the shard has received the ready event */
|
||||
ready: boolean;
|
||||
/** The list of guild ids that are currently unavailable due to an outage. */
|
||||
unavailableGuildIds: Set<string>;
|
||||
heartbeat: {
|
||||
|
||||
Reference in New Issue
Block a user