Skip to content

Commit

Permalink
feat: add autocomplete api types
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Sep 23, 2021
1 parent a787426 commit 0aa5841
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { APIApplicationCommandOption, ApplicationCommandOptionType } from './chatInput.ts';

const data: APIApplicationCommandOption = {
type: ApplicationCommandOptionType.Number,
name: 'test',
description: 'test',
};
15 changes: 13 additions & 2 deletions deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
options?: APIApplicationCommandOption[];
}

// This is here because auto completed command options aren't a seperate 'type', and it only
// applies to the the choices types.
type AutoCompleteOrChoices =
| { type: ApplicationCommandOptionType.String; choices?: never; autocomplete: true }
| { choices?: APIApplicationCommandOptionChoice[]; autocomplete?: false };

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices` one
*/
export interface APIApplicationCommandArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
export type APIApplicationCommandArgumentOptions = Omit<APIApplicationCommandOptionBase, 'type'> & {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
} & AutoCompleteOrChoices;

export interface APIApplicationCommandAutocompleteOptions
extends Omit<APIApplicationCommandArgumentOptions, 'choices' | 'autocomplete'> {
choices?: never;
autocomplete: true;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions deno/payloads/v9/_interactions/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { APIBaseInteraction, ApplicationCommandOptionType, InteractionType } from '../mod.ts';

export type APICommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APICommandAutocompleteInteractionData
>;

export interface APICommandAutocompleteInteractionData {
/**
* The name of the parameter
*/
name: string;
/**
* Value of application command option type
*/
type: ApplicationCommandOptionType;
/**
* Value of the command option
*/
value?: string;
/**
* Whether the field is focused by the user
*/
focused: boolean;
}
9 changes: 9 additions & 0 deletions deno/payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
}

/**
Expand All @@ -24,6 +25,10 @@ export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APICommandAutocompleteResponse {
type: InteractionResponseType.ApplicationCommandAutocompleteResult;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -67,6 +72,10 @@ export enum InteractionResponseType {
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
/**
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
}

/**
Expand Down
7 changes: 6 additions & 1 deletion deno/payloads/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands.ts';
import type { APICommandAutocompleteInteraction } from './_interactions/autocomplete.ts';

export * from './_interactions/base.ts';
export * from './_interactions/messageComponents.ts';
Expand All @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands.ts';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction;
export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APICommandAutocompleteInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
4 changes: 4 additions & 0 deletions deno/rest/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit<
*/
export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody {
type?: ApplicationCommandType.ChatInput;
/**
* Whether this application command option should be autocompleted
*/
auto_complete?: boolean;
description: string;
}

Expand Down
5 changes: 5 additions & 0 deletions deno/rest/v9/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
APIMessage,
APIWebhook,
APIAttachment,
APIApplicationCommandOptionChoice,
} from '../../payloads/v9/mod.ts';
import type { Nullable } from '../../utils/internals.ts';

Expand Down Expand Up @@ -135,6 +136,10 @@ export interface RESTPostAPIWebhookWithTokenJSONBody {
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
/**
* Autocomplete choices (limited to 25 choices)
*/
choices?: APIApplicationCommandOptionChoice[];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { APIApplicationCommandOption, ApplicationCommandOptionType } from './chatInput';

const data: APIApplicationCommandOption = {
type: ApplicationCommandOptionType.Number,
name: 'test',
description: 'test',
};
15 changes: 13 additions & 2 deletions payloads/v9/_interactions/_applicationCommands/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
options?: APIApplicationCommandOption[];
}

// This is here because auto completed command options aren't a seperate 'type', and it only
// applies to the the choices types.
type AutoCompleteOrChoices =
| { type: ApplicationCommandOptionType.String; choices?: never; autocomplete: true }
| { choices?: APIApplicationCommandOptionChoice[]; autocomplete?: false };

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
*
* In contrast to `APIApplicationCommandSubCommandOptions`, these types cannot have an `options` array,
* but they can have a `choices` one
*/
export interface APIApplicationCommandArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
export type APIApplicationCommandArgumentOptions = Omit<APIApplicationCommandOptionBase, 'type'> & {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
choices?: APIApplicationCommandOptionChoice[];
} & AutoCompleteOrChoices;

export interface APIApplicationCommandAutocompleteOptions
extends Omit<APIApplicationCommandArgumentOptions, 'choices' | 'autocomplete'> {
choices?: never;
autocomplete: true;
}

/**
Expand Down
25 changes: 25 additions & 0 deletions payloads/v9/_interactions/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { APIBaseInteraction, ApplicationCommandOptionType, InteractionType } from '..';

export type APICommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APICommandAutocompleteInteractionData
>;

export interface APICommandAutocompleteInteractionData {
/**
* The name of the parameter
*/
name: string;
/**
* Value of application command option type
*/
type: ApplicationCommandOptionType;
/**
* Value of the command option
*/
value?: string;
/**
* Whether the field is focused by the user
*/
focused: boolean;
}
9 changes: 9 additions & 0 deletions payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
}

/**
Expand All @@ -24,6 +25,10 @@ export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APICommandAutocompleteResponse {
type: InteractionResponseType.ApplicationCommandAutocompleteResult;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -67,6 +72,10 @@ export const enum InteractionResponseType {
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
/**
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
}

/**
Expand Down
7 changes: 6 additions & 1 deletion payloads/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
APIApplicationCommandGuildInteraction,
APIApplicationCommandInteraction,
} from './_interactions/applicationCommands';
import type { APICommandAutocompleteInteraction } from './_interactions/autocomplete';

export * from './_interactions/base';
export * from './_interactions/messageComponents';
Expand All @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction;
export type APIInteraction =
| APIPingInteraction
| APIApplicationCommandInteraction
| APIMessageComponentInteraction
| APICommandAutocompleteInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
4 changes: 4 additions & 0 deletions rest/v9/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit<
*/
export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody {
type?: ApplicationCommandType.ChatInput;
/**
* Whether this application command option should be autocompleted
*/
auto_complete?: boolean;
description: string;
}

Expand Down
5 changes: 5 additions & 0 deletions rest/v9/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
APIMessage,
APIWebhook,
APIAttachment,
APIApplicationCommandOptionChoice,
} from '../../payloads/v9/index';
import type { Nullable } from '../../utils/internals';

Expand Down Expand Up @@ -135,6 +136,10 @@ export interface RESTPostAPIWebhookWithTokenJSONBody {
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
/**
* Autocomplete choices (limited to 25 choices)
*/
choices?: APIApplicationCommandOptionChoice[];
}

/**
Expand Down

0 comments on commit 0aa5841

Please sign in to comment.