mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
some ws fixes
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { eventHandlers } from "../bot.ts";
|
||||
import { handlers } from "../handlers/mod.ts";
|
||||
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
||||
import { DiscordReady } from "../types/gateway/ready.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
@@ -7,16 +9,14 @@ import { ws } from "./ws.ts";
|
||||
|
||||
/** Handler for handling every message event from websocket. */
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export function handleOnMessage(message: any, shardId: number) {
|
||||
export async function handleOnMessage(message: any, shardId: number) {
|
||||
if (message instanceof ArrayBuffer) {
|
||||
message = new Uint8Array(message);
|
||||
}
|
||||
|
||||
if (message instanceof Uint8Array) {
|
||||
message = decompressWith(
|
||||
message,
|
||||
0,
|
||||
(slice: Uint8Array) => ws.utf8decoder.decode(slice),
|
||||
message = decompressWith(message, 0, (slice: Uint8Array) =>
|
||||
ws.utf8decoder.decode(slice)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function handleOnMessage(message: any, shardId: number) {
|
||||
case DiscordGatewayOpcodes.Hello:
|
||||
ws.heartbeat(
|
||||
shardId,
|
||||
(messageData.d as DiscordHeartbeat).heartbeat_interval,
|
||||
(messageData.d as DiscordHeartbeat).heartbeat_interval
|
||||
);
|
||||
break;
|
||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||
@@ -90,7 +90,16 @@ export function handleOnMessage(message: any, shardId: number) {
|
||||
}
|
||||
}
|
||||
|
||||
ws.handleDiscordPayload(messageData, shardId);
|
||||
if (ws.url) ws.handleDiscordPayload(messageData, shardId);
|
||||
else {
|
||||
eventHandlers.raw?.(messageData);
|
||||
await eventHandlers.dispatchRequirements?.(messageData, shardId);
|
||||
|
||||
if (messageData.op !== DiscordGatewayOpcodes.Dispatch) return;
|
||||
|
||||
return handlers[messageData.t]?.(messageData, shardId);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user