Complete some TODOs

This commit is contained in:
ayntee
2021-04-30 16:03:26 +04:00
parent 6808328946
commit 379d332492
5 changed files with 28 additions and 23 deletions

View File

@@ -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<DiscordGuildWidget>(
"get",
`${endpoints.GUILD_WIDGET(guildId)}.json`,
);
}

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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<UpdateSelfVoiceState>;
/** https://discord.com/developers/docs/resources/guild#update-current-user-voice-state */
export type DiscordUpdateSelfVoiceState = SnakeCasedProperties<
UpdateSelfVoiceState
>;

View File

@@ -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: