mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
types: add gateway opcodes enum (#711)
* bring opcodes enum back * Update src/types/gateway/opcodes.ts Co-authored-by: ayntee <ayyantee@gmail.com> * DiscordGatewayOpcodes Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/** https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-opcodes */
|
||||
export enum DiscordGatewayOpcodes {
|
||||
Dispatch,
|
||||
Heartbeat,
|
||||
Identify,
|
||||
StatusUpdate,
|
||||
VoiceStateUpdate,
|
||||
Resume = 6,
|
||||
Reconnect,
|
||||
RequestGuildMembers,
|
||||
InvalidSession,
|
||||
Hello,
|
||||
HeartbeatACK,
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export * from "./emojis/create_guild_emoji.ts";
|
||||
export * from "./emojis/emoji.ts";
|
||||
export * from "./emojis/modify_guild_emoji.ts";
|
||||
export * from "./gateway.ts";
|
||||
export * from "./gateway/opcodes.ts";
|
||||
export * from "./invites/get_invite.ts";
|
||||
export * from "./invites/invite.ts";
|
||||
export * from "./invites/invite_metadata.ts";
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { encode } from "../../deps.ts";
|
||||
import { DiscordGatewayOpcodes } from "../types/mod.ts";
|
||||
import { basicShards, sendWS } from "../ws/shard.ts";
|
||||
import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";
|
||||
|
||||
@@ -11,7 +12,7 @@ export function editBotStatus(
|
||||
) {
|
||||
basicShards.forEach((shard) => {
|
||||
sendWS({
|
||||
op: GatewayOpcode.StatusUpdate,
|
||||
op: DiscordGatewayOpcodes.StatusUpdate,
|
||||
d: {
|
||||
since: null,
|
||||
afk: false,
|
||||
|
||||
+9
-8
@@ -5,6 +5,7 @@ import {
|
||||
DiscordHello,
|
||||
DiscordIdentify,
|
||||
} from "../types/gateway.ts";
|
||||
import { DiscordGatewayOpcodes } from "../types/mod.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
@@ -72,7 +73,7 @@ export function createShard(
|
||||
const messageData = JSON.parse(message);
|
||||
if (!messageData.t) eventHandlers.rawGateway?.(messageData);
|
||||
switch (messageData.op) {
|
||||
case GatewayOpcode.Hello:
|
||||
case DiscordGatewayOpcodes.Hello:
|
||||
if (!heartbeating.has(basicShard.id)) {
|
||||
await heartbeat(
|
||||
basicShard,
|
||||
@@ -82,17 +83,17 @@ export function createShard(
|
||||
);
|
||||
}
|
||||
break;
|
||||
case GatewayOpcode.HeartbeatACK:
|
||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||
heartbeating.set(shardID, true);
|
||||
break;
|
||||
case GatewayOpcode.Reconnect:
|
||||
case DiscordGatewayOpcodes.Reconnect:
|
||||
eventHandlers.debug?.(
|
||||
{ type: "gatewayReconnect", data: { shardID: basicShard.id } },
|
||||
);
|
||||
basicShard.needToResume = true;
|
||||
await resumeConnection(data, identifyPayload, basicShard.id);
|
||||
break;
|
||||
case GatewayOpcode.InvalidSession:
|
||||
case DiscordGatewayOpcodes.InvalidSession:
|
||||
eventHandlers.debug?.(
|
||||
{
|
||||
type: "gatewayInvalidSession",
|
||||
@@ -166,14 +167,14 @@ function identify(shard: BasicShard, payload: DiscordIdentify) {
|
||||
);
|
||||
|
||||
sendWS({
|
||||
op: GatewayOpcode.Identify,
|
||||
op: DiscordGatewayOpcodes.Identify,
|
||||
d: { ...payload, shard: [shard.id, payload.shard[1]] },
|
||||
}, shard.id);
|
||||
}
|
||||
|
||||
function resume(shard: BasicShard, payload: DiscordIdentify) {
|
||||
sendWS({
|
||||
op: GatewayOpcode.Resume,
|
||||
op: DiscordGatewayOpcodes.Resume,
|
||||
d: {
|
||||
token: payload.token,
|
||||
session_id: shard.sessionID,
|
||||
@@ -219,7 +220,7 @@ async function heartbeat(
|
||||
heartbeating.set(shard.id, false);
|
||||
|
||||
sendWS(
|
||||
{ op: GatewayOpcode.Heartbeat, d: shard.previousSequenceNumber },
|
||||
{ op: DiscordGatewayOpcodes.Heartbeat, d: shard.previousSequenceNumber },
|
||||
shard.id,
|
||||
);
|
||||
eventHandlers.debug?.(
|
||||
@@ -291,7 +292,7 @@ export async function requestGuildMembers(
|
||||
}
|
||||
|
||||
sendWS({
|
||||
op: GatewayOpcode.RequestGuildMembers,
|
||||
op: DiscordGatewayOpcodes.RequestGuildMembers,
|
||||
d: {
|
||||
guild_id: guildID,
|
||||
// If a query is provided use it, OR if a limit is NOT provided use ""
|
||||
|
||||
@@ -2,6 +2,7 @@ import { eventHandlers } from "../bot.ts";
|
||||
import { cache } from "../cache.ts";
|
||||
import { handlers } from "../handlers/mod.ts";
|
||||
import { Member } from "../structures/mod.ts";
|
||||
import { DiscordGatewayOpcodes } from "../types/mod.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { createShard, requestGuildMembers } from "./mod.ts";
|
||||
@@ -67,10 +68,10 @@ export async function handleDiscordPayload(
|
||||
await eventHandlers.dispatchRequirements?.(data, shardID);
|
||||
|
||||
switch (data.op) {
|
||||
case GatewayOpcode.HeartbeatACK:
|
||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||
// In case the user wants to listen to heartbeat responses
|
||||
return eventHandlers.heartbeat?.();
|
||||
case GatewayOpcode.Dispatch:
|
||||
case DiscordGatewayOpcodes.Dispatch:
|
||||
if (!data.t) return;
|
||||
// Run the appropriate handler for this event.
|
||||
return handlers[data.t]?.(data, shardID);
|
||||
|
||||
Reference in New Issue
Block a user