Skip to content

Commit

Permalink
fix(APIInteraction): add modal submit interaction & make data requi…
Browse files Browse the repository at this point in the history
…red in APIModalSubmit (#321)
  • Loading branch information
almeidx authored Feb 11, 2022
1 parent 72e9617 commit f88727b
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 20 deletions.
21 changes: 19 additions & 2 deletions deno/payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';
import type {
APIBaseInteraction,
InteractionType,
ComponentType,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
} from '../mod.ts';

export interface ModalSubmitComponent {
type: ComponentType;
Expand All @@ -25,4 +31,15 @@ export interface APIModalSubmission {
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission> &
Required<Pick<APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>, 'data'>>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitDMInteraction = APIDMInteractionWrapper<APIModalSubmitInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitGuildInteraction = APIGuildInteractionWrapper<APIModalSubmitInteraction>;
18 changes: 15 additions & 3 deletions deno/payloads/v8/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import type {
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands.ts';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
APIModalSubmitInteraction,
} from './_interactions/modalSubmit.ts';

export * from './_interactions/base.ts';
export * from './_interactions/messageComponents.ts';
Expand All @@ -25,14 +30,21 @@ export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APIApplicationCommandAutocompleteInteraction;
| APIApplicationCommandAutocompleteInteraction
| APIModalSubmitInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIDMInteraction = APIApplicationCommandDMInteraction | APIMessageComponentDMInteraction;
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIModalSubmitDMInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIGuildInteraction = APIApplicationCommandGuildInteraction | APIMessageComponentGuildInteraction;
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIModalSubmitGuildInteraction;
21 changes: 19 additions & 2 deletions deno/payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';
import type {
APIBaseInteraction,
InteractionType,
ComponentType,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
} from '../mod.ts';

export interface ModalSubmitComponent {
type: ComponentType;
Expand All @@ -25,4 +31,15 @@ export interface APIModalSubmission {
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission> &
Required<Pick<APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>, 'data'>>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitDMInteraction = APIDMInteractionWrapper<APIModalSubmitInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitGuildInteraction = APIGuildInteractionWrapper<APIModalSubmitInteraction>;
18 changes: 15 additions & 3 deletions deno/payloads/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import type {
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands.ts';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
APIModalSubmitInteraction,
} from './_interactions/modalSubmit.ts';

export * from './_interactions/base.ts';
export * from './_interactions/messageComponents.ts';
Expand All @@ -25,14 +30,21 @@ export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APIApplicationCommandAutocompleteInteraction;
| APIApplicationCommandAutocompleteInteraction
| APIModalSubmitInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIDMInteraction = APIApplicationCommandDMInteraction | APIMessageComponentDMInteraction;
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIModalSubmitDMInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIGuildInteraction = APIApplicationCommandGuildInteraction | APIMessageComponentGuildInteraction;
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIModalSubmitGuildInteraction;
21 changes: 19 additions & 2 deletions payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';
import type {
APIBaseInteraction,
InteractionType,
ComponentType,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
} from '../index';

export interface ModalSubmitComponent {
type: ComponentType;
Expand All @@ -25,4 +31,15 @@ export interface APIModalSubmission {
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission> &
Required<Pick<APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>, 'data'>>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitDMInteraction = APIDMInteractionWrapper<APIModalSubmitInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitGuildInteraction = APIGuildInteractionWrapper<APIModalSubmitInteraction>;
18 changes: 15 additions & 3 deletions payloads/v8/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import type {
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
APIModalSubmitInteraction,
} from './_interactions/modalSubmit';

export * from './_interactions/base';
export * from './_interactions/messageComponents';
Expand All @@ -25,14 +30,21 @@ export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APIApplicationCommandAutocompleteInteraction;
| APIApplicationCommandAutocompleteInteraction
| APIModalSubmitInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIDMInteraction = APIApplicationCommandDMInteraction | APIMessageComponentDMInteraction;
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIModalSubmitDMInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIGuildInteraction = APIApplicationCommandGuildInteraction | APIMessageComponentGuildInteraction;
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIModalSubmitGuildInteraction;
21 changes: 19 additions & 2 deletions payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';
import type {
APIBaseInteraction,
InteractionType,
ComponentType,
APIDMInteractionWrapper,
APIGuildInteractionWrapper,
} from '../index';

export interface ModalSubmitComponent {
type: ComponentType;
Expand All @@ -25,4 +31,15 @@ export interface APIModalSubmission {
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission> &
Required<Pick<APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>, 'data'>>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitDMInteraction = APIDMInteractionWrapper<APIModalSubmitInteraction>;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitGuildInteraction = APIGuildInteractionWrapper<APIModalSubmitInteraction>;
18 changes: 15 additions & 3 deletions payloads/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import type {
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands';
import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete';
import type {
APIModalSubmitDMInteraction,
APIModalSubmitGuildInteraction,
APIModalSubmitInteraction,
} from './_interactions/modalSubmit';

export * from './_interactions/base';
export * from './_interactions/messageComponents';
Expand All @@ -25,14 +30,21 @@ export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APIApplicationCommandAutocompleteInteraction;
| APIApplicationCommandAutocompleteInteraction
| APIModalSubmitInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIDMInteraction = APIApplicationCommandDMInteraction | APIMessageComponentDMInteraction;
export type APIDMInteraction =
| APIApplicationCommandDMInteraction
| APIMessageComponentDMInteraction
| APIModalSubmitDMInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIGuildInteraction = APIApplicationCommandGuildInteraction | APIMessageComponentGuildInteraction;
export type APIGuildInteraction =
| APIApplicationCommandGuildInteraction
| APIMessageComponentGuildInteraction
| APIModalSubmitGuildInteraction;
5 changes: 5 additions & 0 deletions tests/v9/interactions.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
APIInteraction,
APIInteractionGuildMember,
APIMessageComponentInteraction,
APIModalSubmission,
APIUser,
ComponentType,
InteractionType,
Expand Down Expand Up @@ -37,6 +38,10 @@ if (interaction.type === InteractionType.MessageComponent) {
}
}

if (interaction.type === InteractionType.ModalSubmit) {
expectType<APIModalSubmission>(interaction.data);
}

declare const dmInteraction: APIDMInteraction;

expectType<APIUser>(dmInteraction.user);
Expand Down

0 comments on commit f88727b

Please sign in to comment.