types: add gateway events types

This commit is contained in:
ayntee
2021-03-27 12:03:55 +04:00
parent 68c0aa4877
commit b1512e0334
30 changed files with 316 additions and 78 deletions

View File

@@ -1,9 +1,10 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleChannelCreate(data: DiscordPayload) {
const payload = data.d as ChannelCreatePayload;
export async function handleChannelCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
const channelStruct = await structures.createChannelStruct(payload);
await cacheHandlers.set("channels", channelStruct.id, channelStruct);

View File

@@ -1,8 +1,9 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleChannelDelete(data: DiscordPayload) {
const payload = data.d as ChannelCreatePayload;
export async function handleChannelDelete(data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
const cachedChannel = await cacheHandlers.get("channels", payload.id);
if (!cachedChannel) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordChannelPinsUpdate,
DiscordGatewayPayload,
} from "../../types/gateway.ts";
export async function handleChannelPinsUpdate(data: DiscordPayload) {
const payload = data.d as DiscordChannelPinsUpdateEvent;
export async function handleChannelPinsUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannelPinsUpdate;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (!channel) return;

View File

@@ -1,9 +1,10 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleChannelUpdate(data: DiscordPayload) {
const payload = data.d as ChannelCreatePayload;
export async function handleChannelUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
const cachedChannel = await cacheHandlers.get("channels", payload.id);
const channelStruct = await structures.createChannelStruct(payload);

View File

@@ -1,9 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { Collection } from "../../util/collection.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildEmojisUpdate,
} from "../../types/gateway.ts";
import { Collection } from "../../util/collection.ts";
export async function handleGuildEmojisUpdate(data: DiscordPayload) {
const payload = data.d as GuildEmojisUpdatePayload;
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildEmojisUpdate;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildBanAddRemove,
} from "../../types/gateway.ts";
export async function handleGuildBanAdd(data: DiscordPayload) {
const payload = data.d as GuildBanPayload;
export async function handleGuildBanAdd(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildBanAddRemove;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildBanAddRemove,
} from "../../types/gateway.ts";
export async function handleGuildBanRemove(data: DiscordPayload) {
const payload = data.d as GuildBanPayload;
export async function handleGuildBanRemove(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildBanAddRemove;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,18 +1,19 @@
import { eventHandlers } from "../../bot.ts";
import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
import { basicShards } from "../../ws/shard.ts";
export async function handleGuildCreate(
data: DiscordPayload,
data: DiscordGatewayPayload,
shardID: number,
) {
const payload = data.d as CreateGuildPayload;
const payload = data.d as DiscordGuild;
// When shards resume they emit GUILD_CREATE again.
if (await cacheHandlers.has("guilds", payload.id)) return;
const guildStruct = await structures.createGuildStruct(
data.d as CreateGuildPayload,
data.d,
shardID,
);
await cacheHandlers.set("guilds", guildStruct.id, guildStruct);

View File

@@ -1,12 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
import { basicShards } from "../../ws/shard.ts";
export async function handleGuildDelete(
data: DiscordPayload,
data: DiscordGatewayPayload,
shardID: number,
) {
const payload = data.d as GuildDeletePayload;
const payload = data.d as DiscordUnavailableGuild;
const guild = await cacheHandlers.get("guilds", payload.id);
if (!guild) return;

View File

@@ -1,10 +1,14 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildIntegrationsUpdate,
} from "../../types/gateway.ts";
export async function handleGuildIntegrationsUpdate(
data: DiscordPayload,
data: DiscordGatewayPayload,
) {
const payload = data.d as DiscordGuildIntegrationsUpdateEvent;
const payload = data.d as DiscordGuildIntegrationsUpdate;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,8 +1,9 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleGuildUpdate(data: DiscordPayload) {
const payload = data.d as UpdateGuildPayload;
export async function handleGuildUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuild;
const cachedGuild = await cacheHandlers.get("guilds", payload.id);
if (!cachedGuild) return;

View File

@@ -1,9 +1,13 @@
import { cache, cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordGuildMembersChunk,
} from "../../types/gateway.ts";
import { Collection } from "../../util/collection.ts";
export async function handleGuildMembersChunk(data: DiscordPayload) {
const payload = data.d as GuildMemberChunkPayload;
export async function handleGuildMembersChunk(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMembersChunk;
const members = await Promise.all(
payload.members.map(async (member) => {

View File

@@ -1,9 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordGuildMemberAdd,
} from "../../types/gateway.ts";
export async function handleGuildMemberAdd(data: DiscordPayload) {
const payload = data.d as GuildMemberAddPayload;
export async function handleGuildMemberAdd(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberAdd;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildMemberRemove,
} from "../../types/gateway.ts";
export async function handleGuildMemberRemove(data: DiscordPayload) {
const payload = data.d as GuildBanPayload;
export async function handleGuildMemberRemove(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberRemove;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,9 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordGuildMemberUpdate,
} from "../../types/gateway.ts";
export async function handleGuildMemberUpdate(data: DiscordPayload) {
const payload = data.d as GuildMemberUpdatePayload;
export async function handleGuildMemberUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberUpdate;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;
@@ -31,7 +35,7 @@ export async function handleGuildMemberUpdate(data: DiscordPayload) {
eventHandlers.nicknameUpdate?.(
guild,
memberStruct,
payload.nick,
payload.nick!,
guildMember?.nick,
);
}

View File

@@ -1,9 +1,10 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleMessageCreate(data: DiscordPayload) {
const payload = data.d as MessageCreateOptions;
export async function handleMessageCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (channel) channel.lastMessageID = payload.id;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordMessageDelete,
} from "../../types/gateway.ts";
export async function handleMessageDelete(data: DiscordPayload) {
const payload = data.d as MessageDeletePayload;
export async function handleMessageDelete(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageDelete;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (!channel) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordMessageDeleteBulk,
} from "../../types/gateway.ts";
export async function handleMessageDeleteBulk(data: DiscordPayload) {
const payload = data.d as MessageDeleteBulkPayload;
export async function handleMessageDeleteBulk(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageDeleteBulk;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (!channel) return;

View File

@@ -1,9 +1,13 @@
import { botID, eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordMessageReactionAdd,
} from "../../types/gateway.ts";
export async function handleMessageReactionAdd(data: DiscordPayload) {
const payload = data.d as MessageReactionPayload;
export async function handleMessageReactionAdd(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageReactionAdd;
const message = await cacheHandlers.get("messages", payload.message_id);
if (message) {

View File

@@ -1,11 +1,15 @@
import { botID, eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordMessageReactionRemove,
} from "../../types/gateway.ts";
export async function handleMessageReactionRemove(
data: DiscordPayload,
data: DiscordGatewayPayload,
) {
const payload = data.d as MessageReactionPayload;
const payload = data.d as DiscordMessageReactionRemove;
const message = await cacheHandlers.get("messages", payload.message_id);
if (message) {

View File

@@ -1,10 +1,14 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordMessageReactionRemoveAll,
} from "../../types/gateway.ts";
export async function handleMessageReactionRemoveAll(
data: DiscordPayload,
data: DiscordGatewayPayload,
) {
const payload = data.d as BaseMessageReactionPayload;
const payload = data.d as DiscordMessageReactionRemoveAll;
const message = await cacheHandlers.get("messages", payload.message_id);
if (message?.reactions) {
@@ -13,5 +17,5 @@ export async function handleMessageReactionRemoveAll(
await cacheHandlers.set("messages", payload.message_id, message);
}
eventHandlers.reactionRemoveAll?.(data.d as BaseMessageReactionPayload);
eventHandlers.reactionRemoveAll?.(data.d);
}

View File

@@ -1,10 +1,14 @@
import { botID, eventHandlers } from "../../bot.ts";
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordMessageReactionRemoveEmoji,
} from "../../types/gateway.ts";
export async function handleMessageReactionRemoveEmoji(
data: DiscordPayload,
data: DiscordGatewayPayload,
) {
const payload = data.d as MessageReactionRemoveEmojiPayload;
const payload = data.d as DiscordMessageReactionRemoveEmoji;
const message = await cacheHandlers.get("messages", payload.message_id);
if (message?.reactions) {
@@ -20,6 +24,6 @@ export async function handleMessageReactionRemoveEmoji(
}
eventHandlers.reactionRemoveEmoji?.(
data.d as MessageReactionRemoveEmojiPayload,
data.d,
);
}

View File

@@ -1,9 +1,10 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handleMessageUpdate(data: DiscordPayload) {
const payload = data.d as MessageCreateOptions;
export async function handleMessageUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
const channel = await cacheHandlers.get("channels", payload.channel_id);
if (!channel) return;

View File

@@ -1,7 +1,8 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { DiscordGatewayPayload } from "../../types/gateway.ts";
export async function handlePresenceUpdate(data: DiscordPayload) {
export async function handlePresenceUpdate(data: DiscordGatewayPayload) {
const payload = data.d as PresenceUpdatePayload;
const oldPresence = await cacheHandlers.get("presences", payload.user.id);
await cacheHandlers.set("presences", payload.user.id, payload);

View File

@@ -7,17 +7,18 @@ import {
import { cache, cacheHandlers } from "../../cache.ts";
import { initialMemberLoadQueue } from "../../structures/guild.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayPayload, DiscordReady } from "../../types/gateway.ts";
import { delay } from "../../util/utils.ts";
import { allowNextShard, basicShards } from "../../ws/mod.ts";
export async function handleReady(
data: DiscordPayload,
data: DiscordGatewayPayload,
shardID: number,
) {
// The bot has already started, the last shard is resumed, however.
if (cache.isReady) return;
const payload = data.d as ReadyPayload;
const payload = data.d as DiscordReady;
setBotID(payload.user.id);
setApplicationID(payload.application.id);
@@ -44,7 +45,7 @@ export async function handleReady(
// Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event
/** This function checks if the shard is fully loaded */
function checkReady(payload: ReadyPayload, shardID: number, now: number) {
function checkReady(payload: DiscordReady, shardID: number, now: number) {
const shard = basicShards.get(shardID);
if (!shard) return;

View File

@@ -1,9 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordGuildRoleCreateUpdate,
} from "../../types/gateway.ts";
export async function handleGuildRoleCreate(data: DiscordPayload) {
const payload = data.d as GuildRolePayload;
export async function handleGuildRoleCreate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleCreateUpdate;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,8 +1,12 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import {
DiscordGatewayPayload,
DiscordGuildRoleDelete,
} from "../../types/gateway.ts";
export async function handleGuildRoleDelete(data: DiscordPayload) {
const payload = data.d as GuildRoleDeletePayload;
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleDelete;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -1,9 +1,13 @@
import { eventHandlers } from "../../bot.ts";
import { structures } from "../../structures/mod.ts";
import { cacheHandlers } from "../../cache.ts";
import { structures } from "../../structures/mod.ts";
import {
DiscordGatewayPayload,
DiscordGuildRoleCreateUpdate,
} from "../../types/gateway.ts";
export async function handleGuildRoleUpdate(data: DiscordPayload) {
const payload = data.d as GuildRolePayload;
export async function handleGuildRoleUpdate(data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleCreateUpdate;
const guild = await cacheHandlers.get("guilds", payload.guild_id);
if (!guild) return;

View File

@@ -228,7 +228,7 @@ export interface DiscordGuildBanAddRemove {
}
/** https://discord.com/developers/docs/topics/gateway#guild-emojis-update */
export interface GuildEmojisUpdate {
export interface DiscordGuildEmojisUpdate {
/** id of the guild */
guild_id: string;
/** Array of emojis */
@@ -236,7 +236,7 @@ export interface GuildEmojisUpdate {
}
/** https://discord.com/developers/docs/topics/gateway#guild-integrations-update */
export interface DiscordIntegrationsUpdate {
export interface DiscordGuildIntegrationsUpdate {
/** id of the guild whose integrations were updated */
guild_id: string;
}
@@ -247,6 +247,156 @@ export interface DiscordGuildMemberAdd extends DiscordMember {
guild_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-remove */
export interface DiscordGuildMemberRemove {
/** The id of the guild */
guild_id: string;
/** The user who was removed */
user: DiscordUser;
}
/** https://discord.com/developers/docs/topics/gateway#guild-member-update */
export interface DiscordGuildMemberUpdate {
/** The id of the guild */
guild_id: string;
/** User role ids */
roles: string[];
/** The user */
user: DiscordUser;
/** Nickname of the user in the guild */
nick?: string | null;
/** When the user joined the guild */
joined_at: string;
/** When the user starting boosting the guild */
premium_since?: string | null;
/** Whether the user has not yet passed the guild's Membership Screening requirements */
pending?: boolean;
}
/** https://discord.com/developers/docs/topics/gateway#guild-members-chunk */
export interface DiscordGuildMembersChunk {
/** The id of the guild */
guild_id: string;
/** Set of guild members */
members: DiscordMember[];
/** The chunk index in the expected chunks for this response (0 <= chunk_index < chunk_count) */
chunk_index: number;
/** The total number of expected chunks for this response */
chunk_count: number;
/** If passing an invalid id to `REQUEST_GUILD_MEMBERS`, it will be returned here */
not_found?: string[];
/** If passing true to `REQUEST_GUILD_MEMBERS`, presences of the returned members will be here */
presences?: DiscordPresence[];
/** The nonce used in the Guild Members Request */
nonce?: string;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-create */
export interface DiscordGuildRoleCreateUpdate {
/** The id of the guild */
guild_id: string;
/** The role created/updated */
role: DiscordRole;
}
/** https://discord.com/developers/docs/topics/gateway#guild-role-delete */
export interface DiscordGuildRoleDelete {
/** id of the guild */
guild_id: string;
/** id of the role */
role_id: string;
}
/** https://discord.com/developers/docs/topics/gateway#invite-create */
export interface DiscordInviteCreate {
/** The channel the invite is for */
channel_id: string;
/** The unique invite code */
code: string;
/** The time at which the invite was created */
created_at: string;
/** The guild of the invite */
guild_id?: string;
/** The user that created the invite */
inviter?: DiscordUser;
/** How long the invite is valid for (in seconds) */
max_age: number;
/** The maximum number of times the invite can be used */
max_uses: number;
/** The target user for this invite */
target_user?: Partial<DiscordUser>;
/** The type of user target for this invite */
target_user_type?: number;
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
temporary: boolean;
/** How many times the invite has been used (always will be 0) */
uses: number;
}
/** https://discord.com/developers/docs/topics/gateway#invite-delete */
export interface DiscordInviteDelete {
/** The channel of the invite */
channel_id: string;
/** The guild of the invite */
guild_id?: string;
/** The unique invite code */
code: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete */
export interface DiscordMessageDelete {
/** The id of the message */
id: string;
/** The id of the channel */
channel_id: string;
/** The id of the guild */
guild_id?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
export interface DiscordMessageDeleteBulk {
/** The ids of the messages */
ids: string[];
/** The id of the channel */
channel_id: string;
/** The id of the guild */
guild_id?: string;
}
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
export interface DiscordMessageReactionAdd {
/** The id of the user */
user_id: string;
/** The id of the channel */
channel_id: string;
/** The id of the message */
message_id: string;
/** The id of the guild */
guild_id?: string;
/** The member who reacted if this happened in a guild */
member?: DiscordMember;
/** The emoji used to react */
emoji: Partial<DiscordEmoji>;
}
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
export type DiscordMessageReactionRemove = Omit<
DiscordMessageReactionAdd,
"member"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
export type DiscordMessageReactionRemoveAll = Pick<
DiscordMessageReactionAdd,
"channel_id" | "message_id" | "guild_id"
>;
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-emoji */
export type DiscordMessageReactionRemoveEmoji = Pick<
DiscordMessageReactionAdd,
"channel_id" | "guild_id" | "message_id" | "emoji"
>;
/** https://discord.com/developers/docs/topics/gateway#get-gateway-bot */
export interface DiscordGetGatewayBot {
/** The WSS URL that can be used for connecting to the gateway */

View File

@@ -1,4 +1,10 @@
import { botGatewayData, eventHandlers, proxyWSURL } from "../bot.ts";
import {
DiscordGatewayPayload,
DiscordGetGatewayBot,
DiscordHello,
DiscordIdentify,
} from "../types/gateway.ts";
import { Collection } from "../util/collection.ts";
import { delay } from "../util/utils.ts";
import { decompressWith } from "./deps.ts";
@@ -70,7 +76,7 @@ export function createShard(
if (!heartbeating.has(basicShard.id)) {
await heartbeat(
basicShard,
(messageData.d as DiscordHeartbeatPayload).heartbeat_interval,
(messageData.d as DiscordHello).heartbeat_interval,
identifyPayload,
data,
);
@@ -180,7 +186,7 @@ async function heartbeat(
shard: BasicShard,
interval: number,
payload: DiscordIdentify,
data: DiscordBotGatewayData,
data: DiscordGetGatewayBot,
) {
// We lost socket connection between heartbeats, resume connection
if (shard.ws.readyState === WebSocket.CLOSED) {
@@ -231,7 +237,7 @@ async function heartbeat(
}
async function resumeConnection(
data: DiscordBotGatewayData,
data: DiscordGetGatewayBot,
payload: DiscordIdentify,
shardID: number,
) {
@@ -361,7 +367,7 @@ async function processGatewayQueue() {
}
/** Enqueues the specified data to be transmitted to the server over the WebSocket connection, */
export function sendWS(payload: DiscordPayload, shardID = 0) {
export function sendWS(payload: DiscordGatewayPayload, shardID = 0) {
const shard = basicShards.get(shardID);
if (!shard) return false;