From 9f31a175763d35b97ba59a4b6dd28f8fe6bcdff6 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:35:48 +0100 Subject: [PATCH 01/14] executedSlashCommands -> unrepliedSlashCommands --- src/cache.ts | 57 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 3cdd49215..908bc3bf0 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -68,12 +68,14 @@ export function createCache( tableCreator?: (bot: Bot, tableName: TableNames) => CacheHandler | AsyncCacheHandler; } ): Omit | Omit { + let cache: Cache | AsyncCache; + if (options.isAsync) { if (!options.tableCreator) { throw new Error("Async cache requires a tableCreator to be passed."); } - const cache = { + cache = { guilds: options.tableCreator(bot, "guilds"), users: options.tableCreator(bot, "users"), members: options.tableCreator(bot, "members"), @@ -85,34 +87,43 @@ export function createCache( dispatchedGuildIds: options.tableCreator(bot, "dispatchedGuildIds"), dispatchedChannelIds: options.tableCreator(bot, "dispatchedChannelIds"), activeGuildIds: options.tableCreator(bot, "activeGuildIds"), - executedSlashCommands: new Set(), + unrepliedSlashCommands: new Set(), fetchAllMembersProcessingRequests: new Map(), execute: async function () { throw new Error("Async Cache requires a custom execute function to be implemented."); }, } as AsyncCache; + } else { + if (!options.tableCreator) options.tableCreator = createTable; - return cache; + cache = { + guilds: options.tableCreator(bot, "guilds"), + users: options.tableCreator(bot, "users"), + members: options.tableCreator(bot, "members"), + channels: options.tableCreator(bot, "channels"), + messages: options.tableCreator(bot, "messages"), + presences: options.tableCreator(bot, "presences"), + // threads: options.tableCreator(bot, "threads"), + unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), + dispatchedGuildIds: new Set(), + dispatchedChannelIds: new Set(), + activeGuildIds: new Set(), + unrepliedSlashCommands: new Set(), + fetchAllMembersProcessingRequests: new Map(), + } as Cache; + + cache.execute = createExecute(cache); } - if (!options.tableCreator) options.tableCreator = createTable; - const cache = { - guilds: options.tableCreator(bot, "guilds"), - users: options.tableCreator(bot, "users"), - members: options.tableCreator(bot, "members"), - channels: options.tableCreator(bot, "channels"), - messages: options.tableCreator(bot, "messages"), - presences: options.tableCreator(bot, "presences"), - // threads: options.tableCreator(bot, "threads"), - unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), - dispatchedGuildIds: new Set(), - dispatchedChannelIds: new Set(), - activeGuildIds: new Set(), - executedSlashCommands: new Set(), - fetchAllMembersProcessingRequests: new Map(), - } as Cache; - - cache.execute = createExecute(cache); + setInterval(() => { + let values = cache.unrepliedSlashCommands.values(); + let now = Date.now(); + for (let val; (val = values.next().value); ) { + if ((val >> 22n) + 1420071300000n < now) { + cache.unrepliedSlashCommands.delete(val); + } + } + }, 300000); return cache; } @@ -131,7 +142,7 @@ export interface Cache { dispatchedGuildIds: Set; dispatchedChannelIds: Set; activeGuildIds: Set; - executedSlashCommands: Set; + unrepliedSlashCommands: Set; fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } @@ -154,7 +165,7 @@ export interface AsyncCache { dispatchedGuildIds: AsyncCacheHandler; dispatchedChannelIds: AsyncCacheHandler; activeGuildIds: AsyncCacheHandler; - executedSlashCommands: Set; + unrepliedSlashCommands: Set; fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } From d03d54a23126e8bcd68f80e817904f55eda939ed Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:36:44 +0100 Subject: [PATCH 02/14] better name for it --- src/cache.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 908bc3bf0..19cba9e68 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -87,7 +87,7 @@ export function createCache( dispatchedGuildIds: options.tableCreator(bot, "dispatchedGuildIds"), dispatchedChannelIds: options.tableCreator(bot, "dispatchedChannelIds"), activeGuildIds: options.tableCreator(bot, "activeGuildIds"), - unrepliedSlashCommands: new Set(), + unrepliedInteractions: new Set(), fetchAllMembersProcessingRequests: new Map(), execute: async function () { throw new Error("Async Cache requires a custom execute function to be implemented."); @@ -108,7 +108,7 @@ export function createCache( dispatchedGuildIds: new Set(), dispatchedChannelIds: new Set(), activeGuildIds: new Set(), - unrepliedSlashCommands: new Set(), + unrepliedInteractions: new Set(), fetchAllMembersProcessingRequests: new Map(), } as Cache; @@ -116,11 +116,11 @@ export function createCache( } setInterval(() => { - let values = cache.unrepliedSlashCommands.values(); + let values = cache.unrepliedInteractions.values(); let now = Date.now(); for (let val; (val = values.next().value); ) { if ((val >> 22n) + 1420071300000n < now) { - cache.unrepliedSlashCommands.delete(val); + cache.unrepliedInteractions.delete(val); } } }, 300000); @@ -142,7 +142,7 @@ export interface Cache { dispatchedGuildIds: Set; dispatchedChannelIds: Set; activeGuildIds: Set; - unrepliedSlashCommands: Set; + unrepliedInteractions: Set; fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } @@ -165,7 +165,7 @@ export interface AsyncCache { dispatchedGuildIds: AsyncCacheHandler; dispatchedChannelIds: AsyncCacheHandler; activeGuildIds: AsyncCacheHandler; - unrepliedSlashCommands: Set; + unrepliedInteractions: Set; fetchAllMembersProcessingRequests: Map; execute: CacheExecutor; } From ec80d8caf1370498553a252d32c0c6a7cde8e46c Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:37:19 +0100 Subject: [PATCH 03/14] add new interactions to unrepliedInteractions --- src/handlers/interactions/INTERACTION_CREATE.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/handlers/interactions/INTERACTION_CREATE.ts b/src/handlers/interactions/INTERACTION_CREATE.ts index 56aac522b..d2ba621dd 100644 --- a/src/handlers/interactions/INTERACTION_CREATE.ts +++ b/src/handlers/interactions/INTERACTION_CREATE.ts @@ -4,5 +4,6 @@ import type { Interaction } from "../../types/interactions/interaction.ts"; import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) { + bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as SnakeCasedPropertiesDeep).id)); bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as SnakeCasedPropertiesDeep)); } From 1a7f8c45df706239f427491cd354d26f42c0c5f4 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:37:27 +0100 Subject: [PATCH 04/14] better handling --- .../interactions/send_interaction_response.ts | 339 ++++++------------ 1 file changed, 119 insertions(+), 220 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index babc0529a..6faa9f1ca 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -37,230 +37,129 @@ export async function sendInteractionResponse( } : { parse: [] }; - // If its already been executed, we need to send a followup response - if (bot.cache.executedSlashCommands.has(token)) { - // FOLLOWUP RESPONSES ARE DIFFERENT STYLED RESPONSE - return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.WEBHOOK(bot.applicationId, token), { - content: options.data.content, - tts: options.data.tts, - embeds: options.data.embeds?.map((embed) => ({ - title: embed.title, - type: embed.type, - description: embed.description, - url: embed.url, - timestamp: embed.timestamp, - color: embed.color, - footer: embed.footer - ? { - text: embed.footer.text, - icon_url: embed.footer.iconUrl, - proxy_icon_url: embed.footer.proxyIconUrl, - } - : undefined, - image: embed.image - ? { - url: embed.image.url, - proxy_url: embed.image.proxyUrl, - height: embed.image.height, - width: embed.image.width, - } - : undefined, - thumbnail: embed.thumbnail - ? { - url: embed.thumbnail.url, - proxy_url: embed.thumbnail.proxyUrl, - height: embed.thumbnail.height, - width: embed.thumbnail.width, - } - : undefined, - video: embed.video - ? { - url: embed.video.url, - proxy_url: embed.video.proxyUrl, - height: embed.video.height, - width: embed.video.width, - } - : undefined, - provider: embed.provider, - author: embed.author - ? { - name: embed.author.name, - url: embed.author.url, - icon_url: embed.author.iconUrl, - proxy_icon_url: embed.author.proxyIconUrl, - } - : undefined, - fields: embed.fields, - })), - allowed_mentions: { - parse: allowedMentions.parse, - roles: allowedMentions.roles, - users: allowedMentions.users, - replied_user: allowedMentions.repliedUser, - }, - file: options.data.file, - components: options.data.components?.map((component) => ({ - type: component.type, - components: component.components.map((subcomponent) => { - if (subcomponent.type === DiscordMessageComponentTypes.SelectMenu) - return { - type: subcomponent.type, - custom_id: subcomponent.customId, - placeholder: subcomponent.placeholder, - min_values: subcomponent.minValues, - max_values: subcomponent.maxValues, - options: subcomponent.options.map((option) => ({ - label: option.label, - value: option.value, - description: option.description, - emoji: option.emoji - ? { - id: option.emoji.id?.toString(), - name: option.emoji.name, - animated: option.emoji.animated, - } - : undefined, - default: option.default, - })), - }; - + let data = { + content: options.data.content, + tts: options.data.tts, + embeds: options.data.embeds?.map((embed) => ({ + title: embed.title, + type: embed.type, + description: embed.description, + url: embed.url, + timestamp: embed.timestamp, + color: embed.color, + footer: embed.footer + ? { + text: embed.footer.text, + icon_url: embed.footer.iconUrl, + proxy_icon_url: embed.footer.proxyIconUrl, + } + : undefined, + image: embed.image + ? { + url: embed.image.url, + proxy_url: embed.image.proxyUrl, + height: embed.image.height, + width: embed.image.width, + } + : undefined, + thumbnail: embed.thumbnail + ? { + url: embed.thumbnail.url, + proxy_url: embed.thumbnail.proxyUrl, + height: embed.thumbnail.height, + width: embed.thumbnail.width, + } + : undefined, + video: embed.video + ? { + url: embed.video.url, + proxy_url: embed.video.proxyUrl, + height: embed.video.height, + width: embed.video.width, + } + : undefined, + provider: embed.provider, + author: embed.author + ? { + name: embed.author.name, + url: embed.author.url, + icon_url: embed.author.iconUrl, + proxy_icon_url: embed.author.proxyIconUrl, + } + : undefined, + fields: embed.fields, + })), + allowed_mentions: { + parse: allowedMentions.parse, + roles: allowedMentions.roles, + users: allowedMentions.users, + replied_user: allowedMentions.repliedUser, + }, + file: options.data.file, + components: options.data.components?.map((component) => ({ + type: component.type, + components: component.components.map((subcomponent) => { + if (subcomponent.type === DiscordMessageComponentTypes.SelectMenu) return { type: subcomponent.type, custom_id: subcomponent.customId, - label: subcomponent.label, - style: subcomponent.style, - emoji: subcomponent.emoji - ? { - id: subcomponent.emoji.id?.toString(), - name: subcomponent.emoji.name, - animated: subcomponent.emoji.animated, - } - : undefined, - url: subcomponent.url, - disabled: subcomponent.disabled, - }; - }), - })), - flags: options.data.flags, - }); - } - - // Expire in 15 minutes - bot.cache.executedSlashCommands.add(token); - setTimeout(() => { - bot.events.debug(`Running setTimeout in send_interaction_response file.`); - bot.cache.executedSlashCommands.delete(token); - }, 900000); - - return await bot.rest.runMethod( - bot.rest, - "post", - bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token), - { - type: options.type, - data: { - content: options.data.content, - tts: options.data.tts, - embeds: options.data.embeds?.map((embed) => ({ - title: embed.title, - type: embed.type, - description: embed.description, - url: embed.url, - timestamp: embed.timestamp, - color: embed.color, - footer: embed.footer - ? { - text: embed.footer.text, - icon_url: embed.footer.iconUrl, - proxy_icon_url: embed.footer.proxyIconUrl, - } - : undefined, - image: embed.image - ? { - url: embed.image.url, - proxy_url: embed.image.proxyUrl, - height: embed.image.height, - width: embed.image.width, - } - : undefined, - thumbnail: embed.thumbnail - ? { - url: embed.thumbnail.url, - proxy_url: embed.thumbnail.proxyUrl, - height: embed.thumbnail.height, - width: embed.thumbnail.width, - } - : undefined, - video: embed.video - ? { - url: embed.video.url, - proxy_url: embed.video.proxyUrl, - height: embed.video.height, - width: embed.video.width, - } - : undefined, - provider: embed.provider, - author: embed.author - ? { - name: embed.author.name, - url: embed.author.url, - icon_url: embed.author.iconUrl, - proxy_icon_url: embed.author.proxyIconUrl, - } - : undefined, - fields: embed.fields, - })), - allowed_mentions: { - parse: allowedMentions.parse, - roles: allowedMentions.roles, - users: allowedMentions.users, - replied_user: allowedMentions.repliedUser, - }, - file: options.data.file, - components: options.data.components?.map((component) => ({ - type: component.type, - components: component.components.map((subcomponent) => { - if (subcomponent.type === DiscordMessageComponentTypes.SelectMenu) - return { - type: subcomponent.type, - custom_id: subcomponent.customId, - placeholder: subcomponent.placeholder, - min_values: subcomponent.minValues, - max_values: subcomponent.maxValues, - options: subcomponent.options.map((option) => ({ - label: option.label, - value: option.value, - description: option.description, - emoji: option.emoji - ? { - id: option.emoji.id?.toString(), - name: option.emoji.name, - animated: option.emoji.animated, - } - : undefined, - default: option.default, - })), - }; - - return { - type: subcomponent.type, - custom_id: subcomponent.customId, - label: subcomponent.label, - style: subcomponent.style, - emoji: subcomponent.emoji + placeholder: subcomponent.placeholder, + min_values: subcomponent.minValues, + max_values: subcomponent.maxValues, + options: subcomponent.options.map((option) => ({ + label: option.label, + value: option.value, + description: option.description, + emoji: option.emoji ? { - id: subcomponent.emoji.id?.toString(), - name: subcomponent.emoji.name, - animated: subcomponent.emoji.animated, + id: option.emoji.id?.toString(), + name: option.emoji.name, + animated: option.emoji.animated, } : undefined, - url: subcomponent.url, - disabled: subcomponent.disabled, - }; - }), - })), - flags: options.data.flags, - }, - } - ); + default: option.default, + })), + }; + + return { + type: subcomponent.type, + custom_id: subcomponent.customId, + label: subcomponent.label, + style: subcomponent.style, + emoji: subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: subcomponent.url, + disabled: subcomponent.disabled, + }; + }), + })), + flags: options.data.flags, + }; + + // A reply has never been send + if (bot.cache.unrepliedInteractions.has(id)) { + bot.cache.unrepliedInteractions.delete(id); + + return await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token), + { + type: options.type, + data, + } + ); + } + + // If its already been executed, we need to send a followup response + return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.WEBHOOK(bot.applicationId, token), { + type: options.type, + data, + }); + // } } From 13447eceaafae285fbde17c6a33cab8782ee2c7f Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:38:02 +0100 Subject: [PATCH 05/14] js has const.... --- src/helpers/interactions/send_interaction_response.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 6faa9f1ca..b36eb65dd 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -37,7 +37,7 @@ export async function sendInteractionResponse( } : { parse: [] }; - let data = { + const data = { content: options.data.content, tts: options.data.tts, embeds: options.data.embeds?.map((embed) => ({ From b0a999c162e20ecd83f80f27ea746a9d673da1cc Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:38:19 +0100 Subject: [PATCH 06/14] JS HAS CONST --- src/cache.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 19cba9e68..c93c9d99d 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -116,8 +116,8 @@ export function createCache( } setInterval(() => { - let values = cache.unrepliedInteractions.values(); - let now = Date.now(); + const values = cache.unrepliedInteractions.values(); + const now = Date.now(); for (let val; (val = values.next().value); ) { if ((val >> 22n) + 1420071300000n < now) { cache.unrepliedInteractions.delete(val); From 7290b46658566834289ad34c8e561d023e7ca4cd Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:46:44 +0100 Subject: [PATCH 07/14] better stuff --- .../interactions/send_interaction_response.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index b36eb65dd..78fa56821 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -28,15 +28,7 @@ export async function sendInteractionResponse( options.data = { ...options.data, allowedMentions: { parse: [] } }; } - const allowedMentions: AllowedMentions = options.data?.allowedMentions - ? { - parse: options.data?.allowedMentions.parse, - repliedUser: options.data?.allowedMentions.repliedUser, - users: options.data?.allowedMentions.users?.map((id) => id.toString()), - roles: options.data?.allowedMentions.roles?.map((id) => id.toString()), - } - : { parse: [] }; - + // DRY code const data = { content: options.data.content, tts: options.data.tts, @@ -90,10 +82,10 @@ export async function sendInteractionResponse( fields: embed.fields, })), allowed_mentions: { - parse: allowedMentions.parse, - roles: allowedMentions.roles, - users: allowedMentions.users, - replied_user: allowedMentions.repliedUser, + parse: options.data.allowedMentions!.parse, + replied_user: options.data.allowedMentions!.repliedUser, + users: options.data.allowedMentions!.users?.map((id) => id.toString()), + roles: options.data.allowedMentions!.roles?.map((id) => id.toString()), }, file: options.data.file, components: options.data.components?.map((component) => ({ From af4be9693d2ea84c4ee1ecdd9ac2cd8033392a57 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:47:16 +0100 Subject: [PATCH 08/14] explain --- src/cache.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index c93c9d99d..f9ea2b343 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -115,10 +115,17 @@ export function createCache( cache.execute = createExecute(cache); } + // Interaction sweeper in case users don't reply do slash commands + // PS: always reply .-. its good practise setInterval(() => { const values = cache.unrepliedInteractions.values(); const now = Date.now(); for (let val; (val = values.next().value); ) { + // Interaction is older than 15 minutes + // and a reply has never been send + // so remove it from cache + // PS: DON'T USE THIS CODE TO CONVERT DC SNOWFLAKES TO UNIX + // SINCE U WILL GET AN INVALID RESULT if ((val >> 22n) + 1420071300000n < now) { cache.unrepliedInteractions.delete(val); } From d0af4800b9ee674e50b1f3d93a486ae3abd82f95 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:49:21 +0100 Subject: [PATCH 09/14] Update send_interaction_response.ts --- src/helpers/interactions/send_interaction_response.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 78fa56821..fd8208f1e 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -28,7 +28,7 @@ export async function sendInteractionResponse( options.data = { ...options.data, allowedMentions: { parse: [] } }; } - // DRY code + // DRY code a little bit const data = { content: options.data.content, tts: options.data.tts, From 91fdfa986dba9dc97042631c683b49340ab31962 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 17:51:24 +0100 Subject: [PATCH 10/14] Update send_interaction_response.ts --- src/helpers/interactions/send_interaction_response.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index fd8208f1e..5d8fc24d2 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -16,7 +16,7 @@ export async function sendInteractionResponse( options: DiscordenoInteractionResponse ) { // TODO: add more options validations - if (options.data?.components) bot.utils.validateComponents(bot, options.data?.components); + if (options.data?.components) bot.utils.validateComponents(bot, options.data.components); // If the user wants this as a private message mark it ephemeral if (options.private) { From ab6f3dd9d14c8a2fb8f1b3993a3d190e619f446d Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 18:07:49 +0100 Subject: [PATCH 11/14] fix follow ups --- src/helpers/interactions/send_interaction_response.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 5d8fc24d2..6e832e06d 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -149,9 +149,5 @@ export async function sendInteractionResponse( } // If its already been executed, we need to send a followup response - return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.WEBHOOK(bot.applicationId, token), { - type: options.type, - data, - }); - // } + return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.WEBHOOK(bot.applicationId, token), data); } From 986a88fbd9c507860b7add99aa7ca39fbf305fd0 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sun, 14 Nov 2021 18:07:56 +0100 Subject: [PATCH 12/14] no need to convert anymore --- .../interactions/send_interaction_response.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 6e832e06d..8acd2d690 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -137,15 +137,10 @@ export async function sendInteractionResponse( if (bot.cache.unrepliedInteractions.has(id)) { bot.cache.unrepliedInteractions.delete(id); - return await bot.rest.runMethod( - bot.rest, - "post", - bot.constants.endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : bot.transformers.snowflake(id), token), - { - type: options.type, - data, - } - ); + return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.INTERACTION_ID_TOKEN(id, token), { + type: options.type, + data, + }); } // If its already been executed, we need to send a followup response From e4569d39a878d6b370a9df17d8840269b4e945f2 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 14 Nov 2021 17:31:22 +0000 Subject: [PATCH 13/14] fix: more broken imports --- src/util/utils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/utils.ts b/src/util/utils.ts index d297650ba..9546897e1 100644 --- a/src/util/utils.ts +++ b/src/util/utils.ts @@ -1,4 +1,3 @@ -import { isButton } from "../helpers/type_guards/is_button.ts"; import { Errors } from "../types/discordeno/errors.ts"; import type { ApplicationCommandOption } from "../types/interactions/commands/application_command_option.ts"; import type { ApplicationCommandOptionChoice } from "../types/interactions/commands/application_command_option_choice.ts"; @@ -10,9 +9,10 @@ import type { MessageComponents } from "../types/messages/components/message_com import type { DiscordImageFormat } from "../types/misc/image_format.ts"; import type { DiscordImageSize } from "../types/misc/image_size.ts"; import { CONTEXT_MENU_COMMANDS_NAME_REGEX, SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; -import { isSelectMenu } from "../helpers/type_guards/is_select_menu.ts"; import { ApplicationCommandTypes } from "../types/interactions/commands/application_command_types.ts"; import { Bot } from "../bot.ts"; +import { InteractionTypes } from "../types/interactions/interaction_types.ts"; +import { MessageComponentTypes } from "../types/messages/components/message_component_types.ts"; /** Pause the execution for a given amount of milliseconds. */ export function delay(ms: number): Promise { @@ -165,7 +165,7 @@ export function validateComponents(bot: Bot, components: MessageComponents) { throw new Error(Errors.TOO_MANY_COMPONENTS); } else if ( component.components?.length > 1 && - component.components.some((subcomponent) => isSelectMenu(subcomponent)) + component.components.some((subcomponent) => subcomponent.type === MessageComponentTypes.SelectMenu) ) { throw new Error(Errors.COMPONENT_SELECT_MUST_BE_ALONE); } @@ -176,7 +176,7 @@ export function validateComponents(bot: Bot, components: MessageComponents) { } // 5 Link buttons can not have a customId - if (isButton(subcomponent)) { + if (subcomponent.type === MessageComponentTypes.Button) { if (subcomponent.style === ButtonStyles.Link && subcomponent.customId) { throw new Error(Errors.LINK_BUTTON_CANNOT_HAVE_CUSTOM_ID); } @@ -192,7 +192,7 @@ export function validateComponents(bot: Bot, components: MessageComponents) { subcomponent.emoji = makeEmojiFromString(subcomponent.emoji); } - if (isSelectMenu(subcomponent)) { + if (subcomponent.type === MessageComponentTypes.SelectMenu) { if (subcomponent.placeholder && !bot.utils.validateLength(subcomponent.placeholder, { max: 100 })) { throw new Error(Errors.COMPONENT_PLACEHOLDER_TOO_BIG); } From 03718161d57eee8b3b1521aab82a9327389ceac9 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sun, 14 Nov 2021 18:45:35 +0000 Subject: [PATCH 14/14] fix: data.resolved type. rc5 --- src/transformers/interaction.ts | 2 +- src/util/constants.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transformers/interaction.ts b/src/transformers/interaction.ts index 1d3ad9465..39753c450 100644 --- a/src/transformers/interaction.ts +++ b/src/transformers/interaction.ts @@ -122,7 +122,7 @@ export function transformInteractionDataResolved( ); } - return resolved; + return transformed; } export interface DiscordenoInteraction { diff --git a/src/util/constants.ts b/src/util/constants.ts index 0c816f059..0efd73de7 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -9,7 +9,7 @@ export const GATEWAY_VERSION = 9; // TODO: update this version /** https://github.com/discordeno/discordeno/releases */ -export const DISCORDENO_VERSION = "13.0.0-rc4"; +export const DISCORDENO_VERSION = "13.0.0-rc5"; /** https://discord.com/developers/docs/reference#user-agent */ export const USER_AGENT = `DiscordBot (https://github.com/discordeno/discordeno, v${DISCORDENO_VERSION})`;