From 4defa9ea1216816f39454b42bc2c5de22e8d0f0a Mon Sep 17 00:00:00 2001 From: Renegade334 Date: Sat, 23 Sep 2023 22:23:15 +0100 Subject: [PATCH] refactor(APIInteractionDataResolvedChannel): thread channels (#825) - bring APIInteractionDataResolvedChannel into line with API specification (thread_metadata, parent_id only exist on thread channel partials) - also adds a ThreadChannelType utility export --- deno/payloads/v10/_interactions/base.ts | 24 ++++++++++++++++++------ deno/payloads/v10/channel.ts | 9 ++++----- deno/payloads/v9/_interactions/base.ts | 24 ++++++++++++++++++------ deno/payloads/v9/channel.ts | 9 ++++----- deno/rest/v10/channel.ts | 3 ++- deno/rest/v9/channel.ts | 3 ++- payloads/v10/_interactions/base.ts | 24 ++++++++++++++++++------ payloads/v10/channel.ts | 9 ++++----- payloads/v9/_interactions/base.ts | 24 ++++++++++++++++++------ payloads/v9/channel.ts | 9 ++++----- rest/v10/channel.ts | 3 ++- rest/v9/channel.ts | 3 ++- 12 files changed, 96 insertions(+), 48 deletions(-) diff --git a/deno/payloads/v10/_interactions/base.ts b/deno/payloads/v10/_interactions/base.ts index d454b009..1b044a4c 100644 --- a/deno/payloads/v10/_interactions/base.ts +++ b/deno/payloads/v10/_interactions/base.ts @@ -1,6 +1,14 @@ import type { Permissions, Snowflake } from '../../../globals.ts'; import type { APIRole, LocaleString } from '../../../v10.ts'; -import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel.ts'; +import type { + APIAttachment, + APIChannel, + APIMessage, + APIPartialChannel, + APIThreadChannel, + ChannelType, + ThreadChannelType, +} from '../channel.ts'; import type { APIGuildMember } from '../guild.ts'; import type { APIUser } from '../user.ts'; import type { InteractionType } from './responses.ts'; @@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper & Required>; +export interface APIInteractionDataResolvedChannelBase extends Required { + type: T; + permissions: Permissions; +} + /** * https://discord.com/developers/docs/resources/channel#channel-object */ -export interface APIInteractionDataResolvedChannel extends Required { - thread_metadata?: APIThreadMetadata | null; - permissions: Permissions; - parent_id?: string | null; -} +export type APIInteractionDataResolvedChannel = + | APIInteractionDataResolvedChannelBase> + | (APIInteractionDataResolvedChannelBase & + Pick); /** * https://discord.com/developers/docs/resources/guild#guild-member-object diff --git a/deno/payloads/v10/channel.ts b/deno/payloads/v10/channel.ts index 9fd8343a..559956d3 100644 --- a/deno/payloads/v10/channel.ts +++ b/deno/payloads/v10/channel.ts @@ -206,12 +206,11 @@ export interface APIGroupDMChannel extends Omit, - 'name' - >, - APIGuildChannel { + extends Omit, 'name'>, + APIGuildChannel { /** * The client users member for the thread, only included in select endpoints */ diff --git a/deno/payloads/v9/_interactions/base.ts b/deno/payloads/v9/_interactions/base.ts index 15d86b7e..5e8f4356 100644 --- a/deno/payloads/v9/_interactions/base.ts +++ b/deno/payloads/v9/_interactions/base.ts @@ -1,6 +1,14 @@ import type { Permissions, Snowflake } from '../../../globals.ts'; import type { APIRole, LocaleString } from '../../../v9.ts'; -import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel.ts'; +import type { + APIAttachment, + APIChannel, + APIMessage, + APIPartialChannel, + APIThreadChannel, + ChannelType, + ThreadChannelType, +} from '../channel.ts'; import type { APIGuildMember } from '../guild.ts'; import type { APIUser } from '../user.ts'; import type { InteractionType } from './responses.ts'; @@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper & Required>; +export interface APIInteractionDataResolvedChannelBase extends Required { + type: T; + permissions: Permissions; +} + /** * https://discord.com/developers/docs/resources/channel#channel-object */ -export interface APIInteractionDataResolvedChannel extends Required { - thread_metadata?: APIThreadMetadata | null; - permissions: Permissions; - parent_id?: string | null; -} +export type APIInteractionDataResolvedChannel = + | APIInteractionDataResolvedChannelBase> + | (APIInteractionDataResolvedChannelBase & + Pick); /** * https://discord.com/developers/docs/resources/guild#guild-member-object diff --git a/deno/payloads/v9/channel.ts b/deno/payloads/v9/channel.ts index f0a96c12..e18835c5 100644 --- a/deno/payloads/v9/channel.ts +++ b/deno/payloads/v9/channel.ts @@ -202,12 +202,11 @@ export interface APIGroupDMChannel extends Omit, - 'name' - >, - APIGuildChannel { + extends Omit, 'name'>, + APIGuildChannel { /** * The client users member for the thread, only included in select endpoints */ diff --git a/deno/rest/v10/channel.ts b/deno/rest/v10/channel.ts index b8f30e29..746383f6 100644 --- a/deno/rest/v10/channel.ts +++ b/deno/rest/v10/channel.ts @@ -17,6 +17,7 @@ import type { MessageFlags, OverwriteType, ThreadAutoArchiveDuration, + ThreadChannelType, VideoQualityMode, APIGuildForumTag, APIGuildForumDefaultReactionEmoji, @@ -678,7 +679,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes * * @default ChannelType.PrivateThread */ - type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined; + type?: ThreadChannelType | undefined; /** * Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread */ diff --git a/deno/rest/v9/channel.ts b/deno/rest/v9/channel.ts index ab200c6d..1a137c39 100644 --- a/deno/rest/v9/channel.ts +++ b/deno/rest/v9/channel.ts @@ -17,6 +17,7 @@ import type { MessageFlags, OverwriteType, ThreadAutoArchiveDuration, + ThreadChannelType, VideoQualityMode, APIGuildForumTag, APIGuildForumDefaultReactionEmoji, @@ -694,7 +695,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes * * @default ChannelType.PrivateThread */ - type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined; + type?: ThreadChannelType | undefined; /** * Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread */ diff --git a/payloads/v10/_interactions/base.ts b/payloads/v10/_interactions/base.ts index a1e7f193..e2bde4fd 100644 --- a/payloads/v10/_interactions/base.ts +++ b/payloads/v10/_interactions/base.ts @@ -1,6 +1,14 @@ import type { Permissions, Snowflake } from '../../../globals'; import type { APIRole, LocaleString } from '../../../v10'; -import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel'; +import type { + APIAttachment, + APIChannel, + APIMessage, + APIPartialChannel, + APIThreadChannel, + ChannelType, + ThreadChannelType, +} from '../channel'; import type { APIGuildMember } from '../guild'; import type { APIUser } from '../user'; import type { InteractionType } from './responses'; @@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper & Required>; +export interface APIInteractionDataResolvedChannelBase extends Required { + type: T; + permissions: Permissions; +} + /** * https://discord.com/developers/docs/resources/channel#channel-object */ -export interface APIInteractionDataResolvedChannel extends Required { - thread_metadata?: APIThreadMetadata | null; - permissions: Permissions; - parent_id?: string | null; -} +export type APIInteractionDataResolvedChannel = + | APIInteractionDataResolvedChannelBase> + | (APIInteractionDataResolvedChannelBase & + Pick); /** * https://discord.com/developers/docs/resources/guild#guild-member-object diff --git a/payloads/v10/channel.ts b/payloads/v10/channel.ts index 6b621c3d..9262c6a8 100644 --- a/payloads/v10/channel.ts +++ b/payloads/v10/channel.ts @@ -206,12 +206,11 @@ export interface APIGroupDMChannel extends Omit, - 'name' - >, - APIGuildChannel { + extends Omit, 'name'>, + APIGuildChannel { /** * The client users member for the thread, only included in select endpoints */ diff --git a/payloads/v9/_interactions/base.ts b/payloads/v9/_interactions/base.ts index f17669d2..70ed6410 100644 --- a/payloads/v9/_interactions/base.ts +++ b/payloads/v9/_interactions/base.ts @@ -1,6 +1,14 @@ import type { Permissions, Snowflake } from '../../../globals'; import type { APIRole, LocaleString } from '../../../v9'; -import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel'; +import type { + APIAttachment, + APIChannel, + APIMessage, + APIPartialChannel, + APIThreadChannel, + ChannelType, + ThreadChannelType, +} from '../channel'; import type { APIGuildMember } from '../guild'; import type { APIUser } from '../user'; import type { InteractionType } from './responses'; @@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper & Required>; +export interface APIInteractionDataResolvedChannelBase extends Required { + type: T; + permissions: Permissions; +} + /** * https://discord.com/developers/docs/resources/channel#channel-object */ -export interface APIInteractionDataResolvedChannel extends Required { - thread_metadata?: APIThreadMetadata | null; - permissions: Permissions; - parent_id?: string | null; -} +export type APIInteractionDataResolvedChannel = + | APIInteractionDataResolvedChannelBase> + | (APIInteractionDataResolvedChannelBase & + Pick); /** * https://discord.com/developers/docs/resources/guild#guild-member-object diff --git a/payloads/v9/channel.ts b/payloads/v9/channel.ts index 27a1fd5d..8f774ce5 100644 --- a/payloads/v9/channel.ts +++ b/payloads/v9/channel.ts @@ -202,12 +202,11 @@ export interface APIGroupDMChannel extends Omit, - 'name' - >, - APIGuildChannel { + extends Omit, 'name'>, + APIGuildChannel { /** * The client users member for the thread, only included in select endpoints */ diff --git a/rest/v10/channel.ts b/rest/v10/channel.ts index f558bc80..5e47dc3d 100644 --- a/rest/v10/channel.ts +++ b/rest/v10/channel.ts @@ -17,6 +17,7 @@ import type { MessageFlags, OverwriteType, ThreadAutoArchiveDuration, + ThreadChannelType, VideoQualityMode, APIGuildForumTag, APIGuildForumDefaultReactionEmoji, @@ -678,7 +679,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes * * @default ChannelType.PrivateThread */ - type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined; + type?: ThreadChannelType | undefined; /** * Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread */ diff --git a/rest/v9/channel.ts b/rest/v9/channel.ts index 73046e84..f79e5182 100644 --- a/rest/v9/channel.ts +++ b/rest/v9/channel.ts @@ -17,6 +17,7 @@ import type { MessageFlags, OverwriteType, ThreadAutoArchiveDuration, + ThreadChannelType, VideoQualityMode, APIGuildForumTag, APIGuildForumDefaultReactionEmoji, @@ -694,7 +695,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes * * @default ChannelType.PrivateThread */ - type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined; + type?: ThreadChannelType | undefined; /** * Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread */