Skip to content

Commit

Permalink
feat(Components): new select menus (#602)
Browse files Browse the repository at this point in the history
Co-authored-by: Almeida <almeidx@pm.me>
  • Loading branch information
advaith1 and almeidx committed Oct 20, 2022
1 parent 5053ac3 commit df1452d
Show file tree
Hide file tree
Showing 29 changed files with 713 additions and 269 deletions.
23 changes: 3 additions & 20 deletions deno/payloads/v10/_interactions/_applicationCommands/chatInput.ts
Expand Up @@ -43,14 +43,8 @@ import type {
APIApplicationCommandUserOption,
} from './_chatInput/user.ts';
import type { APIBaseApplicationCommandInteractionData } from './internals.ts';
import type { Snowflake } from '../../../../globals.ts';
import type { APIAttachment, APIRole, APIUser } from '../../mod.ts';
import type {
APIApplicationCommandInteractionWrapper,
APIInteractionDataResolvedChannel,
APIInteractionDataResolvedGuildMember,
ApplicationCommandType,
} from '../applicationCommands.ts';
import type { APIInteractionDataResolved } from '../../mod.ts';
import type { APIApplicationCommandInteractionWrapper, ApplicationCommandType } from '../applicationCommands.ts';
import type { APIDMInteractionWrapper, APIGuildInteractionWrapper } from '../base.ts';

export * from './_chatInput/attachment.ts';
Expand Down Expand Up @@ -114,18 +108,7 @@ export type APIApplicationCommandInteractionDataBasicOption =
export interface APIChatInputApplicationCommandInteractionData
extends APIBaseApplicationCommandInteractionData<ApplicationCommandType.ChatInput> {
options?: APIApplicationCommandInteractionDataOption[];
resolved?: APIChatInputApplicationCommandInteractionDataResolved;
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
export interface APIChatInputApplicationCommandInteractionDataResolved {
users?: Record<Snowflake, APIUser>;
roles?: Record<Snowflake, APIRole>;
members?: Record<Snowflake, APIInteractionDataResolvedGuildMember>;
channels?: Record<Snowflake, APIInteractionDataResolvedChannel>;
attachments?: Record<Snowflake, APIAttachment>;
resolved?: APIInteractionDataResolved;
}

/**
Expand Down
@@ -1,29 +1,16 @@
import type { APIBaseApplicationCommandInteractionData } from './internals.ts';
import type { Snowflake } from '../../../../globals.ts';
import type { APIMessage } from '../../channel.ts';
import type { APIUser } from '../../user.ts';
import type {
APIApplicationCommandInteractionWrapper,
APIInteractionDataResolvedGuildMember,
ApplicationCommandType,
} from '../applicationCommands.ts';
import type { APIDMInteractionWrapper, APIGuildInteractionWrapper } from '../base.ts';
import type { APIApplicationCommandInteractionWrapper, ApplicationCommandType } from '../applicationCommands.ts';
import type { APIDMInteractionWrapper, APIGuildInteractionWrapper, APIUserInteractionDataResolved } from '../base.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data
*/
export interface APIUserApplicationCommandInteractionData
extends APIBaseApplicationCommandInteractionData<ApplicationCommandType.User> {
target_id: Snowflake;
resolved: APIUserApplicationCommandInteractionDataResolved;
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
export interface APIUserApplicationCommandInteractionDataResolved {
users: Record<Snowflake, APIUser>;
members?: Record<Snowflake, APIInteractionDataResolvedGuildMember>;
resolved: APIUserInteractionDataResolved;
}

/**
Expand Down
18 changes: 0 additions & 18 deletions deno/payloads/v10/_interactions/applicationCommands.ts
Expand Up @@ -15,8 +15,6 @@ import type { APIBaseInteraction } from './base.ts';
import type { InteractionType } from './responses.ts';
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { LocalizationMap } from '../../../v10.ts';
import type { APIPartialChannel, APIThreadMetadata } from '../channel.ts';
import type { APIGuildMember } from '../guild.ts';

export * from './_applicationCommands/chatInput.ts';
export * from './_applicationCommands/contextMenu.ts';
Expand Down Expand Up @@ -107,22 +105,6 @@ export type APIApplicationCommandInteractionData =
| APIChatInputApplicationCommandInteractionData
| APIContextMenuInteractionData;

/**
* https://discord.com/developers/docs/resources/channel#channel-object
*/
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
thread_metadata?: APIThreadMetadata | null;
permissions: Permissions;
parent_id?: string | null;
}

/**
* https://discord.com/developers/docs/resources/guild#guild-member-object
*/
export interface APIInteractionDataResolvedGuildMember extends Omit<APIGuildMember, 'user' | 'deaf' | 'mute'> {
permissions: Permissions;
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
Expand Down
47 changes: 45 additions & 2 deletions deno/payloads/v10/_interactions/base.ts
@@ -1,7 +1,7 @@
import type { InteractionType } from './responses.ts';
import type { Permissions, Snowflake } from '../../../globals.ts';
import type { LocaleString } from '../../../v10.ts';
import type { APIMessage } from '../channel.ts';
import type { APIRole, LocaleString } from '../../../v10.ts';
import type { APIAttachment, APIMessage, APIPartialChannel, APIThreadMetadata } from '../channel.ts';
import type { APIGuildMember } from '../guild.ts';
import type { APIUser } from '../user.ts';

Expand Down Expand Up @@ -129,3 +129,46 @@ export type APIGuildInteractionWrapper<Original extends APIBaseInteraction<Inter
'user'
> &
Required<Pick<Original, 'member' | 'guild_id'>>;

/**
* https://discord.com/developers/docs/resources/channel#channel-object
*/
export interface APIInteractionDataResolvedChannel extends Required<APIPartialChannel> {
thread_metadata?: APIThreadMetadata | null;
permissions: Permissions;
parent_id?: string | null;
}

/**
* https://discord.com/developers/docs/resources/guild#guild-member-object
*/
export interface APIInteractionDataResolvedGuildMember extends Omit<APIGuildMember, 'user' | 'deaf' | 'mute'> {
permissions: Permissions;
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
export interface APIInteractionDataResolved {
users?: Record<Snowflake, APIUser>;
roles?: Record<Snowflake, APIRole>;
members?: Record<Snowflake, APIInteractionDataResolvedGuildMember>;
channels?: Record<Snowflake, APIInteractionDataResolvedChannel>;
attachments?: Record<Snowflake, APIAttachment>;
}

/**
* @deprecated Renamed to `APIInteractionDataResolved`
*/
export type APIChatInputApplicationCommandInteractionDataResolved = APIInteractionDataResolved;

/**
* `users` and optional `members` from APIInteractionDataResolved, for user commands and user selects
*/
export type APIUserInteractionDataResolved = Required<Pick<APIInteractionDataResolved, 'users'>> &
Pick<APIInteractionDataResolved, 'members'>;

/**
* @deprecated Renamed to `APIUserInteractionDataResolved`
*/
export type APIUserApplicationCommandInteractionDataResolved = APIUserInteractionDataResolved;
43 changes: 40 additions & 3 deletions deno/payloads/v10/_interactions/messageComponents.ts
@@ -1,4 +1,10 @@
import type { APIDMInteractionWrapper, APIGuildInteractionWrapper } from './base.ts';
import type {
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
APIInteractionDataResolved,
APIUserInteractionDataResolved,
} from './base.ts';
import type { Snowflake } from '../../../globals.ts';
import type { ComponentType } from '../channel.ts';
import type { APIBaseInteraction, InteractionType } from '../interactions.ts';

Expand Down Expand Up @@ -50,11 +56,42 @@ export interface APIMessageComponentBaseInteractionData<CType extends ComponentT

export type APIMessageButtonInteractionData = APIMessageComponentBaseInteractionData<ComponentType.Button>;

export interface APIMessageSelectMenuInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.SelectMenu> {
export interface APIMessageStringSelectInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.StringSelect> {
values: string[];
}

export interface APIMessageUserSelectInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.UserSelect> {
values: Snowflake[];
resolved: APIUserInteractionDataResolved;
}

export interface APIMessageRoleSelectInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.RoleSelect> {
values: Snowflake[];
resolved: Required<Pick<APIInteractionDataResolved, 'roles'>>;
}

export interface APIMessageMentionableSelectInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.MentionableSelect> {
values: Snowflake[];
resolved: Pick<APIInteractionDataResolved, 'users' | 'members' | 'roles'>;
}

export interface APIMessageChannelSelectInteractionData
extends APIMessageComponentBaseInteractionData<ComponentType.ChannelSelect> {
values: Snowflake[];
resolved: Required<Pick<APIInteractionDataResolved, 'channels'>>;
}

export type APIMessageSelectMenuInteractionData =
| APIMessageStringSelectInteractionData
| APIMessageUserSelectInteractionData
| APIMessageRoleSelectInteractionData
| APIMessageMentionableSelectInteractionData
| APIMessageChannelSelectInteractionData;

export type APIMessageComponentDMInteraction = APIDMInteractionWrapper<APIMessageComponentInteraction>;

export type APIMessageComponentGuildInteraction = APIGuildInteractionWrapper<APIMessageComponentInteraction>;
87 changes: 80 additions & 7 deletions deno/payloads/v10/channel.ts
Expand Up @@ -1313,13 +1313,38 @@ export enum ComponentType {
*/
Button,
/**
* Select Menu component
* Select menu for picking from defined text options
*/
SelectMenu,
StringSelect,
/**
* Text Input component
*/
TextInput,
/**
* Select menu for users
*/
UserSelect,
/**
* Select menu for roles
*/
RoleSelect,
/**
* Select menu for users and roles
*/
MentionableSelect,
/**
* Select menu for channels
*/
ChannelSelect,

// EVERYTHING BELOW THIS LINE SHOULD BE OLD NAMES FOR RENAMED ENUM MEMBERS //

/**
* Select menu for picking from defined text options
*
* @deprecated This is the old name for {@apilink ComponentType#StringSelect}
*/
SelectMenu = 3,
}

/**
Expand Down Expand Up @@ -1411,15 +1436,18 @@ export enum TextInputStyle {
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.SelectMenu> {
export interface APIBaseSelectMenuComponent<
T extends
| ComponentType.StringSelect
| ComponentType.UserSelect
| ComponentType.RoleSelect
| ComponentType.MentionableSelect
| ComponentType.ChannelSelect,
> extends APIBaseComponent<T> {
/**
* A developer-defined identifier for the select menu, max 100 characters
*/
custom_id: string;
/**
* The choices in the select, max 25
*/
options: APISelectMenuOption[];
/**
* Custom placeholder text if nothing is selected, max 150 characters
*/
Expand All @@ -1444,6 +1472,51 @@ export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.S
disabled?: boolean;
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APIStringSelectComponent extends APIBaseSelectMenuComponent<ComponentType.StringSelect> {
/**
* Specified choices in a select menu; max 25
*/
options: APISelectMenuOption[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIUserSelectComponent = APIBaseSelectMenuComponent<ComponentType.UserSelect>;

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

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APIMentionableSelectComponent = APIBaseSelectMenuComponent<ComponentType.MentionableSelect>;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APIChannelSelectComponent extends APIBaseSelectMenuComponent<ComponentType.ChannelSelect> {
/**
* List of channel types to include in the ChannelSelect component
*/
channel_types?: ChannelType[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export type APISelectMenuComponent =
| APIStringSelectComponent
| APIUserSelectComponent
| APIRoleSelectComponent
| APIMentionableSelectComponent
| APIChannelSelectComponent;

/**
* https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure
*/
Expand Down
23 changes: 3 additions & 20 deletions deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts
Expand Up @@ -43,14 +43,8 @@ import type {
APIApplicationCommandUserOption,
} from './_chatInput/user.ts';
import type { APIBaseApplicationCommandInteractionData } from './internals.ts';
import type { Snowflake } from '../../../../globals.ts';
import type { APIAttachment, APIRole, APIUser } from '../../mod.ts';
import type {
APIApplicationCommandInteractionWrapper,
APIInteractionDataResolvedChannel,
APIInteractionDataResolvedGuildMember,
ApplicationCommandType,
} from '../applicationCommands.ts';
import type { APIInteractionDataResolved } from '../../mod.ts';
import type { APIApplicationCommandInteractionWrapper, ApplicationCommandType } from '../applicationCommands.ts';
import type { APIDMInteractionWrapper, APIGuildInteractionWrapper } from '../base.ts';

export * from './_chatInput/attachment.ts';
Expand Down Expand Up @@ -114,18 +108,7 @@ export type APIApplicationCommandInteractionDataBasicOption =
export interface APIChatInputApplicationCommandInteractionData
extends APIBaseApplicationCommandInteractionData<ApplicationCommandType.ChatInput> {
options?: APIApplicationCommandInteractionDataOption[];
resolved?: APIChatInputApplicationCommandInteractionDataResolved;
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
export interface APIChatInputApplicationCommandInteractionDataResolved {
users?: Record<Snowflake, APIUser>;
roles?: Record<Snowflake, APIRole>;
members?: Record<Snowflake, APIInteractionDataResolvedGuildMember>;
channels?: Record<Snowflake, APIInteractionDataResolvedChannel>;
attachments?: Record<Snowflake, APIAttachment>;
resolved?: APIInteractionDataResolved;
}

/**
Expand Down

1 comment on commit df1452d

@vercel
Copy link

@vercel vercel bot commented on df1452d Oct 20, 2022

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.