From 579bf369bad4fe3d92aefe5809cf7818bfc37f4f Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 9 Dec 2021 17:04:55 +0100 Subject: [PATCH 1/3] for yui --- benchmarks | 2 +- .../commands/editInteractionResponse.ts | 19 +++++++++-------- .../interactions/sendInteractionResponse.ts | 19 +++++++++-------- src/helpers/messages/editMessage.ts | 19 +++++++++-------- src/helpers/messages/sendMessage.ts | 19 +++++++++-------- src/helpers/webhooks/editWebhookMessage.ts | 21 +++++++++++-------- src/transformers/component.ts | 2 +- 7 files changed, 54 insertions(+), 47 deletions(-) diff --git a/benchmarks b/benchmarks index 27a2c5ca0..7944b87a6 160000 --- a/benchmarks +++ b/benchmarks @@ -1 +1 @@ -Subproject commit 27a2c5ca041e3eee2e0fb1c27100091813d9c681 +Subproject commit 7944b87a6a37ed610c00033c075a4f0361bf629c diff --git a/src/helpers/interactions/commands/editInteractionResponse.ts b/src/helpers/interactions/commands/editInteractionResponse.ts index b92a63d8e..b4c32c347 100644 --- a/src/helpers/interactions/commands/editInteractionResponse.ts +++ b/src/helpers/interactions/commands/editInteractionResponse.ts @@ -66,15 +66,16 @@ export async function editInteractionResponse(bot: Bot, token: string, options: 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, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, }; }), })), diff --git a/src/helpers/interactions/sendInteractionResponse.ts b/src/helpers/interactions/sendInteractionResponse.ts index 4ea482fa9..c81848bec 100644 --- a/src/helpers/interactions/sendInteractionResponse.ts +++ b/src/helpers/interactions/sendInteractionResponse.ts @@ -129,15 +129,16 @@ export async function sendInteractionResponse( 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, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, }; }), })), diff --git a/src/helpers/messages/editMessage.ts b/src/helpers/messages/editMessage.ts index 5705865a1..05feb4360 100644 --- a/src/helpers/messages/editMessage.ts +++ b/src/helpers/messages/editMessage.ts @@ -127,15 +127,16 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint 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, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, }; }), })), diff --git a/src/helpers/messages/sendMessage.ts b/src/helpers/messages/sendMessage.ts index f8a684b88..fbc498223 100644 --- a/src/helpers/messages/sendMessage.ts +++ b/src/helpers/messages/sendMessage.ts @@ -142,15 +142,16 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | 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, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, }; }), })), diff --git a/src/helpers/webhooks/editWebhookMessage.ts b/src/helpers/webhooks/editWebhookMessage.ts index 97a61b32d..4cc4ddb48 100644 --- a/src/helpers/webhooks/editWebhookMessage.ts +++ b/src/helpers/webhooks/editWebhookMessage.ts @@ -3,6 +3,8 @@ import type { EditWebhookMessage } from "../../types/webhooks/editWebhookMessage import type { Bot } from "../../bot.ts"; import { AllowedMentionsTypes } from "../../types/messages/allowedMentionsTypes.ts"; import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; +import { hasProperty } from "../../util/utils.ts"; +import { ButtonComponent } from "../../types/messages/components/buttonComponent.ts"; export async function editWebhookMessage( bot: Bot, @@ -101,15 +103,16 @@ export async function editWebhookMessage( 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, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, }; }), })), diff --git a/src/transformers/component.ts b/src/transformers/component.ts index 9839d9670..7f0ca4b2a 100644 --- a/src/transformers/component.ts +++ b/src/transformers/component.ts @@ -81,7 +81,7 @@ export interface DiscordenoComponent { customId?: string; /** whether the component is disabled, default false */ disabled?: boolean; - /** For different styles/colors of the buttons */ + /** For different styles/colors of the buttons or TextInput */ style?: ButtonStyles | TextStyles; /** text that appears on the button (max 80 characters) */ label?: string; From e1b262b2c45ee96c7761104661c1544f191f9681 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Fri, 10 Dec 2021 09:43:44 +0700 Subject: [PATCH 2/3] Update README Minimal Example --- README.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 10c3f2024..96035b4b1 100644 --- a/README.md +++ b/README.md @@ -79,21 +79,23 @@ Here is a minimal example to get started with: import { createBot, startBot } from "https://deno.land/x/discordeno/mod.ts"; import { enableCachePlugin, enableCacheSweepers } from "https://deno.land/x/discordeno_cache_plugin@0.0.9/mod.ts"; -const bot = createBot({ - token: Deno.env.get("DISCORD_TOKEN"), - intents: ["Guilds", "GuildMessages"], - botId: Deno.env.get("BOT_ID"), - events: { - ready() { - console.log("Successfully connected to gateway"); +const bot = enableCachePlugin( + createBot({ + token: Deno.env.get("DISCORD_TOKEN"), + intents: ["Guilds", "GuildMessages"], + botId: Deno.env.get("BOT_ID"), + events: { + ready() { + console.log("Successfully connected to gateway"); + }, + messageCreate(bot, message) { + // Process the message with your command handler here + }, }, - messageCreate(bot, message) { - // Process the message with your command handler here - }, - }, -}); + }) +); -enableCachePlugin(enableCacheSweepers(bot)); +enableCacheSweepers(bot); await startBot(bot); ``` From d2f351f00c3b017f1631f53a1c28d73dcf1bc1b6 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Fri, 10 Dec 2021 10:59:40 +0700 Subject: [PATCH 3/3] Update README minimal example (based on discordeno cache plugin README) --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 96035b4b1..8addba28f 100644 --- a/README.md +++ b/README.md @@ -79,21 +79,21 @@ Here is a minimal example to get started with: import { createBot, startBot } from "https://deno.land/x/discordeno/mod.ts"; import { enableCachePlugin, enableCacheSweepers } from "https://deno.land/x/discordeno_cache_plugin@0.0.9/mod.ts"; -const bot = enableCachePlugin( - createBot({ - token: Deno.env.get("DISCORD_TOKEN"), - intents: ["Guilds", "GuildMessages"], - botId: Deno.env.get("BOT_ID"), - events: { - ready() { - console.log("Successfully connected to gateway"); - }, - messageCreate(bot, message) { - // Process the message with your command handler here - }, +const baseBot = createBot({ + token: Deno.env.get("DISCORD_TOKEN"), + intents: ["Guilds", "GuildMessages"], + botId: Deno.env.get("BOT_ID"), + events: { + ready() { + console.log("Successfully connected to gateway"); }, - }) -); + messageCreate(bot, message) { + // Process the message with your command handler here + }, + }, +}); + +const bot = enableCachePlugin(baseBot); enableCacheSweepers(bot);