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

Conversation

suneettipirneni
Copy link
Member

Please describe the changes this PR makes and why it should be merged:

Closes #61

Reference Discord API Docs PRs or commits:
https://discord.com/developers/docs/resources/channel#channel-object-channel-types

Copy link
Member

@vladfrangu vladfrangu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mad lad for tackling this issue, and overall, great start! Still needs some work tho, as well as the same change in v8 :D

payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
rest/v9/guild.ts Outdated Show resolved Hide resolved
@suneettipirneni
Copy link
Member Author

as well as the same change in v8 :D

😦

@suneettipirneni
Copy link
Member Author

suneettipirneni commented Sep 18, 2021

So I tried my best to integrate the changes you requested, let me know if there's anything else.

I'll work on v8 after v9 is finalized.

Also if you need to test the typings I'm using this file to verify everything is working as expected:

/* eslint-disable @typescript-eslint/no-unused-vars */
import { APIChannel, ChannelType } from '.';

const guildTextChannel: APIChannel = {
	id: '12',
	type: ChannelType.GuildText,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	rate_limit_per_user: 2,
	nsfw: true,
	topic: 'topic',
	last_message_id: '12',
	default_auto_archive_duration: 60,
};

const guildNewsChannel: APIChannel = {
	id: '12',
	type: ChannelType.GuildNews,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	nsfw: true,
	topic: 'topic',
	last_message_id: '12',
	default_auto_archive_duration: 60,
};

const guildNewsThread: APIChannel = {
	id: '12',
	type: ChannelType.GuildNewsThread,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	nsfw: true,
	last_message_id: '12',
	thread_metadata: {
		archived: false,
		auto_archive_duration: 1440,
		archive_timestamp: 'date',
		locked: false,
	},
};

const guildVoiceChannel: APIChannel = {
	id: '12',
	type: ChannelType.GuildVoice,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	nsfw: true,
	bitrate: 64000,
	user_limit: 0,
	parent_id: null,
	rtc_region: null,
};

const DMChannel: APIChannel = {
	id: '12',
	type: ChannelType.DM,
	recipients: [],
	last_message_id: '12',
};

const groupDMChannel: APIChannel = {
	id: '12',
	type: ChannelType.GroupDM,
	recipients: [],
	last_message_id: '12',
	owner_id: '12',
	icon: null,
};

const categoryChannel: APIChannel = {
	id: '12',
	type: ChannelType.GuildCategory,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	nsfw: true,
};

const storeChannel: APIChannel = {
	id: '12',
	type: ChannelType.GuildStore,
	name: 'general',
	position: 6,
	permission_overwrites: [],
	nsfw: true,
	parent_id: null,
};

const threadChannel: APIChannel = {
	id: '12',
	guild_id: '12',
	owner_id: '12',
	parent_id: '12',
	name: 'general',
	type: ChannelType.GuildPublicThread,
	last_message_id: '12',
	member_count: 1,
	message_count: 5,
	rate_limit_per_user: 2,
	thread_metadata: {
		archived: false,
		auto_archive_duration: 1440,
		archive_timestamp: 'date',
		locked: false,
	},
};

Copy link
Member

@vladfrangu vladfrangu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small issues, please fix in non-deno ones

deno/payloads/v9/channel.ts Outdated Show resolved Hide resolved
deno/payloads/v9/channel.ts Show resolved Hide resolved
deno/payloads/v9/channel.ts Outdated Show resolved Hide resolved
@suneettipirneni
Copy link
Member Author

So v8 will pretty much be the same, just without the threads right?

@vladfrangu
Copy link
Member

Yep yep

Copy link
Member

@vladfrangu vladfrangu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more requested changes for you, please apply them to v9/v8 and then run the deno script 🙏

deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
suneettipirneni and others added 3 commits September 21, 2021 12:32
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v9/channel.ts Outdated Show resolved Hide resolved
payloads/v8/channel.ts Outdated Show resolved Hide resolved
payloads/v8/channel.ts Outdated Show resolved Hide resolved
payloads/v8/channel.ts Outdated Show resolved Hide resolved
rest/v8/guild.ts Outdated Show resolved Hide resolved
deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
Copy link
Member

@vladfrangu vladfrangu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're reaching a point where having to keep these types updates is probably gonna be annoying to do..

deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
deno/payloads/v8/channel.ts Outdated Show resolved Hide resolved
payloads/v8/channel.ts Outdated Show resolved Hide resolved
@vladfrangu
Copy link
Member

Well what do you know, the curse follows everyone as this PR needs a rebase

payloads/v8/channel.ts Outdated Show resolved Hide resolved
rest/v8/guild.ts Show resolved Hide resolved
@vladfrangu vladfrangu merged commit 2c1fbda into discordjs:main Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: convert APIChannel into an union of channels, based on their type
7 participants