Skip to content

Commit

Permalink
feat(Interactions): add autocomplete api types (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Oct 29, 2021
1 parent fdf133e commit 3b9320d
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 66 deletions.
47 changes: 33 additions & 14 deletions deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts
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 @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionNumber
| ApplicationCommandInteractionDataOptionBoolean;

export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase<
ApplicationCommandOptionType.String,
string
>;
export interface ApplicationCommandInteractionDataOptionString
extends InteractionDataOptionBase<ApplicationCommandOptionType.String, string> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase<
ApplicationCommandOptionType.Role,
Expand All @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData
Snowflake
>;

export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase<
ApplicationCommandOptionType.Integer,
number
>;
export interface ApplicationCommandInteractionDataOptionInteger
extends InteractionDataOptionBase<ApplicationCommandOptionType.Integer, number> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase<
ApplicationCommandOptionType.Number,
number
>;
export interface ApplicationCommandInteractionDataOptionNumber
extends InteractionDataOptionBase<ApplicationCommandOptionType.Number, number> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase<
ApplicationCommandOptionType.Boolean,
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
| APIApplicationCommandAutocompleteResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APIApplicationCommandAutocompleteResponse {
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
49 changes: 34 additions & 15 deletions deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts
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 @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues =
| ApplicationCommandInteractionDataOptionNumber
| ApplicationCommandInteractionDataOptionBoolean;

export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase<
ApplicationCommandOptionType.String,
string
>;
export interface ApplicationCommandInteractionDataOptionString
extends InteractionDataOptionBase<ApplicationCommandOptionType.String, string> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase<
ApplicationCommandOptionType.Role,
Expand All @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData
Snowflake
>;

export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase<
ApplicationCommandOptionType.Integer,
number
>;
export interface ApplicationCommandInteractionDataOptionInteger
extends InteractionDataOptionBase<ApplicationCommandOptionType.Integer, number> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase<
ApplicationCommandOptionType.Number,
number
>;
export interface ApplicationCommandInteractionDataOptionNumber
extends InteractionDataOptionBase<ApplicationCommandOptionType.Number, number> {
focused?: boolean;
}

export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase<
ApplicationCommandOptionType.Boolean,
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
| APIApplicationCommandAutocompleteResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
}

export interface APIApplicationCommandAutocompleteResponse {
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

0 comments on commit 3b9320d

Please sign in to comment.