Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Add tagged type unions for channel types #200

Merged
merged 36 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4145dff
types: Add unions for channel types
suneettipirneni Sep 17, 2021
feb3fee
types: generate deno
suneettipirneni Sep 17, 2021
600bcc9
fix: make tags work properly
suneettipirneni Sep 17, 2021
1775f85
types: add other channel types
suneettipirneni Sep 17, 2021
78ec93e
types: add other channel types
suneettipirneni Sep 17, 2021
0514ae8
fix: compiler error
suneettipirneni Sep 17, 2021
f4de298
types: try to make requested changes
suneettipirneni Sep 18, 2021
17914ff
fix: make requested changes
suneettipirneni Sep 20, 2021
cef57a5
fix: compiler error
suneettipirneni Sep 20, 2021
045b9c3
chore: add v8 support
suneettipirneni Sep 20, 2021
088215b
fix: run post publish
suneettipirneni Sep 20, 2021
e07cd20
Merge branch 'main' of https://github.com/discordjs/discord-api-types…
suneettipirneni Sep 20, 2021
8153443
fix: v8 compiler error
suneettipirneni Sep 20, 2021
b95a82a
Update deno/payloads/v8/channel.ts
suneettipirneni Sep 21, 2021
84cb495
Update deno/payloads/v8/channel.ts
suneettipirneni Sep 21, 2021
b0164f7
chore: build deno
suneettipirneni Sep 21, 2021
16c3a6e
fix: rename text channels type
suneettipirneni Sep 21, 2021
c63cafe
fix: diffs and exports
suneettipirneni Sep 21, 2021
91b997c
Apply suggestions from code review
suneettipirneni Sep 21, 2021
01aad69
Merge branch 'types/channel-type-unions' of https://github.com/suneet…
suneettipirneni Sep 21, 2021
47c31a6
fix: add changes to v8
suneettipirneni Sep 21, 2021
c53db10
fix: remove DS store
suneettipirneni Sep 21, 2021
78f6357
Update .gitignore
vladfrangu Oct 29, 2021
4bdbc1f
Merge branch 'main' of https://github.com/discordjs/discord-api-types…
suneettipirneni Nov 17, 2021
e37eb1d
fix: make requested changes
suneettipirneni Nov 17, 2021
8d6f512
Merge branch 'types/channel-type-unions' of https://github.com/suneet…
suneettipirneni Nov 17, 2021
f301397
fix: duplicated symbol
suneettipirneni Nov 17, 2021
452eb74
docs: add TODO
suneettipirneni Nov 18, 2021
ab5cb5c
docs: fix typo
suneettipirneni Nov 18, 2021
f2c0258
docs: update todo description
suneettipirneni Nov 22, 2021
0428084
docs: move to text channel
suneettipirneni Nov 22, 2021
f431155
types: make requested changes
suneettipirneni Nov 23, 2021
a7278a2
Merge branch 'main' of https://github.com/discordjs/discord-api-types…
suneettipirneni Jan 9, 2022
3078644
Merge branch 'types/channel-type-unions' of https://github.com/suneet…
suneettipirneni Jan 9, 2022
38733e3
chore: make requested changes
suneettipirneni Jan 9, 2022
c697ac1
chore: singular types
suneettipirneni Jan 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
136 changes: 89 additions & 47 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,13 @@ export interface APIPartialChannel {
* The id of the channel
*/
id: Snowflake;
/**
* The type of the channel
*
* See https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
type: ChannelType;
/**
* The name of the channel (2-100 characters)
*/
name?: string;
}

/**
* https://discord.com/developers/docs/resources/channel#channel-object-channel-structure
*/
export interface APIChannel extends APIPartialChannel {
export interface BaseAPIChannel extends APIPartialChannel {
/**
* The id of the guild (may be missing for some channel objects received over gateway guild dispatches)
*/
Expand All @@ -49,26 +40,34 @@ export interface APIChannel extends APIPartialChannel {
* See https://discord.com/developers/docs/resources/channel#overwrite-object
*/
permission_overwrites?: APIOverwrite[];
/**
* The channel topic (0-1024 characters)
*/
topic?: string | null;
/**
* Whether the channel is nsfw
*/
nsfw?: boolean;
/**
* The id of the last message sent in this channel (may not point to an existing or valid message)
* Icon hash
*/
last_message_id?: Snowflake | null;
icon?: string | null;
/**
* The bitrate (in bits) of the voice channel
* ID of the parent category for a channel (each parent category can contain up to 50 channels)
*
* OR
*
* ID of the parent channel for a thread
*/
bitrate?: number;
parent_id?: Snowflake | null;
}

export interface APITextBasedChannel extends BaseAPIChannel {
/**
* The user limit of the voice channel
* The id of the last message sent in this channel (may not point to an existing or valid message)
*/
user_limit?: number;
last_message_id?: Snowflake | null;
/**
* When the last pinned message was pinned.
* This may be `null` in events such as `GUILD_CREATE` when a message is not pinned
*/
last_pin_timestamp?: string | null;
/**
* Amount of seconds a user has to wait before sending another message (0-21600);
* bots, as well as users with the permission `MANAGE_MESSAGES` or `MANAGE_CHANNELS`, are unaffected
Expand All @@ -79,37 +78,45 @@ export interface APIChannel extends APIPartialChannel {
* The absence of this field in API calls and Gateway events should indicate that slowmode has been reset to the default value.
*/
rate_limit_per_user?: number;
}

export interface APITextChannel extends APITextBasedChannel {
type: ChannelType.GuildText;
/**
* The recipients of the DM
*
* See https://discord.com/developers/docs/resources/user#user-object
* Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity
*/
recipients?: APIUser[];
default_auto_archive_duration?: ThreadAutoArchiveDuration;
/**
* Icon hash
* The channel topic (0-1024 characters)
*/
icon?: string | null;
topic?: string | null;
}

export interface APINonRateLimitedChannel extends Omit<APITextChannel, 'rate_limit_per_user' | 'type'> {
type: ChannelType.GuildNews;
}

export interface APINonInteractiveChannel extends BaseAPIChannel {
type: ChannelType.GuildCategory | ChannelType.GuildStore;
}

export interface APIOwnedChannel extends APITextBasedChannel {
/**
* ID of the DM creator or thread creator
*/
owner_id?: Snowflake;
}

export interface APIVoiceChannel extends BaseAPIChannel {
type: ChannelType.GuildVoice | ChannelType.GuildStageVoice;
/**
* Application id of the group DM creator if it is bot-created
*/
application_id?: Snowflake;
/**
* ID of the parent category for a channel (each parent category can contain up to 50 channels)
*
* OR
*
* ID of the parent channel for a thread
* The bitrate (in bits) of the voice channel
*/
parent_id?: Snowflake | null;
bitrate?: number;
/**
* When the last pinned message was pinned.
* This may be `null` in events such as `GUILD_CREATE` when a message is not pinned
* The user limit of the voice channel
*/
last_pin_timestamp?: string | null;
user_limit?: number;
/**
* Voice region id for the voice or stage channel, automatic when set to `null`
*
Expand All @@ -122,28 +129,63 @@ export interface APIChannel extends APIPartialChannel {
* See https://discord.com/developers/docs/resources/channel#channel-object-video-quality-modes
*/
video_quality_mode?: VideoQualityMode;
}

export interface APIDMChannelBase
extends Pick<APITextBasedChannel, 'last_message_id' | 'parent_id'>,
Pick<BaseAPIChannel, 'id'> {
/**
* The approximate message count of the thread, does not count above 50 even if there are more messages
* The recipients of the DM
*
* See https://discord.com/developers/docs/resources/user#user-object
*/
message_count?: number;
recipients?: APIUser[];
}

export interface APIDMChannel extends APIDMChannelBase {
type: ChannelType.DM;
}

export interface APIGroupDMChannel extends APIDMChannelBase, APIOwnedChannel, Pick<BaseAPIChannel, 'name'> {
type: ChannelType.GroupDM;
/**
* The approximate member count of the thread, does not count above 50 even if there are more members
* Application id of the group DM creator if it is bot-created
*/
member_count?: number;
application_id?: Snowflake;
}

export interface APIThreadChannel extends APITextBasedChannel, APIOwnedChannel {
type: ChannelType.GuildPublicThread | ChannelType.GuildPrivateThread | ChannelType.GuildNewsThread;
/**
* The client users member for the thread, only included in select endpoints
*/
member?: APIThreadMember;
/**
* The metadata for a thread channel not shared by other channels
*/
thread_metadata?: APIThreadMetadata;
/**
* The client users member for the thread, only included in select endpoints
* The approximate message count of the thread, does not count above 50 even if there are more messages
*/
member?: APIThreadMember;
message_count?: number;
/**
* Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity
* The approximate member count of the thread, does not count above 50 even if there are more members
*/
default_auto_archive_duration?: ThreadAutoArchiveDuration;
member_count?: number;
}

/**
* https://discord.com/developers/docs/resources/channel#channel-object-channel-structure
*/
export type APIChannel =
| APIDMChannel
| APIGroupDMChannel
| APIVoiceChannel
| APITextChannel
| APIThreadChannel
| APINonInteractiveChannel
| APINonRateLimitedChannel;

/**
* https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
Expand Down
4 changes: 3 additions & 1 deletion deno/rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import type {
APIGuildWidget,
APIGuildWidgetSettings,
APIRole,
APITextChannel,
APIThreadList,
APIVoiceChannel,
APIVoiceRegion,
GuildDefaultMessageNotifications,
GuildExplicitContentFilter,
Expand All @@ -29,7 +31,7 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON
}

export type APIGuildCreatePartialChannel = Partial<
Pick<APIChannel, 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'>
Pick<APIVoiceChannel & APITextChannel, 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'>
> & {
name: string;
id?: number | string;
Expand Down