Skip to content

Commit

Permalink
refactor: make action row generic
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Feb 9, 2022
1 parent fc674a1 commit d68e4dc
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 76 deletions.
5 changes: 3 additions & 2 deletions deno/payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../mod.ts';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';

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

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

Expand Down
4 changes: 2 additions & 2 deletions deno/payloads/v8/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +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';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand Down Expand Up @@ -119,5 +119,5 @@ export interface APIModalInteractionResponseCallbackData {
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
components: APIActionRowComponent<APIModalComponent>[];
}
23 changes: 11 additions & 12 deletions deno/payloads/v8/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
Expand Down Expand Up @@ -1008,18 +1008,12 @@ export enum ComponentType {
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

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

/**
Expand Down Expand Up @@ -1200,6 +1194,11 @@ export interface APITextInputComponent extends APIBaseMessageComponent<Component
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;

export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
5 changes: 3 additions & 2 deletions deno/payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../mod.ts';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';

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

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

Expand Down
4 changes: 2 additions & 2 deletions deno/payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +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';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand Down Expand Up @@ -119,5 +119,5 @@ export interface APIModalInteractionResponseCallbackData {
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
components: APIActionRowComponent<APIModalComponent>[];
}
23 changes: 11 additions & 12 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
Expand Down Expand Up @@ -1173,18 +1173,12 @@ export enum ComponentType {
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

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

/**
Expand Down Expand Up @@ -1365,6 +1359,11 @@ export interface APITextInputComponent extends APIBaseMessageComponent<Component
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;

export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
5 changes: 3 additions & 2 deletions deno/rest/v8/channel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type {
APIActionRowComponent,
APIMessageComponent,
APIAllowedMentions,
APIAttachment,
APIChannel,
Expand Down Expand Up @@ -210,7 +211,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
Expand Down Expand Up @@ -344,7 +345,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;

/**
Expand Down
3 changes: 2 additions & 1 deletion deno/rest/v8/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v8/mod.ts';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals.ts';

Expand Down Expand Up @@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/
Expand Down
5 changes: 3 additions & 2 deletions deno/rest/v9/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type {
APIMessageComponent,
APIActionRowComponent,
APIAllowedMentions,
APIAttachment,
Expand Down Expand Up @@ -243,7 +244,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
Expand Down Expand Up @@ -377,7 +378,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;

/**
Expand Down
3 changes: 2 additions & 1 deletion deno/rest/v9/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v9/mod.ts';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals.ts';

Expand Down Expand Up @@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/
Expand Down
5 changes: 3 additions & 2 deletions payloads/v8/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../index';
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';

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

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

Expand Down
4 changes: 2 additions & 2 deletions payloads/v8/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MessageFlags } from '../index';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8';
import type { APIApplicationCommandOptionChoice } from './applicationCommands';
import type { APIModalActionRowComponent } from '../channel';
import type { APIActionRowComponent, APIModalComponent } from '../channel';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand Down Expand Up @@ -119,5 +119,5 @@ export interface APIModalInteractionResponseCallbackData {
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
components: APIActionRowComponent<APIModalComponent>[];
}
23 changes: 11 additions & 12 deletions payloads/v8/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
Expand Down Expand Up @@ -1008,18 +1008,12 @@ export const enum ComponentType {
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

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

/**
Expand Down Expand Up @@ -1200,6 +1194,11 @@ export interface APITextInputComponent extends APIBaseMessageComponent<Component
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent | APIModalComponent>
| APIButtonComponent
| APISelectMenuComponent;

export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
5 changes: 3 additions & 2 deletions payloads/v9/_interactions/modalSubmit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { APIBaseInteraction, InteractionType, APIModalActionRowComponent, ComponentType } from '../index';
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';

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

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

Expand Down
4 changes: 2 additions & 2 deletions payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MessageFlags } from '../index';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9';
import type { APIApplicationCommandOptionChoice } from './applicationCommands';
import type { APIModalActionRowComponent } from '../channel';
import type { APIActionRowComponent, APIModalComponent } from '../channel';

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
Expand Down Expand Up @@ -119,5 +119,5 @@ export interface APIModalInteractionResponseCallbackData {
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIModalActionRowComponent[];
components: APIActionRowComponent<APIModalComponent>[];
}
23 changes: 11 additions & 12 deletions payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
Expand Down Expand Up @@ -1173,18 +1173,12 @@ export const enum ComponentType {
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseMessageComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}

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

/**
Expand Down Expand Up @@ -1365,6 +1359,11 @@ export interface APITextInputComponent extends APIBaseMessageComponent<Component
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent | APIModalComponent>
| APIButtonComponent
| APISelectMenuComponent;

export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;

export type APIModalComponent = APIModalActionRowComponent | APITextInputComponent;
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;

0 comments on commit d68e4dc

Please sign in to comment.