types: add interactions types (#709)

* types: add Interaction ApplicationCommand type

* types: add Interaction ApplicationCommandInteractionData type

* types: add Interaction ApplicationCommandInteractionData type

* types: add Interaction ApplicationCommandInteractionDataOption

* types: add Interaction ApplicationCommandOption

* types: add Interaction ApplicatoinCommandOptionChoice

* types: add Interaction ApplicationCommandOptionTypes

* types: add Interaction CreateGlobalApplicationCommand

* types: add Interaction CreateGuildApplicationCommand

* types: add Interaction EditGlobalApplicationCommand

* types: add Interaction EditGuildApplicationCommand

* types: add Interaction

* types: add Interaction InteractionResponse

* types: add Interaction InteractionResponseTypes

* types: add Interaction InteractionTypes

* types: add Interaction MessageInteraction

* change names

* my bad

* Update src/types/interactions/application_command_callback_data.ts

* Update src/types/interactions/interaction.ts

* InteractionTypes => DiscordInteractionTypes

* s

* delete this test file

Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
ITOH
2021-03-29 19:09:25 +02:00
committed by GitHub
parent b0c3398689
commit a0ff1a3a71
16 changed files with 251 additions and 0 deletions

View File

@@ -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<ApplicationCommand>;

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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;

View File

@@ -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,
}

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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
>;

View File

@@ -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<Interaction>;

View File

@@ -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<InteractionResponse>;

View File

@@ -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,
}

View File

@@ -0,0 +1,5 @@
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-interactiontype */
export enum DiscordInteractionTypes {
Ping = 1,
ApplicationCommand,
}

View File

@@ -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<MessageInteraction>;