Skip to content

Commit

Permalink
refactor: separate GUILD_CREATE fields from APIGuild object (#423)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: APIGuild now correctly shows just the properties that are obtainable through rest/GUILD_UPDATE, while the extra fields have been moved to GatewayGuildCreateDispatchData to correctly represent the data received
  • Loading branch information
vvito7 committed May 13, 2022
1 parent d3163ca commit 17f5caa
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 324 deletions.
80 changes: 78 additions & 2 deletions deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../globals.ts';
import type { GatewayPresenceUpdate } from '../payloads/v10/gateway.ts';
import type {
APIApplication,
APIChannel,
Expand Down Expand Up @@ -509,7 +510,6 @@ export type GatewayGuildModifyDispatch = DataPayload<
>;

/**
* https://discord.com/developers/docs/topics/gateway#guild-create
* https://discord.com/developers/docs/topics/gateway#guild-update
*/
export type GatewayGuildModifyDispatchData = APIGuild;
Expand All @@ -521,8 +521,84 @@ export type GatewayGuildCreateDispatch = GatewayGuildModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway#guild-create
* https://discord.com/developers/docs/topics/gateway#guild-create-guild-create-extra-fields
*/
export type GatewayGuildCreateDispatchData = GatewayGuildModifyDispatchData;
export type GatewayGuildCreateDispatchData = APIGuild & {
/**
* When this guild was joined at
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
joined_at: string;
/**
* `true` if this is considered a large guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
large: boolean;
/**
* Total number of members in this guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
member_count: number;
/**
* States of members currently in voice channels; lacks the `guild_id` key
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/voice#voice-state-object
*/
voice_states: Omit<GatewayVoiceState, 'guild_id'>[];
/**
* Users in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/guild#guild-member-object
*/
members: APIGuildMember[];
/**
* Channels in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
channels: APIChannel[];
/**
* Threads in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
threads: APIChannel[];
/**
* Presences of the members in the guild, will only include non-offline members if the size is greater than `large_threshold`
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/topics/gateway#presence-update
*/
presences: GatewayPresenceUpdate[];
/**
* The stage instances in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-stage-instance-structure
*/
stage_instances: APIStageInstance[];
/**
* The scheduled events in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object
*/
guild_scheduled_events: APIGuildScheduledEvent[];
};

/**
* https://discord.com/developers/docs/topics/gateway#guild-update
Expand Down
80 changes: 78 additions & 2 deletions deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import type { Snowflake } from '../globals.ts';
import type { GatewayPresenceUpdate } from '../payloads/v9/gateway.ts';
import type {
APIApplication,
APIChannel,
Expand Down Expand Up @@ -508,7 +509,6 @@ export type GatewayGuildModifyDispatch = DataPayload<
>;

/**
* https://discord.com/developers/docs/topics/gateway#guild-create
* https://discord.com/developers/docs/topics/gateway#guild-update
*/
export type GatewayGuildModifyDispatchData = APIGuild;
Expand All @@ -520,8 +520,84 @@ export type GatewayGuildCreateDispatch = GatewayGuildModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway#guild-create
* https://discord.com/developers/docs/topics/gateway#guild-create-guild-create-extra-fields
*/
export type GatewayGuildCreateDispatchData = GatewayGuildModifyDispatchData;
export type GatewayGuildCreateDispatchData = APIGuild & {
/**
* When this guild was joined at
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
joined_at: string;
/**
* `true` if this is considered a large guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
large: boolean;
/**
* Total number of members in this guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
member_count: number;
/**
* States of members currently in voice channels; lacks the `guild_id` key
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/voice#voice-state-object
*/
voice_states: Omit<GatewayVoiceState, 'guild_id'>[];
/**
* Users in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/guild#guild-member-object
*/
members: APIGuildMember[];
/**
* Channels in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
channels: APIChannel[];
/**
* Threads in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
threads: APIChannel[];
/**
* Presences of the members in the guild, will only include non-offline members if the size is greater than `large_threshold`
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/topics/gateway#presence-update
*/
presences: GatewayPresenceUpdate[];
/**
* The stage instances in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-stage-instance-structure
*/
stage_instances: APIStageInstance[];
/**
* The scheduled events in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object
*/
guild_scheduled_events: APIGuildScheduledEvent[];
};

/**
* https://discord.com/developers/docs/topics/gateway#guild-update
Expand Down
80 changes: 1 addition & 79 deletions deno/payloads/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
* Types extracted from https://discord.com/developers/docs/resources/guild
*/

import type { APIChannel } from './channel.ts';
import type { APIEmoji } from './emoji.ts';
import type { GatewayPresenceUpdate, PresenceUpdateStatus } from './gateway.ts';
import type { APIGuildScheduledEvent } from './guildScheduledEvent.ts';
import type { PresenceUpdateStatus } from './gateway.ts';
import type { APIRole } from './permissions.ts';
import type { APIStageInstance } from './stageInstance.ts';
import type { APISticker } from './sticker.ts';
import type { APIUser } from './user.ts';
import type { GatewayVoiceState } from './voice.ts';
import type { Permissions, Snowflake } from '../../globals.ts';

/**
Expand Down Expand Up @@ -196,64 +192,6 @@ export interface APIGuild extends APIPartialGuild {
* The id of the channel where Community guilds can display rules and/or guidelines
*/
rules_channel_id: Snowflake | null;
/**
* When this guild was joined at
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
joined_at?: string;
/**
* `true` if this is considered a large guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
large?: boolean;
/**
* Total number of members in this guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*/
member_count?: number;
/**
* States of members currently in voice channels; lacks the `guild_id` key
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/voice#voice-state-object
*/
voice_states?: Omit<GatewayVoiceState, 'guild_id'>[];
/**
* Users in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/guild#guild-member-object
*/
members?: APIGuildMember[];
/**
* Channels in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
channels?: APIChannel[];
/**
* Threads in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/channel#channel-object
*/
threads?: APIChannel[];
/**
* Presences of the members in the guild, will only include non-offline members if the size is greater than `large_threshold`
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/topics/gateway#presence-update
*/
presences?: GatewayPresenceUpdate[];
/**
* The maximum number of presences for the guild (`null` is always returned, apart from the largest of guilds)
*/
Expand Down Expand Up @@ -320,14 +258,6 @@ export interface APIGuild extends APIPartialGuild {
* See https://discord.com/developers/docs/resources/guild#guild-object-guild-nsfw-level
*/
nsfw_level: GuildNSFWLevel;
/**
* The stage instances in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* See https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-stage-instance-structure
*/
stage_instances?: APIStageInstance[];
/**
* Custom guild stickers
*
Expand All @@ -338,14 +268,6 @@ export interface APIGuild extends APIPartialGuild {
* Whether the guild has the boost progress bar enabled.
*/
premium_progress_bar_enabled: boolean;
/**
* The scheduled events in the guild
*
* **This field is only sent within the [GUILD_CREATE](https://discord.com/developers/docs/topics/gateway#guild-create) event**
*
* https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object
*/
guild_scheduled_events?: APIGuildScheduledEvent[];
/**
* The type of Student Hub the guild is
*/
Expand Down
Loading

0 comments on commit 17f5caa

Please sign in to comment.