From 0bb2204b5ddd32b791641a33d52669bc739bc208 Mon Sep 17 00:00:00 2001 From: Vitor Date: Wed, 8 Jun 2022 20:24:24 +0100 Subject: [PATCH] refactor: separate `MESSAGE_CREATE` fields from `APIMessage` object (#434) BREAKING CHANGE: Certain fields that come only through the gateway are now correctly typed as such --- deno/gateway/v10.ts | 43 +++++++++++++++++++++++++++++++----- deno/gateway/v9.ts | 43 +++++++++++++++++++++++++++++++----- deno/payloads/v10/channel.ts | 16 +------------- deno/payloads/v9/channel.ts | 16 +------------- gateway/v10.ts | 43 +++++++++++++++++++++++++++++++----- gateway/v9.ts | 43 +++++++++++++++++++++++++++++++----- payloads/v10/channel.ts | 16 +------------- payloads/v9/channel.ts | 16 +------------- 8 files changed, 156 insertions(+), 80 deletions(-) diff --git a/deno/gateway/v10.ts b/deno/gateway/v10.ts index f2b3e87c..ced2c6b0 100644 --- a/deno/gateway/v10.ts +++ b/deno/gateway/v10.ts @@ -1125,7 +1125,7 @@ export type GatewayMessageCreateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-create */ -export type GatewayMessageCreateDispatchData = APIMessage; +export type GatewayMessageCreateDispatchData = Omit & GatewayMessageEventExtraFields; /** * https://discord.com/developers/docs/topics/gateway#message-update @@ -1138,10 +1138,43 @@ export type GatewayMessageUpdateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-update */ -export type GatewayMessageUpdateDispatchData = { - id: Snowflake; - channel_id: Snowflake; -} & Partial; +export type GatewayMessageUpdateDispatchData = Omit, 'mentions'> & + GatewayMessageEventExtraFields & { + /** + * ID of the message + */ + id: Snowflake; + /** + * ID of the channel the message was sent in + */ + channel_id: Snowflake; + }; + +export interface GatewayMessageEventExtraFields { + /** + * ID of the guild the message was sent in + */ + guild_id?: Snowflake; + /** + * Member properties for this message's author + * + * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + member?: APIGuildMember; + /** + * Users specifically mentioned in the message + * + * The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/user#user-object + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + mentions: (APIUser & { member?: Omit })[]; +} /** * https://discord.com/developers/docs/topics/gateway#message-delete diff --git a/deno/gateway/v9.ts b/deno/gateway/v9.ts index fd4eaee4..36b9991d 100644 --- a/deno/gateway/v9.ts +++ b/deno/gateway/v9.ts @@ -1124,7 +1124,7 @@ export type GatewayMessageCreateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-create */ -export type GatewayMessageCreateDispatchData = APIMessage; +export type GatewayMessageCreateDispatchData = Omit & GatewayMessageEventExtraFields; /** * https://discord.com/developers/docs/topics/gateway#message-update @@ -1137,10 +1137,43 @@ export type GatewayMessageUpdateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-update */ -export type GatewayMessageUpdateDispatchData = { - id: Snowflake; - channel_id: Snowflake; -} & Partial; +export type GatewayMessageUpdateDispatchData = Omit, 'mentions'> & + GatewayMessageEventExtraFields & { + /** + * ID of the message + */ + id: Snowflake; + /** + * ID of the channel the message was sent in + */ + channel_id: Snowflake; + }; + +export interface GatewayMessageEventExtraFields { + /** + * ID of the guild the message was sent in + */ + guild_id?: Snowflake; + /** + * Member properties for this message's author + * + * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + member?: APIGuildMember; + /** + * Users specifically mentioned in the message + * + * The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/user#user-object + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + mentions: (APIUser & { member?: Omit })[]; +} /** * https://discord.com/developers/docs/topics/gateway#message-delete diff --git a/deno/payloads/v10/channel.ts b/deno/payloads/v10/channel.ts index 65c63e9b..9ae9ef6e 100644 --- a/deno/payloads/v10/channel.ts +++ b/deno/payloads/v10/channel.ts @@ -4,7 +4,6 @@ import type { APIApplication } from './application.ts'; import type { APIPartialEmoji } from './emoji.ts'; -import type { APIGuildMember } from './guild.ts'; import type { APIMessageInteraction } from './interactions.ts'; import type { APIRole } from './permissions.ts'; import type { APISticker, APIStickerItem } from './sticker.ts'; @@ -326,10 +325,6 @@ export interface APIMessage { * ID of the channel the message was sent in */ channel_id: Snowflake; - /** - * ID of the guild the message was sent in - */ - guild_id?: Snowflake; /** * The author of this message (only a valid user in the case where the message is generated by a user or bot user) * @@ -339,15 +334,6 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object */ author: APIUser; - /** - * Member properties for this message's author - * - * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events - * from text-based guild channels - * - * See https://discord.com/developers/docs/resources/guild#guild-member-object - */ - member?: APIGuildMember; /** * Contents of the message */ @@ -377,7 +363,7 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object * See https://discord.com/developers/docs/resources/guild#guild-member-object */ - mentions: (APIUser & { member?: Omit })[]; + mentions: APIUser[]; /** * Roles specifically mentioned in this message * diff --git a/deno/payloads/v9/channel.ts b/deno/payloads/v9/channel.ts index 4bd4ec8f..15b8e2c6 100644 --- a/deno/payloads/v9/channel.ts +++ b/deno/payloads/v9/channel.ts @@ -4,7 +4,6 @@ import type { APIApplication } from './application.ts'; import type { APIPartialEmoji } from './emoji.ts'; -import type { APIGuildMember } from './guild.ts'; import type { APIMessageInteraction } from './interactions.ts'; import type { APIRole } from './permissions.ts'; import type { APISticker, APIStickerItem } from './sticker.ts'; @@ -326,10 +325,6 @@ export interface APIMessage { * ID of the channel the message was sent in */ channel_id: Snowflake; - /** - * ID of the guild the message was sent in - */ - guild_id?: Snowflake; /** * The author of this message (only a valid user in the case where the message is generated by a user or bot user) * @@ -339,15 +334,6 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object */ author: APIUser; - /** - * Member properties for this message's author - * - * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events - * from text-based guild channels - * - * See https://discord.com/developers/docs/resources/guild#guild-member-object - */ - member?: APIGuildMember; /** * Contents of the message */ @@ -377,7 +363,7 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object * See https://discord.com/developers/docs/resources/guild#guild-member-object */ - mentions: (APIUser & { member?: Omit })[]; + mentions: APIUser[]; /** * Roles specifically mentioned in this message * diff --git a/gateway/v10.ts b/gateway/v10.ts index d03fa88a..c22076f1 100644 --- a/gateway/v10.ts +++ b/gateway/v10.ts @@ -1125,7 +1125,7 @@ export type GatewayMessageCreateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-create */ -export type GatewayMessageCreateDispatchData = APIMessage; +export type GatewayMessageCreateDispatchData = Omit & GatewayMessageEventExtraFields; /** * https://discord.com/developers/docs/topics/gateway#message-update @@ -1138,10 +1138,43 @@ export type GatewayMessageUpdateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-update */ -export type GatewayMessageUpdateDispatchData = { - id: Snowflake; - channel_id: Snowflake; -} & Partial; +export type GatewayMessageUpdateDispatchData = Omit, 'mentions'> & + GatewayMessageEventExtraFields & { + /** + * ID of the message + */ + id: Snowflake; + /** + * ID of the channel the message was sent in + */ + channel_id: Snowflake; + }; + +export interface GatewayMessageEventExtraFields { + /** + * ID of the guild the message was sent in + */ + guild_id?: Snowflake; + /** + * Member properties for this message's author + * + * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + member?: APIGuildMember; + /** + * Users specifically mentioned in the message + * + * The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/user#user-object + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + mentions: (APIUser & { member?: Omit })[]; +} /** * https://discord.com/developers/docs/topics/gateway#message-delete diff --git a/gateway/v9.ts b/gateway/v9.ts index a8f443bc..593f1be9 100644 --- a/gateway/v9.ts +++ b/gateway/v9.ts @@ -1124,7 +1124,7 @@ export type GatewayMessageCreateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-create */ -export type GatewayMessageCreateDispatchData = APIMessage; +export type GatewayMessageCreateDispatchData = Omit & GatewayMessageEventExtraFields; /** * https://discord.com/developers/docs/topics/gateway#message-update @@ -1137,10 +1137,43 @@ export type GatewayMessageUpdateDispatch = DataPayload< /** * https://discord.com/developers/docs/topics/gateway#message-update */ -export type GatewayMessageUpdateDispatchData = { - id: Snowflake; - channel_id: Snowflake; -} & Partial; +export type GatewayMessageUpdateDispatchData = Omit, 'mentions'> & + GatewayMessageEventExtraFields & { + /** + * ID of the message + */ + id: Snowflake; + /** + * ID of the channel the message was sent in + */ + channel_id: Snowflake; + }; + +export interface GatewayMessageEventExtraFields { + /** + * ID of the guild the message was sent in + */ + guild_id?: Snowflake; + /** + * Member properties for this message's author + * + * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + member?: APIGuildMember; + /** + * Users specifically mentioned in the message + * + * The `member` field is only present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events + * from text-based guild channels + * + * See https://discord.com/developers/docs/resources/user#user-object + * See https://discord.com/developers/docs/resources/guild#guild-member-object + */ + mentions: (APIUser & { member?: Omit })[]; +} /** * https://discord.com/developers/docs/topics/gateway#message-delete diff --git a/payloads/v10/channel.ts b/payloads/v10/channel.ts index f94d0320..9236f504 100644 --- a/payloads/v10/channel.ts +++ b/payloads/v10/channel.ts @@ -4,7 +4,6 @@ import type { APIApplication } from './application'; import type { APIPartialEmoji } from './emoji'; -import type { APIGuildMember } from './guild'; import type { APIMessageInteraction } from './interactions'; import type { APIRole } from './permissions'; import type { APISticker, APIStickerItem } from './sticker'; @@ -326,10 +325,6 @@ export interface APIMessage { * ID of the channel the message was sent in */ channel_id: Snowflake; - /** - * ID of the guild the message was sent in - */ - guild_id?: Snowflake; /** * The author of this message (only a valid user in the case where the message is generated by a user or bot user) * @@ -339,15 +334,6 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object */ author: APIUser; - /** - * Member properties for this message's author - * - * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events - * from text-based guild channels - * - * See https://discord.com/developers/docs/resources/guild#guild-member-object - */ - member?: APIGuildMember; /** * Contents of the message */ @@ -377,7 +363,7 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object * See https://discord.com/developers/docs/resources/guild#guild-member-object */ - mentions: (APIUser & { member?: Omit })[]; + mentions: APIUser[]; /** * Roles specifically mentioned in this message * diff --git a/payloads/v9/channel.ts b/payloads/v9/channel.ts index 89eca06a..a2f14bc9 100644 --- a/payloads/v9/channel.ts +++ b/payloads/v9/channel.ts @@ -4,7 +4,6 @@ import type { APIApplication } from './application'; import type { APIPartialEmoji } from './emoji'; -import type { APIGuildMember } from './guild'; import type { APIMessageInteraction } from './interactions'; import type { APIRole } from './permissions'; import type { APISticker, APIStickerItem } from './sticker'; @@ -326,10 +325,6 @@ export interface APIMessage { * ID of the channel the message was sent in */ channel_id: Snowflake; - /** - * ID of the guild the message was sent in - */ - guild_id?: Snowflake; /** * The author of this message (only a valid user in the case where the message is generated by a user or bot user) * @@ -339,15 +334,6 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object */ author: APIUser; - /** - * Member properties for this message's author - * - * The member object exists in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events - * from text-based guild channels - * - * See https://discord.com/developers/docs/resources/guild#guild-member-object - */ - member?: APIGuildMember; /** * Contents of the message */ @@ -377,7 +363,7 @@ export interface APIMessage { * See https://discord.com/developers/docs/resources/user#user-object * See https://discord.com/developers/docs/resources/guild#guild-member-object */ - mentions: (APIUser & { member?: Omit })[]; + mentions: APIUser[]; /** * Roles specifically mentioned in this message *