From e5d0723a1d2d393686a31934628b9893abfd3ac9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 6 May 2021 19:57:08 +0200 Subject: [PATCH 1/4] change: update std version to 0.95.0 --- deps.ts | 2 +- tests/deps.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps.ts b/deps.ts index 842c7c13b..c6ca70f87 100644 --- a/deps.ts +++ b/deps.ts @@ -1 +1 @@ -export { encode } from "https://deno.land/std@0.90.0/encoding/base64.ts"; +export { encode } from "https://deno.land/std@0.95.0/encoding/base64.ts"; diff --git a/tests/deps.ts b/tests/deps.ts index 8ecc89d22..c5c708cdd 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -3,4 +3,4 @@ export { assertEquals, assertExists, assertThrows, -} from "https://deno.land/std@0.90.0/testing/asserts.ts"; +} from "https://deno.land/std@0.95.0/testing/asserts.ts"; From 3fda6de72876d6127d213f40198c00ad1fa710da Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 7 May 2021 09:48:17 +0200 Subject: [PATCH 2/4] move structures export to structures mod --- mod.ts | 5 ----- src/structures/mod.ts | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/mod.ts b/mod.ts index 152fd637a..131b9e0e1 100644 --- a/mod.ts +++ b/mod.ts @@ -3,12 +3,7 @@ export * from "./src/cache.ts"; export * from "./src/handlers/mod.ts"; export * from "./src/helpers/mod.ts"; export * from "./src/rest/mod.ts"; -export * from "./src/structures/channel.ts"; -export * from "./src/structures/guild.ts"; -export * from "./src/structures/member.ts"; -export * from "./src/structures/message.ts"; export * from "./src/structures/mod.ts"; -export * from "./src/structures/role.ts"; export * from "./src/types/mod.ts"; export * from "./src/util/mod.ts"; export * from "./src/ws/mod.ts"; diff --git a/src/structures/mod.ts b/src/structures/mod.ts index b5e55bbc4..220d793b8 100644 --- a/src/structures/mod.ts +++ b/src/structures/mod.ts @@ -5,6 +5,13 @@ import { createDiscordenoMessage } from "./message.ts"; import { createDiscordenoRole } from "./role.ts"; import { createDiscordenoVoiceState } from "./voice_state.ts"; +import type { DiscordenoChannel } from "./channel.ts"; +import type { DiscordenoGuild } from "./guild.ts"; +import type { DiscordenoMember } from "./member.ts"; +import type { DiscordenoMessage } from "./message.ts"; +import type { DiscordenoRole } from "./role.ts"; +import type { DiscordenoVoiceState } from "./voice_state.ts"; + /** This is the placeholder where the structure creation functions are kept. */ export let structures = { createDiscordenoChannel, @@ -15,7 +22,14 @@ export let structures = { createDiscordenoVoiceState, }; -// export type { Channel, Guild, Member, Message, Role, Template }; +export type { + DiscordenoChannel, + DiscordenoGuild, + DiscordenoMember, + DiscordenoMessage, + DiscordenoRole, + DiscordenoVoiceState, +}; export type Structures = typeof structures; @@ -23,7 +37,7 @@ export type Structures = typeof structures; * * ⚠️ **ADVANCED USE ONLY: If you customize this incorrectly, you could potentially create many new errors/bugs. * Please take caution when using this.** -*/ + */ export function updateStructures(newStructures: Structures) { structures = { ...structures, 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 3/4] 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; } From cad57690c9c523e800c07650cfcd67207f033a2a Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 7 May 2021 14:16:13 +0200 Subject: [PATCH 4/4] run fmt --- src/helpers/interactions/send_interaction_response.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 51a1004e8..9c873cd7d 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -14,7 +14,7 @@ import { validateComponents } from "../../util/utils.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); @@ -25,7 +25,7 @@ export async function sendInteractionResponse( endpoints.WEBHOOK(applicationId, token), { ...options, - } + }, ); } @@ -34,7 +34,7 @@ export async function sendInteractionResponse( setTimeout(() => { eventHandlers.debug?.( "loop", - `Running setTimeout in send_interaction_response file.` + `Running setTimeout in send_interaction_response file.`, ); cache.executedSlashCommands.delete(token); }, 900000); @@ -52,6 +52,6 @@ export async function sendInteractionResponse( return await rest.runMethod( "post", endpoints.INTERACTION_ID_TOKEN(id, token), - options + options, ); }