Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Interactions): add modal and text input interactions #243

Merged
merged 15 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions deno/payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../mod.ts';

export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}

export interface ModalSubmitActionRowComponent extends Omit<APIModalActionRowComponent, 'components'> {
components: ModalSubmitComponent[];
}

export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
29 changes: 29 additions & 0 deletions deno/payloads/v8/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';
import type { APIModalActionRowComponent } from '../channel.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand All @@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}

/**
Expand All @@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}

export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}

/**
Expand All @@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
}
59 changes: 59 additions & 0 deletions deno/payloads/v8/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}

/**
Expand All @@ -1011,6 +1015,13 @@ export interface APIActionRowComponent extends APIBaseMessageComponent<Component
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

export interface APIModalActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIModalComponent, APIModalActionRowComponent>[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
Expand Down Expand Up @@ -1078,6 +1089,14 @@ export enum ButtonStyle {
Link,
}

/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand Down Expand Up @@ -1140,7 +1159,47 @@ export interface APISelectMenuOption {
default?: boolean;
}

/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseMessageComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}

/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
1 change: 1 addition & 0 deletions deno/payloads/v8/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './_interactions/messageComponents.ts';
export * from './_interactions/ping.ts';
export * from './_interactions/responses.ts';
export * from './_interactions/applicationCommands.ts';
export * from './_interactions/modalSubmit.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
27 changes: 27 additions & 0 deletions deno/payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../mod.ts';

export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}

export interface ModalSubmitActionRowComponent extends Omit<APIModalActionRowComponent, 'components'> {
components: ModalSubmitComponent[];
}

export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
29 changes: 29 additions & 0 deletions deno/payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';
import type { APIModalActionRowComponent } from '../channel.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand All @@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}

/**
Expand All @@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}

export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}

/**
Expand All @@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
}
59 changes: 59 additions & 0 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,10 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}

/**
Expand All @@ -1176,6 +1180,13 @@ export interface APIActionRowComponent extends APIBaseMessageComponent<Component
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

export interface APIModalActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIModalComponent, APIModalActionRowComponent>[];
}

/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
Expand Down Expand Up @@ -1243,6 +1254,14 @@ export enum ButtonStyle {
Link,
}

/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}

/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
Expand Down Expand Up @@ -1305,7 +1324,47 @@ export interface APISelectMenuOption {
default?: boolean;
}

/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseMessageComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}

/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
1 change: 1 addition & 0 deletions deno/payloads/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './_interactions/messageComponents.ts';
export * from './_interactions/ping.ts';
export * from './_interactions/responses.ts';
export * from './_interactions/applicationCommands.ts';
export * from './_interactions/modalSubmit.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
27 changes: 27 additions & 0 deletions payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../index';

export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}

export interface ModalSubmitActionRowComponent extends Omit<APIModalActionRowComponent, 'components'> {
components: ModalSubmitComponent[];
}

export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;