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 2 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
20 changes: 20 additions & 0 deletions deno/payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent } from '../mod.ts';

/**
* https://discord.com/developers/docs/interactions/message-components#component-object-component-structure
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
*/
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: APIModalActionRowComponent[];
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
17 changes: 17 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,9 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}

export interface APIModalInteractionResponseCallbackData {
custom_id: string;
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
title: string;
components: APIModalActionRowComponent[];
}
43 changes: 43 additions & 0 deletions deno/payloads/v8/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,10 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Input Text component
*/
InputText,
}

/**
Expand All @@ -949,6 +953,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, APIActionRowComponent>[];
}

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

// TODO: Add link
export enum InputTextStyle {
Short = 1,
Paragraph,
}

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

// TODO: Add api links
export interface APIInputTextComponent extends APIBaseMessageComponent<ComponentType.InputText> {
/**
* One of input text styles
*/
style: InputTextStyle;
/**
* Text that appears on top of the input text field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
}

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

export type APIModalComponent = APIActionRowComponent | APIInputTextComponent;
20 changes: 20 additions & 0 deletions deno/payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent } from '../mod.ts';

/**
* https://discord.com/developers/docs/interactions/message-components#component-object-component-structure
*/
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: APIModalActionRowComponent[];
}

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
17 changes: 17 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,9 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}

export interface APIModalInteractionResponseCallbackData {
custom_id: string;
title: string;
components: APIModalActionRowComponent[];
}
43 changes: 43 additions & 0 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,10 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Input Text component
*/
InputText,
}

/**
Expand All @@ -1078,6 +1082,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, APIActionRowComponent>[];
}

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

// TODO: Add link
export enum InputTextStyle {
Short = 1,
Paragraph,
}

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

// TODO: Add api links
export interface APIInputTextComponent extends APIBaseMessageComponent<ComponentType.InputText> {
/**
* One of input text styles
*/
style: InputTextStyle;
/**
* Text that appears on top of the input text field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
}

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

export type APIModalComponent = APIActionRowComponent | APIInputTextComponent;
20 changes: 20 additions & 0 deletions payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent } from '../index';

/**
* https://discord.com/developers/docs/interactions/message-components#component-object-component-structure
*/
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: APIModalActionRowComponent[];
}

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

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand All @@ -10,6 +11,7 @@ export const 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 const 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,9 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}

export interface APIModalInteractionResponseCallbackData {
custom_id: string;
title: string;
components: APIModalActionRowComponent[];
}