diff --git a/src/helpers/guilds/get_widget.ts b/src/helpers/guilds/get_widget.ts index c685b8088..adcc4989d 100644 --- a/src/helpers/guilds/get_widget.ts +++ b/src/helpers/guilds/get_widget.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; +import { DiscordGuildWidget } from "../../types/guilds/guild_widget.ts"; import { Errors } from "../../types/misc/errors.ts"; import { endpoints } from "../../util/constants.ts"; @@ -11,6 +12,8 @@ export async function getWidget(guildId: string, options?: { force: boolean }) { if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED); } - // TODO: add return type - return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`); + return await rest.runMethod( + "get", + `${endpoints.GUILD_WIDGET(guildId)}.json`, + ); } diff --git a/src/types/guilds/modify_guild_welcome_screen.ts b/src/types/guilds/modify_guild_welcome_screen.ts index d983043af..f7757e761 100644 --- a/src/types/guilds/modify_guild_welcome_screen.ts +++ b/src/types/guilds/modify_guild_welcome_screen.ts @@ -10,7 +10,7 @@ export interface ModifyGuildWelcomeScreen { description?: string | null; } -// TODO: add documentation link +/** https://discord.com/developers/docs/resources/guild#modify-guild-welcome-screen */ export type DiscordModifyGuildWelcomeScreen = SnakeCasedPropertiesDeep< ModifyGuildWelcomeScreen >; diff --git a/src/types/guilds/update_others_voice_state.ts b/src/types/guilds/update_others_voice_state.ts index 6b4c5aa8f..deb0904f2 100644 --- a/src/types/guilds/update_others_voice_state.ts +++ b/src/types/guilds/update_others_voice_state.ts @@ -1,4 +1,4 @@ -import { SnakeCaseProps } from "../util.ts"; +import { SnakeCasedProperties } from "../util.ts"; export interface UpdateOthersVoiceState { /** The id of the channel the user is currently in */ @@ -7,7 +7,7 @@ export interface UpdateOthersVoiceState { suppress?: boolean; } -// TODO: add corresponding link to the resource -export type DiscordUpdateOthersVoiceState = SnakeCaseProps< +/** https://discord.com/developers/docs/resources/guild#update-user-voice-state */ +export type DiscordUpdateOthersVoiceState = SnakeCasedProperties< UpdateOthersVoiceState >; diff --git a/src/types/guilds/update_self_voice_state.ts b/src/types/guilds/update_self_voice_state.ts index 120b60c8e..fcc6fbda3 100644 --- a/src/types/guilds/update_self_voice_state.ts +++ b/src/types/guilds/update_self_voice_state.ts @@ -1,4 +1,4 @@ -import { SnakeCaseProps } from "../util.ts"; +import { SnakeCasedProperties } from "../util.ts"; export interface UpdateSelfVoiceState { /** The id of the channel the user is currently in */ @@ -9,5 +9,7 @@ export interface UpdateSelfVoiceState { requestToSpeakTimestamp?: string | null; } -// TODO: add corresponding link to the resource -export type DiscordUpdateSelfVoiceState = SnakeCaseProps; +/** https://discord.com/developers/docs/resources/guild#update-current-user-voice-state */ +export type DiscordUpdateSelfVoiceState = SnakeCasedProperties< + UpdateSelfVoiceState +>; diff --git a/src/ws/create_shard.ts b/src/ws/create_shard.ts index cecbc20a0..a4b90af7a 100644 --- a/src/ws/create_shard.ts +++ b/src/ws/create_shard.ts @@ -1,3 +1,4 @@ +import { DiscordGatewayCloseEventCodes } from "../types/codes/gateway_close_event_codes.ts"; import { identify } from "./identify.ts"; import { resume } from "./resume.ts"; import { ws } from "./ws.ts"; @@ -33,25 +34,24 @@ export async function createShard(shardId: number) { return ws.log("CLOSED_RECONNECT", { shardId, payload: event }); } - // TODO: ENUM FOR THESE CODES? switch (event.code) { - case 4001: - case 4002: - case 4004: - case 4005: - case 4010: - case 4011: - case 4012: - case 4013: - case 4014: + case DiscordGatewayCloseEventCodes.UnknownOpcode: + case DiscordGatewayCloseEventCodes.DecodeError: + case DiscordGatewayCloseEventCodes.AuthenticationFailed: + case DiscordGatewayCloseEventCodes.AlreadyAuthenticated: + case DiscordGatewayCloseEventCodes.InvalidShard: + case DiscordGatewayCloseEventCodes.ShardingRequired: + case DiscordGatewayCloseEventCodes.InvalidApiVersion: + case DiscordGatewayCloseEventCodes.InvalidIntents: + case DiscordGatewayCloseEventCodes.DisallowedIntents: throw new Error( event.reason || "Discord gave no reason! GG! You broke Discord!", ); // THESE ERRORS CAN NO BE RESUMED! THEY MUST RE-IDENTIFY! - case 4003: - case 4007: - case 4008: - case 4009: + case DiscordGatewayCloseEventCodes.NotAuthenticated: + case DiscordGatewayCloseEventCodes.InvalidSeq: + case DiscordGatewayCloseEventCodes.RateLimited: + case DiscordGatewayCloseEventCodes.SessionTimedOut: identify(shardId, ws.maxShards); break; default: