diff --git a/src/types/interactions/application_command.ts b/src/types/interactions/application_command.ts new file mode 100644 index 000000000..af0b75710 --- /dev/null +++ b/src/types/interactions/application_command.ts @@ -0,0 +1,18 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOption } from "./application_command_option.ts"; + +export interface ApplicationCommand { + /** Unique id of the command */ + id: string; + /** Unique id of the parent application */ + applicationId: string; + /** 1-32 character name matching `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** The parameters for the command */ + options?: ApplicationCommandOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommand */ +export type DiscordApplicationCommand = SnakeCaseProps; diff --git a/src/types/interactions/application_command_callback_data.ts b/src/types/interactions/application_command_callback_data.ts new file mode 100644 index 000000000..c8c20fbc5 --- /dev/null +++ b/src/types/interactions/application_command_callback_data.ts @@ -0,0 +1,21 @@ +import { Embed } from "../embeds/embed.ts"; +import { AllowedMentions } from "../messages/allowed_mentions.ts"; +import { SnakeCaseProps } from "../util.ts"; + +export interface InteractionApplicationCommandCallbackData { + /** Is the response TTS */ + tts?: boolean; + /** Message content */ + content?: string; + /** Supports up to 10 embeds */ + embeds?: Embed[]; + /** Allowed Mentions object */ + allowedMentions?: AllowedMentions; + /** Set to `64` to make your response ephemeral */ + flags?: number; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ +export type DiscordInteractionApplicationCommandCallbackData = SnakeCaseProps< + InteractionApplicationCommandCallbackData +>; diff --git a/src/types/interactions/application_command_interaction_data.ts b/src/types/interactions/application_command_interaction_data.ts new file mode 100644 index 000000000..9ad641b00 --- /dev/null +++ b/src/types/interactions/application_command_interaction_data.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandInteractionDataOption } from "./application_command_interaction_data_option.ts"; + +export interface ApplicationCommandInteractionData { + /** The ID of the invoked command */ + id: string; + /** The name of the invoked command */ + name: string; + /** The params + values from the user */ + options?: ApplicationCommandInteractionDataOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondata */ +export type DiscordApplicationCommandInteractionData = SnakeCaseProps< + ApplicationCommandInteractionData +>; diff --git a/src/types/interactions/application_command_interaction_data_option.ts b/src/types/interactions/application_command_interaction_data_option.ts new file mode 100644 index 000000000..89cb32421 --- /dev/null +++ b/src/types/interactions/application_command_interaction_data_option.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { DiscordApplicationCommandOptionTypes } from "./application_command_option_types.ts"; + +export interface ApplicationCommandInteractionDataOption { + /** The name of the parameter */ + name: string; + /** The value of the pair */ + value?: DiscordApplicationCommandOptionTypes; + /** Present if this option is a group or subcommand */ + options?: ApplicationCommandInteractionDataOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-applicationcommandinteractiondataoption */ +export type DiscordApplicationCommandInteractionDataOption = SnakeCaseProps< + ApplicationCommandInteractionDataOption +>; diff --git a/src/types/interactions/application_command_option.ts b/src/types/interactions/application_command_option.ts new file mode 100644 index 000000000..8547df0c0 --- /dev/null +++ b/src/types/interactions/application_command_option.ts @@ -0,0 +1,23 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOptionChoice } from "./application_command_option_choice.ts"; +import { DiscordApplicationCommandOptionTypes } from "./application_command_option_types.ts"; + +export interface ApplicationCommandOption { + /** Value of Application Command Option Type */ + type: DiscordApplicationCommandOptionTypes; + /** 1-32 character name matching `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** If the parameter is required or optional--default `false` */ + required?: boolean; + /** Choices for `string` and `int` types for the user to pick from */ + choices?: ApplicationCommandOptionChoice[]; + /** If the optino is a subcommand or subcommand group type, this nested options will be the parameters */ + options?: ApplicationCommandOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoption */ +export type DiscordApplicationCommandOption = SnakeCaseProps< + ApplicationCommandOption +>; diff --git a/src/types/interactions/application_command_option_choice.ts b/src/types/interactions/application_command_option_choice.ts new file mode 100644 index 000000000..7bde91922 --- /dev/null +++ b/src/types/interactions/application_command_option_choice.ts @@ -0,0 +1,10 @@ +export interface ApplicationCommandOptionChoice { + /** 1-100 character choice name */ + name: string; + /** Value of the choice, up to 100 characters if string */ + value: string | number; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptionchoice */ +export type DiscordApplicationCommandOptionChoice = + ApplicationCommandOptionChoice; diff --git a/src/types/interactions/application_command_option_types.ts b/src/types/interactions/application_command_option_types.ts new file mode 100644 index 000000000..5416ce41a --- /dev/null +++ b/src/types/interactions/application_command_option_types.ts @@ -0,0 +1,11 @@ +/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype */ +export enum DiscordApplicationCommandOptionTypes { + SUB_COMMAND = 1, + SUB_COMMAND_GROUP, + STRING, + INTEGER, + BOOLEAN, + USER, + CHANNEL, + ROLE, +} diff --git a/src/types/interactions/create_global_application_command.ts b/src/types/interactions/create_global_application_command.ts new file mode 100644 index 000000000..b7392566f --- /dev/null +++ b/src/types/interactions/create_global_application_command.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOption } from "./application_command_option.ts"; + +export interface CreateGlobalApplicationCommand { + /** 1-31 character name matching `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** The parameters for the command */ + options?: ApplicationCommandOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command-json-params */ +export type DiscordCreateGlobalApplicationCommand = SnakeCaseProps< + CreateGlobalApplicationCommand +>; diff --git a/src/types/interactions/create_guild_application_command.ts b/src/types/interactions/create_guild_application_command.ts new file mode 100644 index 000000000..2e4bbbc50 --- /dev/null +++ b/src/types/interactions/create_guild_application_command.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOption } from "./application_command_option.ts"; + +export interface CreateGuildApplicationCommand { + /** 1-31 character name matching `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** The parameters for the command */ + options?: ApplicationCommandOption[]; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#create-guild-application-command-json-params */ +export type DiscordCreateGuildApplicationCommand = SnakeCaseProps< + CreateGuildApplicationCommand +>; diff --git a/src/types/interactions/edit_global_application_command.ts b/src/types/interactions/edit_global_application_command.ts new file mode 100644 index 000000000..e8c239c70 --- /dev/null +++ b/src/types/interactions/edit_global_application_command.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOption } from "./application_command_option.ts"; + +export interface EditGlobalApplicationCommand { + /** 1-31 character name matching `^[\w-]{1,32}$` */ + name?: string; + /** 1-100 character description */ + description?: string; + /** The parameters for the command */ + options?: ApplicationCommandOption[] | null; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command-json-params */ +export type DiscordEditGlobalApplicationCommand = SnakeCaseProps< + EditGlobalApplicationCommand +>; diff --git a/src/types/interactions/edit_guild_application_command.ts b/src/types/interactions/edit_guild_application_command.ts new file mode 100644 index 000000000..79abd7c82 --- /dev/null +++ b/src/types/interactions/edit_guild_application_command.ts @@ -0,0 +1,16 @@ +import { SnakeCaseProps } from "../util.ts"; +import { ApplicationCommandOption } from "./application_command_option.ts"; + +export interface EditGuildApplicationCommand { + /** 1-31 character name matching `^[\w-]{1,32}$` */ + name?: string; + /** 1-100 character description */ + description?: string; + /** The parameters for the command */ + options?: ApplicationCommandOption[] | null; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#edit-guild-application-command-json-params */ +export type DiscordEditGuildApplicationCommand = SnakeCaseProps< + EditGuildApplicationCommand +>; diff --git a/src/types/interactions/interaction.ts b/src/types/interactions/interaction.ts new file mode 100644 index 000000000..927a9bc88 --- /dev/null +++ b/src/types/interactions/interaction.ts @@ -0,0 +1,28 @@ +import { User } from "../users/user.ts"; +import { SnakeCaseProps } from "../util.ts"; +import { InteractionApplicationCommandCallbackData } from "./application_command_callback_data.ts"; +import { DiscordInteractionTypes } from "./interaction_types.ts"; + +export interface Interaction { + /** id of the interaction */ + id: string; + /** The type of interaction */ + type: DiscordInteractionTypes; + /** The command data payload */ + data?: InteractionApplicationCommandCallbackData; + /** The guild it was sent from */ + guildId?: string; + /** The channel it was sent from */ + channelId?: string; + /** Guild member data for the invoking user, including permissions */ + member?: GuildMember; + /** User object for the invoking user, if invoked in a DM */ + user?: User; + /** A continuation token for responding to the interaction */ + token: string; + /** Read-only property, always `1` */ + version: 1; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction */ +export type DiscordInteraction = SnakeCaseProps; diff --git a/src/types/interactions/interaction_response.ts b/src/types/interactions/interaction_response.ts new file mode 100644 index 000000000..fa7acec0a --- /dev/null +++ b/src/types/interactions/interaction_response.ts @@ -0,0 +1,13 @@ +import { SnakeCaseProps } from "../util.ts"; +import { InteractionApplicationCommandCallbackData } from "./application_command_callback_data.ts"; +import { InteractionResponseTypes } from "./interaction_response_types.ts"; + +export interface InteractionResponse { + /** The type of response */ + type: InteractionResponseTypes; + /** An optional response message */ + data?: InteractionApplicationCommandCallbackData; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */ +export type DiscordInteractionResponse = SnakeCaseProps; diff --git a/src/types/interactions/interaction_response_types.ts b/src/types/interactions/interaction_response_types.ts new file mode 100644 index 000000000..b7b825707 --- /dev/null +++ b/src/types/interactions/interaction_response_types.ts @@ -0,0 +1,9 @@ +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype */ +export enum InteractionResponseTypes { + /** ACK a `Ping` */ + Pong = 1, + /** Respond to an interaction with a message */ + ChannelMessageWithSource = 4, + /** ACK an interaction and edit to a response later, the user sees a loading state */ + DeferredChannelMessageWithSource = 5, +} diff --git a/src/types/interactions/interaction_types.ts b/src/types/interactions/interaction_types.ts new file mode 100644 index 000000000..fe9408744 --- /dev/null +++ b/src/types/interactions/interaction_types.ts @@ -0,0 +1,5 @@ +/** https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype */ +export enum DiscordInteractionTypes { + Ping = 1, + ApplicationCommand, +} diff --git a/src/types/interactions/message_interaction.ts b/src/types/interactions/message_interaction.ts new file mode 100644 index 000000000..6abb12fdd --- /dev/null +++ b/src/types/interactions/message_interaction.ts @@ -0,0 +1,17 @@ +import { User } from "../users/user.ts"; +import { SnakeCaseProps } from "../util.ts"; +import { DiscordInteractionTypes } from "./interaction_types.ts"; + +export interface MessageInteraction { + /** Id of the interaction */ + id: string; + /** The type of interaction */ + type: DiscordInteractionTypes; + /** The name of the ApplicationCommand */ + name: string; + /** The user who invoked the interaction */ + user: User; +} + +/** https://discord.com/developers/docs/interactions/slash-commands#messageinteraction */ +export type DiscordMessageInteraction = SnakeCaseProps;