Skip to content

Commit 4defa9e

Browse files
authored
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
1 parent 1290c94 commit 4defa9e

File tree

12 files changed

+96
-48
lines changed

12 files changed

+96
-48
lines changed

deno/payloads/v10/_interactions/base.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { Permissions, Snowflake } from '../../../globals.ts';
22
import type { APIRole, LocaleString } from '../../../v10.ts';
3-
import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel.ts';
3+
import type {
4+
APIAttachment,
5+
APIChannel,
6+
APIMessage,
7+
APIPartialChannel,
8+
APIThreadChannel,
9+
ChannelType,
10+
ThreadChannelType,
11+
} from '../channel.ts';
412
import type { APIGuildMember } from '../guild.ts';
513
import type { APIUser } from '../user.ts';
614
import type { InteractionType } from './responses.ts';
@@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<Inter
136144
> &
137145
Required<Pick<Original, 'member' | 'guild_id'>>;
138146

147+
export interface APIInteractionDataResolvedChannelBase<T extends ChannelType> extends Required<APIPartialChannel> {
148+
type: T;
149+
permissions: Permissions;
150+
}
151+
139152
/**
140153
* https://discord.com/developers/docs/resources/channel#channel-object
141154
*/
142-
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
143-
thread_metadata?: APIThreadMetadata | null;
144-
permissions: Permissions;
145-
parent_id?: string | null;
146-
}
155+
export type APIInteractionDataResolvedChannel =
156+
| APIInteractionDataResolvedChannelBase<Exclude<ChannelType, ThreadChannelType>>
157+
| (APIInteractionDataResolvedChannelBase<ThreadChannelType> &
158+
Pick<APIThreadChannel, 'thread_metadata' | 'parent_id'>);
147159

148160
/**
149161
* https://discord.com/developers/docs/resources/guild#guild-member-object

deno/payloads/v10/channel.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,11 @@ export interface APIGroupDMChannel extends Omit<APIDMChannelBase<ChannelType.Gro
206206
managed?: boolean;
207207
}
208208

209+
export type ThreadChannelType = ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread;
210+
209211
export interface APIThreadChannel
210-
extends Omit<
211-
APITextBasedChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread>,
212-
'name'
213-
>,
214-
APIGuildChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread> {
212+
extends Omit<APITextBasedChannel<ThreadChannelType>, 'name'>,
213+
APIGuildChannel<ThreadChannelType> {
215214
/**
216215
* The client users member for the thread, only included in select endpoints
217216
*/

deno/payloads/v9/_interactions/base.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { Permissions, Snowflake } from '../../../globals.ts';
22
import type { APIRole, LocaleString } from '../../../v9.ts';
3-
import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel.ts';
3+
import type {
4+
APIAttachment,
5+
APIChannel,
6+
APIMessage,
7+
APIPartialChannel,
8+
APIThreadChannel,
9+
ChannelType,
10+
ThreadChannelType,
11+
} from '../channel.ts';
412
import type { APIGuildMember } from '../guild.ts';
513
import type { APIUser } from '../user.ts';
614
import type { InteractionType } from './responses.ts';
@@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<Inter
136144
> &
137145
Required<Pick<Original, 'member' | 'guild_id'>>;
138146

147+
export interface APIInteractionDataResolvedChannelBase<T extends ChannelType> extends Required<APIPartialChannel> {
148+
type: T;
149+
permissions: Permissions;
150+
}
151+
139152
/**
140153
* https://discord.com/developers/docs/resources/channel#channel-object
141154
*/
142-
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
143-
thread_metadata?: APIThreadMetadata | null;
144-
permissions: Permissions;
145-
parent_id?: string | null;
146-
}
155+
export type APIInteractionDataResolvedChannel =
156+
| APIInteractionDataResolvedChannelBase<Exclude<ChannelType, ThreadChannelType>>
157+
| (APIInteractionDataResolvedChannelBase<ThreadChannelType> &
158+
Pick<APIThreadChannel, 'thread_metadata' | 'parent_id'>);
147159

148160
/**
149161
* https://discord.com/developers/docs/resources/guild#guild-member-object

deno/payloads/v9/channel.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,11 @@ export interface APIGroupDMChannel extends Omit<APIDMChannelBase<ChannelType.Gro
202202
managed?: boolean;
203203
}
204204

205+
export type ThreadChannelType = ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread;
206+
205207
export interface APIThreadChannel
206-
extends Omit<
207-
APITextBasedChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread>,
208-
'name'
209-
>,
210-
APIGuildChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread> {
208+
extends Omit<APITextBasedChannel<ThreadChannelType>, 'name'>,
209+
APIGuildChannel<ThreadChannelType> {
211210
/**
212211
* The client users member for the thread, only included in select endpoints
213212
*/

deno/rest/v10/channel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
MessageFlags,
1818
OverwriteType,
1919
ThreadAutoArchiveDuration,
20+
ThreadChannelType,
2021
VideoQualityMode,
2122
APIGuildForumTag,
2223
APIGuildForumDefaultReactionEmoji,
@@ -678,7 +679,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes
678679
*
679680
* @default ChannelType.PrivateThread
680681
*/
681-
type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined;
682+
type?: ThreadChannelType | undefined;
682683
/**
683684
* Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread
684685
*/

deno/rest/v9/channel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
MessageFlags,
1818
OverwriteType,
1919
ThreadAutoArchiveDuration,
20+
ThreadChannelType,
2021
VideoQualityMode,
2122
APIGuildForumTag,
2223
APIGuildForumDefaultReactionEmoji,
@@ -694,7 +695,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes
694695
*
695696
* @default ChannelType.PrivateThread
696697
*/
697-
type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined;
698+
type?: ThreadChannelType | undefined;
698699
/**
699700
* Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread
700701
*/

payloads/v10/_interactions/base.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { Permissions, Snowflake } from '../../../globals';
22
import type { APIRole, LocaleString } from '../../../v10';
3-
import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel';
3+
import type {
4+
APIAttachment,
5+
APIChannel,
6+
APIMessage,
7+
APIPartialChannel,
8+
APIThreadChannel,
9+
ChannelType,
10+
ThreadChannelType,
11+
} from '../channel';
412
import type { APIGuildMember } from '../guild';
513
import type { APIUser } from '../user';
614
import type { InteractionType } from './responses';
@@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<Inter
136144
> &
137145
Required<Pick<Original, 'member' | 'guild_id'>>;
138146

147+
export interface APIInteractionDataResolvedChannelBase<T extends ChannelType> extends Required<APIPartialChannel> {
148+
type: T;
149+
permissions: Permissions;
150+
}
151+
139152
/**
140153
* https://discord.com/developers/docs/resources/channel#channel-object
141154
*/
142-
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
143-
thread_metadata?: APIThreadMetadata | null;
144-
permissions: Permissions;
145-
parent_id?: string | null;
146-
}
155+
export type APIInteractionDataResolvedChannel =
156+
| APIInteractionDataResolvedChannelBase<Exclude<ChannelType, ThreadChannelType>>
157+
| (APIInteractionDataResolvedChannelBase<ThreadChannelType> &
158+
Pick<APIThreadChannel, 'thread_metadata' | 'parent_id'>);
147159

148160
/**
149161
* https://discord.com/developers/docs/resources/guild#guild-member-object

payloads/v10/channel.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,11 @@ export interface APIGroupDMChannel extends Omit<APIDMChannelBase<ChannelType.Gro
206206
managed?: boolean;
207207
}
208208

209+
export type ThreadChannelType = ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread;
210+
209211
export interface APIThreadChannel
210-
extends Omit<
211-
APITextBasedChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread>,
212-
'name'
213-
>,
214-
APIGuildChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread> {
212+
extends Omit<APITextBasedChannel<ThreadChannelType>, 'name'>,
213+
APIGuildChannel<ThreadChannelType> {
215214
/**
216215
* The client users member for the thread, only included in select endpoints
217216
*/

payloads/v9/_interactions/base.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { Permissions, Snowflake } from '../../../globals';
22
import type { APIRole, LocaleString } from '../../../v9';
3-
import type { APIAttachment, APIChannel, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel';
3+
import type {
4+
APIAttachment,
5+
APIChannel,
6+
APIMessage,
7+
APIPartialChannel,
8+
APIThreadChannel,
9+
ChannelType,
10+
ThreadChannelType,
11+
} from '../channel';
412
import type { APIGuildMember } from '../guild';
513
import type { APIUser } from '../user';
614
import type { InteractionType } from './responses';
@@ -136,14 +144,18 @@ export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<Inter
136144
> &
137145
Required<Pick<Original, 'member' | 'guild_id'>>;
138146

147+
export interface APIInteractionDataResolvedChannelBase<T extends ChannelType> extends Required<APIPartialChannel> {
148+
type: T;
149+
permissions: Permissions;
150+
}
151+
139152
/**
140153
* https://discord.com/developers/docs/resources/channel#channel-object
141154
*/
142-
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
143-
thread_metadata?: APIThreadMetadata | null;
144-
permissions: Permissions;
145-
parent_id?: string | null;
146-
}
155+
export type APIInteractionDataResolvedChannel =
156+
| APIInteractionDataResolvedChannelBase<Exclude<ChannelType, ThreadChannelType>>
157+
| (APIInteractionDataResolvedChannelBase<ThreadChannelType> &
158+
Pick<APIThreadChannel, 'thread_metadata' | 'parent_id'>);
147159

148160
/**
149161
* https://discord.com/developers/docs/resources/guild#guild-member-object

payloads/v9/channel.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,11 @@ export interface APIGroupDMChannel extends Omit<APIDMChannelBase<ChannelType.Gro
202202
managed?: boolean;
203203
}
204204

205+
export type ThreadChannelType = ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread;
206+
205207
export interface APIThreadChannel
206-
extends Omit<
207-
APITextBasedChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread>,
208-
'name'
209-
>,
210-
APIGuildChannel<ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread> {
208+
extends Omit<APITextBasedChannel<ThreadChannelType>, 'name'>,
209+
APIGuildChannel<ThreadChannelType> {
211210
/**
212211
* The client users member for the thread, only included in select endpoints
213212
*/

rest/v10/channel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
MessageFlags,
1818
OverwriteType,
1919
ThreadAutoArchiveDuration,
20+
ThreadChannelType,
2021
VideoQualityMode,
2122
APIGuildForumTag,
2223
APIGuildForumDefaultReactionEmoji,
@@ -678,7 +679,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes
678679
*
679680
* @default ChannelType.PrivateThread
680681
*/
681-
type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined;
682+
type?: ThreadChannelType | undefined;
682683
/**
683684
* Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread
684685
*/

rest/v9/channel.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
MessageFlags,
1818
OverwriteType,
1919
ThreadAutoArchiveDuration,
20+
ThreadChannelType,
2021
VideoQualityMode,
2122
APIGuildForumTag,
2223
APIGuildForumDefaultReactionEmoji,
@@ -694,7 +695,7 @@ export interface RESTPostAPIChannelThreadsJSONBody extends RESTPostAPIChannelMes
694695
*
695696
* @default ChannelType.PrivateThread
696697
*/
697-
type?: ChannelType.AnnouncementThread | ChannelType.PublicThread | ChannelType.PrivateThread | undefined;
698+
type?: ThreadChannelType | undefined;
698699
/**
699700
* Whether non-moderators can add other non-moderators to the thread; only available when creating a private thread
700701
*/

0 commit comments

Comments
 (0)