From 819d85207ae7e07322e404a5ef9e3eb283b4aa03 Mon Sep 17 00:00:00 2001 From: Walter Min <60995055+Saghetti0@users.noreply.github.com> Date: Wed, 27 Dec 2023 04:22:42 -0800 Subject: [PATCH] fix(GatewayThreadDispatch): properly type thread create/update/delete dispatches (#861) * fix: properly type thread create/update/delete dispatches * fix(GatewayThreadDispatch): deno types * fix(GatewayThreadDispatch): deprecate GatewayThreadModifyDispatch --- deno/gateway/v10.ts | 47 +++++++++++++++++++++++++++++++++++++++------ deno/gateway/v9.ts | 47 +++++++++++++++++++++++++++++++++++++++------ gateway/v10.ts | 47 +++++++++++++++++++++++++++++++++++++++------ gateway/v9.ts | 47 +++++++++++++++++++++++++++++++++++++++------ 4 files changed, 164 insertions(+), 24 deletions(-) diff --git a/deno/gateway/v10.ts b/deno/gateway/v10.ts index e30c673d..73b5b035 100644 --- a/deno/gateway/v10.ts +++ b/deno/gateway/v10.ts @@ -34,6 +34,7 @@ import type { AutoModerationRuleTriggerType, APIAuditLogEntry, APIEntitlement, + ChannelType, } from '../payloads/v10/mod.ts'; import type { Nullable } from '../utils/internals.ts'; @@ -339,7 +340,9 @@ export type GatewayDispatchPayload = | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch - | GatewayThreadModifyDispatch + | GatewayThreadCreateDispatch + | GatewayThreadUpdateDispatch + | GatewayThreadDeleteDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch @@ -1608,6 +1611,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload< export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake }; /** + * @deprecated This type doesn't accurately reflect the Discord API. + * Use {@apilink GatewayThreadCreateDispatch}, + * {@apilink GatewayThreadUpdateDispatch}, or + * {@apilink GatewayThreadDeleteDispatch} instead. * https://discord.com/developers/docs/topics/gateway-events#thread-create * https://discord.com/developers/docs/topics/gateway-events#thread-update * https://discord.com/developers/docs/topics/gateway-events#thread-delete @@ -1620,7 +1627,10 @@ export type GatewayThreadModifyDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway-events#thread-create */ -export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadCreateDispatch = DataPayload< + GatewayDispatchEvents.ThreadCreate, + GatewayThreadCreateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-create @@ -1635,22 +1645,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel { /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadUpdateDispatch = DataPayload< + GatewayDispatchEvents.ThreadUpdate, + GatewayThreadUpdateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData; +export type GatewayThreadUpdateDispatchData = APIThreadChannel; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadDeleteDispatch = DataPayload< + GatewayDispatchEvents.ThreadDelete, + GatewayThreadDeleteDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData; +export interface GatewayThreadDeleteDispatchData { + /** + * The id of the channel + */ + id: Snowflake; + /** + * The id of the guild + */ + guild_id: Snowflake; + /** + * The id of the parent channel of the thread + */ + parent_id: Snowflake; + /** + * The type of the channel + * + * See https://discord.com/developers/docs/resources/channel#channel-object-channel-types + */ + type: ChannelType; +} /** * https://discord.com/developers/docs/topics/gateway-events#typing-start diff --git a/deno/gateway/v9.ts b/deno/gateway/v9.ts index b24173f9..2ad370bf 100644 --- a/deno/gateway/v9.ts +++ b/deno/gateway/v9.ts @@ -33,6 +33,7 @@ import type { PresenceUpdateStatus, AutoModerationRuleTriggerType, APIAuditLogEntry, + ChannelType, } from '../payloads/v9/mod.ts'; import type { Nullable } from '../utils/internals.ts'; import type { APIEntitlement } from '../v10.ts'; @@ -338,7 +339,9 @@ export type GatewayDispatchPayload = | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch - | GatewayThreadModifyDispatch + | GatewayThreadCreateDispatch + | GatewayThreadUpdateDispatch + | GatewayThreadDeleteDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch @@ -1607,6 +1610,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload< export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake }; /** + * @deprecated This type doesn't accurately reflect the Discord API. + * Use {@apilink GatewayThreadCreateDispatch}, + * {@apilink GatewayThreadUpdateDispatch}, or + * {@apilink GatewayThreadDeleteDispatch} instead. * https://discord.com/developers/docs/topics/gateway-events#thread-create * https://discord.com/developers/docs/topics/gateway-events#thread-update * https://discord.com/developers/docs/topics/gateway-events#thread-delete @@ -1619,7 +1626,10 @@ export type GatewayThreadModifyDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway-events#thread-create */ -export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadCreateDispatch = DataPayload< + GatewayDispatchEvents.ThreadCreate, + GatewayThreadCreateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-create @@ -1634,22 +1644,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel { /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadUpdateDispatch = DataPayload< + GatewayDispatchEvents.ThreadUpdate, + GatewayThreadUpdateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData; +export type GatewayThreadUpdateDispatchData = APIThreadChannel; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadDeleteDispatch = DataPayload< + GatewayDispatchEvents.ThreadDelete, + GatewayThreadDeleteDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData; +export interface GatewayThreadDeleteDispatchData { + /** + * The id of the channel + */ + id: Snowflake; + /** + * The id of the guild + */ + guild_id: Snowflake; + /** + * The id of the parent channel of the thread + */ + parent_id: Snowflake; + /** + * The type of the channel + * + * See https://discord.com/developers/docs/resources/channel#channel-object-channel-types + */ + type: ChannelType; +} /** * https://discord.com/developers/docs/topics/gateway-events#typing-start diff --git a/gateway/v10.ts b/gateway/v10.ts index b8a8e035..8ed2c034 100644 --- a/gateway/v10.ts +++ b/gateway/v10.ts @@ -34,6 +34,7 @@ import type { AutoModerationRuleTriggerType, APIAuditLogEntry, APIEntitlement, + ChannelType, } from '../payloads/v10/index'; import type { Nullable } from '../utils/internals'; @@ -339,7 +340,9 @@ export type GatewayDispatchPayload = | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch - | GatewayThreadModifyDispatch + | GatewayThreadCreateDispatch + | GatewayThreadUpdateDispatch + | GatewayThreadDeleteDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch @@ -1608,6 +1611,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload< export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake }; /** + * @deprecated This type doesn't accurately reflect the Discord API. + * Use {@apilink GatewayThreadCreateDispatch}, + * {@apilink GatewayThreadUpdateDispatch}, or + * {@apilink GatewayThreadDeleteDispatch} instead. * https://discord.com/developers/docs/topics/gateway-events#thread-create * https://discord.com/developers/docs/topics/gateway-events#thread-update * https://discord.com/developers/docs/topics/gateway-events#thread-delete @@ -1620,7 +1627,10 @@ export type GatewayThreadModifyDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway-events#thread-create */ -export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadCreateDispatch = DataPayload< + GatewayDispatchEvents.ThreadCreate, + GatewayThreadCreateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-create @@ -1635,22 +1645,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel { /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadUpdateDispatch = DataPayload< + GatewayDispatchEvents.ThreadUpdate, + GatewayThreadUpdateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData; +export type GatewayThreadUpdateDispatchData = APIThreadChannel; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadDeleteDispatch = DataPayload< + GatewayDispatchEvents.ThreadDelete, + GatewayThreadDeleteDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData; +export interface GatewayThreadDeleteDispatchData { + /** + * The id of the channel + */ + id: Snowflake; + /** + * The id of the guild + */ + guild_id: Snowflake; + /** + * The id of the parent channel of the thread + */ + parent_id: Snowflake; + /** + * The type of the channel + * + * See https://discord.com/developers/docs/resources/channel#channel-object-channel-types + */ + type: ChannelType; +} /** * https://discord.com/developers/docs/topics/gateway-events#typing-start diff --git a/gateway/v9.ts b/gateway/v9.ts index 85986bef..0a0bf0fa 100644 --- a/gateway/v9.ts +++ b/gateway/v9.ts @@ -33,6 +33,7 @@ import type { PresenceUpdateStatus, AutoModerationRuleTriggerType, APIAuditLogEntry, + ChannelType, } from '../payloads/v9/index'; import type { Nullable } from '../utils/internals'; import type { APIEntitlement } from '../v10'; @@ -338,7 +339,9 @@ export type GatewayDispatchPayload = | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch - | GatewayThreadModifyDispatch + | GatewayThreadCreateDispatch + | GatewayThreadUpdateDispatch + | GatewayThreadDeleteDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch @@ -1607,6 +1610,10 @@ export type GatewayThreadMemberUpdateDispatch = DataPayload< export type GatewayThreadMemberUpdateDispatchData = APIThreadMember & { guild_id: Snowflake }; /** + * @deprecated This type doesn't accurately reflect the Discord API. + * Use {@apilink GatewayThreadCreateDispatch}, + * {@apilink GatewayThreadUpdateDispatch}, or + * {@apilink GatewayThreadDeleteDispatch} instead. * https://discord.com/developers/docs/topics/gateway-events#thread-create * https://discord.com/developers/docs/topics/gateway-events#thread-update * https://discord.com/developers/docs/topics/gateway-events#thread-delete @@ -1619,7 +1626,10 @@ export type GatewayThreadModifyDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway-events#thread-create */ -export type GatewayThreadCreateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadCreateDispatch = DataPayload< + GatewayDispatchEvents.ThreadCreate, + GatewayThreadCreateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-create @@ -1634,22 +1644,47 @@ export interface GatewayThreadCreateDispatchData extends APIThreadChannel { /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadUpdateDispatch = DataPayload< + GatewayDispatchEvents.ThreadUpdate, + GatewayThreadUpdateDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-update */ -export type GatewayThreadUpdateDispatchData = GatewayChannelModifyDispatchData; +export type GatewayThreadUpdateDispatchData = APIThreadChannel; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatch = GatewayChannelModifyDispatch; +export type GatewayThreadDeleteDispatch = DataPayload< + GatewayDispatchEvents.ThreadDelete, + GatewayThreadDeleteDispatchData +>; /** * https://discord.com/developers/docs/topics/gateway-events#thread-delete */ -export type GatewayThreadDeleteDispatchData = GatewayChannelModifyDispatchData; +export interface GatewayThreadDeleteDispatchData { + /** + * The id of the channel + */ + id: Snowflake; + /** + * The id of the guild + */ + guild_id: Snowflake; + /** + * The id of the parent channel of the thread + */ + parent_id: Snowflake; + /** + * The type of the channel + * + * See https://discord.com/developers/docs/resources/channel#channel-object-channel-types + */ + type: ChannelType; +} /** * https://discord.com/developers/docs/topics/gateway-events#typing-start