Skip to content

Commit

Permalink
feat: default select menu values (#824)
Browse files Browse the repository at this point in the history
Co-authored-by: Renegade334 <[email protected]>
  • Loading branch information
jaw0r3k and Renegade334 authored Sep 23, 2023
1 parent 4309463 commit 1290c94
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 22 deletions.
64 changes: 58 additions & 6 deletions deno/payloads/v10/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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<T> {
/**
* List of default values for auto-populated select menu components
*/
default_values?: APISelectMenuDefaultValue<D>[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand All @@ -1625,28 +1644,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent<Com
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIUserSelectComponent = APIBaseSelectMenuComponent<ComponentType.UserSelect>;
export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.UserSelect,
SelectMenuDefaultValueType.User
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIRoleSelectComponent = APIBaseSelectMenuComponent<ComponentType.RoleSelect>;
export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.RoleSelect,
SelectMenuDefaultValueType.Role
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIMentionableSelectComponent = APIBaseSelectMenuComponent<ComponentType.MentionableSelect>;
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<ComponentType.ChannelSelect> {
export interface APIChannelSelectComponent
extends APIBaseAutoPopulatedSelectMenuComponent<ComponentType.ChannelSelect, SelectMenuDefaultValueType.Channel> {
/**
* 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<T extends SelectMenuDefaultValueType> {
type: T;
id: Snowflake;
}

export type APIAutoPopulatedSelectMenuComponent =
| APIChannelSelectComponent
| APIMentionableSelectComponent
| APIRoleSelectComponent
| APIUserSelectComponent;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand Down
63 changes: 58 additions & 5 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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<T> {
/**
* List of default values for auto-populated select menu components
*/
default_values?: APISelectMenuDefaultValue<D>[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand All @@ -1593,28 +1613,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent<Com
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIUserSelectComponent = APIBaseSelectMenuComponent<ComponentType.UserSelect>;
export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.UserSelect,
SelectMenuDefaultValueType.User
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIRoleSelectComponent = APIBaseSelectMenuComponent<ComponentType.RoleSelect>;
export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.RoleSelect,
SelectMenuDefaultValueType.Role
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIMentionableSelectComponent = APIBaseSelectMenuComponent<ComponentType.MentionableSelect>;
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<ComponentType.ChannelSelect> {
export interface APIChannelSelectComponent
extends APIBaseAutoPopulatedSelectMenuComponent<ComponentType.ChannelSelect, SelectMenuDefaultValueType.Channel> {
/**
* 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<T extends SelectMenuDefaultValueType> {
type: T;
id: Snowflake;
}

export type APIAutoPopulatedSelectMenuComponent =
| APIChannelSelectComponent
| APIMentionableSelectComponent
| APIRoleSelectComponent
| APIUserSelectComponent;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand Down
64 changes: 58 additions & 6 deletions payloads/v10/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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<T> {
/**
* List of default values for auto-populated select menu components
*/
default_values?: APISelectMenuDefaultValue<D>[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand All @@ -1625,28 +1644,61 @@ export interface APIStringSelectComponent extends APIBaseSelectMenuComponent<Com
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIUserSelectComponent = APIBaseSelectMenuComponent<ComponentType.UserSelect>;
export type APIUserSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.UserSelect,
SelectMenuDefaultValueType.User
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIRoleSelectComponent = APIBaseSelectMenuComponent<ComponentType.RoleSelect>;
export type APIRoleSelectComponent = APIBaseAutoPopulatedSelectMenuComponent<
ComponentType.RoleSelect,
SelectMenuDefaultValueType.Role
>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIMentionableSelectComponent = APIBaseSelectMenuComponent<ComponentType.MentionableSelect>;
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<ComponentType.ChannelSelect> {
export interface APIChannelSelectComponent
extends APIBaseAutoPopulatedSelectMenuComponent<ComponentType.ChannelSelect, SelectMenuDefaultValueType.Channel> {
/**
* 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<T extends SelectMenuDefaultValueType> {
type: T;
id: Snowflake;
}

export type APIAutoPopulatedSelectMenuComponent =
| APIChannelSelectComponent
| APIMentionableSelectComponent
| APIRoleSelectComponent
| APIUserSelectComponent;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand Down
Loading

1 comment on commit 1290c94

@vercel
Copy link

@vercel vercel bot commented on 1290c94 Sep 23, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.