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 autocomplete api types #205

Merged
merged 18 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase {
description: string;
default?: boolean;
required?: boolean;
autocomplete?: never;
}

/**
Expand All @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase {
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandOptionBase;
| APIApplicationCommandAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -46,12 +48,29 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* 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 interface APIApplicationCommandArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
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 `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
autocomplete: true;
}

/**
Expand Down Expand Up @@ -109,6 +128,16 @@ export interface ApplicationCommandInteractionDataOptionSubCommandGroup {
options: ApplicationCommandInteractionDataOptionSubCommand[];
}

export interface ApplicationCommandInteractionDataOptionAutocomplete {
name: string;
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
value?: string | number;
focused?: boolean;
}

export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionString
| ApplicationCommandInteractionDataOptionRole
Expand All @@ -117,7 +146,8 @@ export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionMentionable
| ApplicationCommandInteractionDataOptionInteger
| ApplicationCommandInteractionDataOptionNumber
| ApplicationCommandInteractionDataOptionBoolean;
| ApplicationCommandInteractionDataOptionBoolean
| ApplicationCommandInteractionDataOptionAutocomplete;

export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase<
ApplicationCommandOptionType.String,
Expand Down
6 changes: 6 additions & 0 deletions deno/payloads/v8/_interactions/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../mod.ts';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIApplicationCommandInteractionData
>;
18 changes: 17 additions & 1 deletion deno/payloads/v8/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';

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

/**
Expand All @@ -18,12 +20,18 @@ export type APIInteractionResponse =
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
| APIInteractionResponseUpdateMessage
| APICommandAutocompleteResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APICommandAutocompleteResponse {
type: InteractionResponseType.ApplicationCommandAutocompleteResult;
data: APICommandAutocompleteInteractionResponseCallbackData;
}

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

/**
Expand All @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit<
RESTPostAPIWebhookWithTokenJSONBody,
'username' | 'avatar_url'
> & { flags?: MessageFlags };

export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
7 changes: 6 additions & 1 deletion deno/payloads/v8/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 { APIApplicationCommandAutocompleteInteraction } 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
| APIApplicationCommandAutocompleteInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase {
description: string;
default?: boolean;
required?: boolean;
autocomplete?: never;
}

/**
Expand All @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase {
export type APIApplicationCommandOption =
| APIApplicationCommandArgumentOptions
| APIApplicationCommandSubCommandOptions
| APIApplicationCommandOptionBase
| APIApplicationCommandChannelOptions
| APIApplicationCommandOptionBase;
| APIApplicationCommandAutocompleteOptions;

/**
* This type is exported as a way to make it stricter for you when you're writing your commands
Expand All @@ -44,14 +46,31 @@ export interface APIApplicationCommandSubCommandOptions extends Omit<APIApplicat
* 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
* but they can have a either a `choices` or a `autocomplete` field where it's set to false.
*/
export interface APIApplicationCommandArgumentOptions extends Omit<APIApplicationCommandOptionBase, 'type'> {
export interface APIApplicationCommandArgumentOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
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 `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array,
* but they can a `autocomplete` field where it's set to `true`
*/
export interface APIApplicationCommandAutocompleteOptions
extends Omit<APIApplicationCommandOptionBase, 'type' | 'autocomplete'> {
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
autocomplete: true;
}

/**
Expand Down Expand Up @@ -109,6 +128,16 @@ export interface ApplicationCommandInteractionDataOptionSubCommandGroup {
options: ApplicationCommandInteractionDataOptionSubCommand[];
}

export interface ApplicationCommandInteractionDataOptionAutocomplete {
name: string;
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
value?: string | number;
focused?: boolean;
}

export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionString
| ApplicationCommandInteractionDataOptionRole
Expand All @@ -117,7 +146,8 @@ export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionMentionable
| ApplicationCommandInteractionDataOptionInteger
| ApplicationCommandInteractionDataOptionNumber
| ApplicationCommandInteractionDataOptionBoolean;
| ApplicationCommandInteractionDataOptionBoolean
| ApplicationCommandInteractionDataOptionAutocomplete;

export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase<
ApplicationCommandOptionType.String,
Expand Down
6 changes: 6 additions & 0 deletions deno/payloads/v9/_interactions/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../mod.ts';

export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction<
InteractionType.ApplicationCommandAutocomplete,
APIApplicationCommandInteractionData
>;
18 changes: 17 additions & 1 deletion deno/payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';

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

/**
Expand All @@ -18,12 +20,18 @@ export type APIInteractionResponse =
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
| APIInteractionResponseUpdateMessage
| APICommandAutocompleteResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APICommandAutocompleteResponse {
type: InteractionResponseType.ApplicationCommandAutocompleteResult;
data: APICommandAutocompleteInteractionResponseCallbackData;
}

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

/**
Expand All @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit<
RESTPostAPIWebhookWithTokenJSONBody,
'username' | 'avatar_url'
> & { flags?: MessageFlags };

export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
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 { APIApplicationCommandAutocompleteInteraction } 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
| APIApplicationCommandAutocompleteInteraction;

/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
Expand Down
4 changes: 4 additions & 0 deletions deno/rest/v8/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
*/
autocomplete?: boolean;
description: string;
}

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
*/
autocomplete?: boolean;
description: string;
}

Expand Down
Loading