From 1290c942abdd8c2d9bf97aa2807f45073970f823 Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Sat, 23 Sep 2023 20:14:35 +0200 Subject: [PATCH] feat: default select menu values (#824) Co-authored-by: Renegade334 --- deno/payloads/v10/channel.ts | 64 ++++++++++++++++++++++++++++++++---- deno/payloads/v9/channel.ts | 63 ++++++++++++++++++++++++++++++++--- payloads/v10/channel.ts | 64 ++++++++++++++++++++++++++++++++---- payloads/v9/channel.ts | 63 ++++++++++++++++++++++++++++++++--- 4 files changed, 232 insertions(+), 22 deletions(-) diff --git a/deno/payloads/v10/channel.ts b/deno/payloads/v10/channel.ts index f63b7f0cb..9fd8343a3 100644 --- a/deno/payloads/v10/channel.ts +++ b/deno/payloads/v10/channel.ts @@ -6,7 +6,7 @@ import type { Permissions, Snowflake } from '../../globals.ts'; 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 { APIInteractionDataResolved, APIMessageInteraction } from './interactions.ts'; import type { APIRole } from './permissions.ts'; import type { APISticker, APIStickerItem } from './sticker.ts'; import type { APIUser } from './user.ts'; @@ -679,11 +679,16 @@ export interface APIMessage { * It can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread */ position?: number; - /** * Data of the role subscription purchase or renewal that prompted this `ROLE_SUBSCRIPTION_PURCHASE` message */ role_subscription_data?: APIMessageRoleSubscriptionData; + /** + * Data for users, members, channels, and roles in the message's auto-populated select menus + * + * See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure + */ + resolved?: APIInteractionDataResolved; } /** @@ -1612,6 +1617,20 @@ export interface APIBaseSelectMenuComponent< disabled?: boolean; } +export interface APIBaseAutoPopulatedSelectMenuComponent< + T extends + | ComponentType.UserSelect + | ComponentType.RoleSelect + | ComponentType.MentionableSelect + | ComponentType.ChannelSelect, + D extends SelectMenuDefaultValueType, +> extends APIBaseSelectMenuComponent { + /** + * List of default values for auto-populated select menu components + */ + default_values?: APISelectMenuDefaultValue[]; +} + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ @@ -1625,28 +1644,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent; +export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.UserSelect, + SelectMenuDefaultValueType.User +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIRoleSelectComponent = APIBaseSelectMenuComponent; +export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.RoleSelect, + SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIMentionableSelectComponent = APIBaseSelectMenuComponent; +export type APIMentionableSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.MentionableSelect, + SelectMenuDefaultValueType.User | SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export interface APIChannelSelectComponent extends APIBaseSelectMenuComponent { +export interface APIChannelSelectComponent + extends APIBaseAutoPopulatedSelectMenuComponent { /** * List of channel types to include in the ChannelSelect component */ channel_types?: ChannelType[]; } +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export enum SelectMenuDefaultValueType { + Channel = 'channel', + Role = 'role', + User = 'user', +} + +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export interface APISelectMenuDefaultValue { + type: T; + id: Snowflake; +} + +export type APIAutoPopulatedSelectMenuComponent = + | APIChannelSelectComponent + | APIMentionableSelectComponent + | APIRoleSelectComponent + | APIUserSelectComponent; + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ diff --git a/deno/payloads/v9/channel.ts b/deno/payloads/v9/channel.ts index e7c86b375..f0a96c12f 100644 --- a/deno/payloads/v9/channel.ts +++ b/deno/payloads/v9/channel.ts @@ -6,7 +6,7 @@ import type { Permissions, Snowflake } from '../../globals.ts'; 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 { APIInteractionDataResolved, APIMessageInteraction } from './interactions.ts'; import type { APIRole } from './permissions.ts'; import type { APISticker, APIStickerItem } from './sticker.ts'; import type { APIUser } from './user.ts'; @@ -670,6 +670,12 @@ export interface APIMessage { * It can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread */ position?: number; + /** + * Data for users, members, channels, and roles in the message's auto-populated select menus + * + * See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure + */ + resolved?: APIInteractionDataResolved; } /** @@ -1580,6 +1586,20 @@ export interface APIBaseSelectMenuComponent< disabled?: boolean; } +export interface APIBaseAutoPopulatedSelectMenuComponent< + T extends + | ComponentType.UserSelect + | ComponentType.RoleSelect + | ComponentType.MentionableSelect + | ComponentType.ChannelSelect, + D extends SelectMenuDefaultValueType, +> extends APIBaseSelectMenuComponent { + /** + * List of default values for auto-populated select menu components + */ + default_values?: APISelectMenuDefaultValue[]; +} + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ @@ -1593,28 +1613,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent; +export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.UserSelect, + SelectMenuDefaultValueType.User +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIRoleSelectComponent = APIBaseSelectMenuComponent; +export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.RoleSelect, + SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIMentionableSelectComponent = APIBaseSelectMenuComponent; +export type APIMentionableSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.MentionableSelect, + SelectMenuDefaultValueType.User | SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export interface APIChannelSelectComponent extends APIBaseSelectMenuComponent { +export interface APIChannelSelectComponent + extends APIBaseAutoPopulatedSelectMenuComponent { /** * List of channel types to include in the ChannelSelect component */ channel_types?: ChannelType[]; } +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export enum SelectMenuDefaultValueType { + Channel = 'channel', + Role = 'role', + User = 'user', +} + +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export interface APISelectMenuDefaultValue { + type: T; + id: Snowflake; +} + +export type APIAutoPopulatedSelectMenuComponent = + | APIChannelSelectComponent + | APIMentionableSelectComponent + | APIRoleSelectComponent + | APIUserSelectComponent; + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ diff --git a/payloads/v10/channel.ts b/payloads/v10/channel.ts index 366091478..6b621c3db 100644 --- a/payloads/v10/channel.ts +++ b/payloads/v10/channel.ts @@ -6,7 +6,7 @@ import type { Permissions, Snowflake } from '../../globals'; import type { APIApplication } from './application'; import type { APIPartialEmoji } from './emoji'; import type { APIGuildMember } from './guild'; -import type { APIMessageInteraction } from './interactions'; +import type { APIInteractionDataResolved, APIMessageInteraction } from './interactions'; import type { APIRole } from './permissions'; import type { APISticker, APIStickerItem } from './sticker'; import type { APIUser } from './user'; @@ -679,11 +679,16 @@ export interface APIMessage { * It can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread */ position?: number; - /** * Data of the role subscription purchase or renewal that prompted this `ROLE_SUBSCRIPTION_PURCHASE` message */ role_subscription_data?: APIMessageRoleSubscriptionData; + /** + * Data for users, members, channels, and roles in the message's auto-populated select menus + * + * See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure + */ + resolved?: APIInteractionDataResolved; } /** @@ -1612,6 +1617,20 @@ export interface APIBaseSelectMenuComponent< disabled?: boolean; } +export interface APIBaseAutoPopulatedSelectMenuComponent< + T extends + | ComponentType.UserSelect + | ComponentType.RoleSelect + | ComponentType.MentionableSelect + | ComponentType.ChannelSelect, + D extends SelectMenuDefaultValueType, +> extends APIBaseSelectMenuComponent { + /** + * List of default values for auto-populated select menu components + */ + default_values?: APISelectMenuDefaultValue[]; +} + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ @@ -1625,28 +1644,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent; +export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.UserSelect, + SelectMenuDefaultValueType.User +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIRoleSelectComponent = APIBaseSelectMenuComponent; +export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.RoleSelect, + SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIMentionableSelectComponent = APIBaseSelectMenuComponent; +export type APIMentionableSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.MentionableSelect, + SelectMenuDefaultValueType.User | SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export interface APIChannelSelectComponent extends APIBaseSelectMenuComponent { +export interface APIChannelSelectComponent + extends APIBaseAutoPopulatedSelectMenuComponent { /** * List of channel types to include in the ChannelSelect component */ channel_types?: ChannelType[]; } +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export enum SelectMenuDefaultValueType { + Channel = 'channel', + Role = 'role', + User = 'user', +} + +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export interface APISelectMenuDefaultValue { + type: T; + id: Snowflake; +} + +export type APIAutoPopulatedSelectMenuComponent = + | APIChannelSelectComponent + | APIMentionableSelectComponent + | APIRoleSelectComponent + | APIUserSelectComponent; + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ diff --git a/payloads/v9/channel.ts b/payloads/v9/channel.ts index a9bce02d0..27a1fd5db 100644 --- a/payloads/v9/channel.ts +++ b/payloads/v9/channel.ts @@ -6,7 +6,7 @@ import type { Permissions, Snowflake } from '../../globals'; import type { APIApplication } from './application'; import type { APIPartialEmoji } from './emoji'; import type { APIGuildMember } from './guild'; -import type { APIMessageInteraction } from './interactions'; +import type { APIInteractionDataResolved, APIMessageInteraction } from './interactions'; import type { APIRole } from './permissions'; import type { APISticker, APIStickerItem } from './sticker'; import type { APIUser } from './user'; @@ -670,6 +670,12 @@ export interface APIMessage { * It can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread */ position?: number; + /** + * Data for users, members, channels, and roles in the message's auto-populated select menus + * + * See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure + */ + resolved?: APIInteractionDataResolved; } /** @@ -1580,6 +1586,20 @@ export interface APIBaseSelectMenuComponent< disabled?: boolean; } +export interface APIBaseAutoPopulatedSelectMenuComponent< + T extends + | ComponentType.UserSelect + | ComponentType.RoleSelect + | ComponentType.MentionableSelect + | ComponentType.ChannelSelect, + D extends SelectMenuDefaultValueType, +> extends APIBaseSelectMenuComponent { + /** + * List of default values for auto-populated select menu components + */ + default_values?: APISelectMenuDefaultValue[]; +} + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ @@ -1593,28 +1613,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent; +export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.UserSelect, + SelectMenuDefaultValueType.User +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIRoleSelectComponent = APIBaseSelectMenuComponent; +export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.RoleSelect, + SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export type APIMentionableSelectComponent = APIBaseSelectMenuComponent; +export type APIMentionableSelectComponent = APIBaseAutoPopulatedSelectMenuComponent< + ComponentType.MentionableSelect, + SelectMenuDefaultValueType.User | SelectMenuDefaultValueType.Role +>; /** * https://discord.com/developers/docs/interactions/message-components#select-menus */ -export interface APIChannelSelectComponent extends APIBaseSelectMenuComponent { +export interface APIChannelSelectComponent + extends APIBaseAutoPopulatedSelectMenuComponent { /** * List of channel types to include in the ChannelSelect component */ channel_types?: ChannelType[]; } +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export enum SelectMenuDefaultValueType { + Channel = 'channel', + Role = 'role', + User = 'user', +} + +/** + * https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-default-value-structure + */ +export interface APISelectMenuDefaultValue { + type: T; + id: Snowflake; +} + +export type APIAutoPopulatedSelectMenuComponent = + | APIChannelSelectComponent + | APIMentionableSelectComponent + | APIRoleSelectComponent + | APIUserSelectComponent; + /** * https://discord.com/developers/docs/interactions/message-components#select-menus */