From b4d2398e6c865531b48ae41c1544ffb404e70fb4 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 7 May 2021 14:14:02 +0200 Subject: [PATCH] add component support --- .../interactions/send_interaction_response.ts | 26 +++++++++---------- .../application_command_callback_data.ts | 3 +++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index dae5c23bd..51a1004e8 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -3,6 +3,7 @@ import { cache } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts"; import { endpoints } from "../../util/constants.ts"; +import { validateComponents } from "../../util/utils.ts"; /** * Send a response to a users slash command. The command data will have the id and token necessary to respond. @@ -13,8 +14,10 @@ import { endpoints } from "../../util/constants.ts"; export async function sendInteractionResponse( id: bigint, token: string, - options: DiscordenoInteractionResponse, + options: DiscordenoInteractionResponse ) { + // TODO: add more options validations + if (options.data?.components) validateComponents(options.data?.components); // If its already been executed, we need to send a followup response if (cache.executedSlashCommands.has(token)) { return await rest.runMethod( @@ -22,22 +25,19 @@ export async function sendInteractionResponse( endpoints.WEBHOOK(applicationId, token), { ...options, - }, + } ); } // Expire in 15 minutes cache.executedSlashCommands.add(token); - setTimeout( - () => { - eventHandlers.debug?.( - "loop", - `Running setTimeout in send_interaction_response file.`, - ); - cache.executedSlashCommands.delete(token); - }, - 900000, - ); + setTimeout(() => { + eventHandlers.debug?.( + "loop", + `Running setTimeout in send_interaction_response file.` + ); + cache.executedSlashCommands.delete(token); + }, 900000); // If the user wants this as a private message mark it ephemeral if (options.private) { @@ -52,6 +52,6 @@ export async function sendInteractionResponse( return await rest.runMethod( "post", endpoints.INTERACTION_ID_TOKEN(id, token), - options, + options ); } diff --git a/src/types/interactions/commands/application_command_callback_data.ts b/src/types/interactions/commands/application_command_callback_data.ts index 6857815af..b14415e5c 100644 --- a/src/types/interactions/commands/application_command_callback_data.ts +++ b/src/types/interactions/commands/application_command_callback_data.ts @@ -1,5 +1,6 @@ import { Embed } from "../../embeds/embed.ts"; import { AllowedMentions } from "../../messages/allowed_mentions.ts"; +import { MessageComponents } from "../../messages/components/message_components.ts"; /** https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionapplicationcommandcallbackdata */ export interface InteractionApplicationCommandCallbackData { @@ -13,4 +14,6 @@ export interface InteractionApplicationCommandCallbackData { allowedMentions?: AllowedMentions; /** Set to `64` to make your response ephemeral */ flags?: number; + /** The components you would like to have sent in this message */ + components?: MessageComponents; }