From 403f93ec27708a98936340f06271b44320eec6b0 Mon Sep 17 00:00:00 2001 From: lts372005 <87189679+lts372005@users.noreply.github.com> Date: Sat, 30 Oct 2021 10:49:49 +0700 Subject: [PATCH 01/13] [Unit Test] utils: delay --- tests/local.ts | 4 ++-- tests/util/{hasProperty.ts => utils.ts} | 17 ++++++++++++++++- .../{validateLength.ts => validate_length.ts} | 0 3 files changed, 18 insertions(+), 3 deletions(-) rename tests/util/{hasProperty.ts => utils.ts} (51%) rename tests/util/{validateLength.ts => validate_length.ts} (100%) diff --git a/tests/local.ts b/tests/local.ts index 5858743f4..bba4ce566 100644 --- a/tests/local.ts +++ b/tests/local.ts @@ -1,4 +1,4 @@ import "./local/snowflake.ts"; -import "./util/validateLength.ts"; -import "./util/hasProperty.ts"; +import "./util/validate_length.ts"; +import "./util/utils.ts"; import "./util/hash.ts"; diff --git a/tests/util/hasProperty.ts b/tests/util/utils.ts similarity index 51% rename from tests/util/hasProperty.ts rename to tests/util/utils.ts index 7cf0bd412..8ec25bee2 100644 --- a/tests/util/hasProperty.ts +++ b/tests/util/utils.ts @@ -1,5 +1,8 @@ -import { hasProperty } from "../../src/util/utils.ts"; +import { hasProperty, delay } from "../../src/util/utils.ts"; import { assertEquals } from "../deps.ts"; + +// hasProperty + const obj = { prop: "lts372005" }; Deno.test({ name: "[utils] hasProperty does HAVE property", @@ -13,3 +16,15 @@ Deno.test({ assertEquals(hasProperty(obj, "lts372005"), false); }, }); + +// delay + +Deno.test({ + name: "[utils] delay 2000 ms", + async fn() { + const before = Date.now(); + await delay(2000); + const after = Date.now(); + if (after - before < 2000) throw new Error(`delay(2000) delayed ${after - before}ms`); + }, +}); diff --git a/tests/util/validateLength.ts b/tests/util/validate_length.ts similarity index 100% rename from tests/util/validateLength.ts rename to tests/util/validate_length.ts From 1a3123011b2b7e420287410dc6e6bcdc88fdbca1 Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 10:29:34 +0200 Subject: [PATCH 02/13] [Unit Test] messages: editMessage --- tests/helpers/messages/editMessage.ts | 26 ++++++++++++++++++++++++++ tests/mod.ts | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/helpers/messages/editMessage.ts diff --git a/tests/helpers/messages/editMessage.ts b/tests/helpers/messages/editMessage.ts new file mode 100644 index 000000000..0ab4f2f8b --- /dev/null +++ b/tests/helpers/messages/editMessage.ts @@ -0,0 +1,26 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + // Delay the execution by to allow MESSAGE_CREATE event to be processed + await delayUntil(10000, () => bot.cache.messages.has(message.id)); + // Make sure the message was created. + if (!bot.cache.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}"); + } + + // Delete the message now + await bot.helpers.editMessage(channelId, message.id, "Goodbye World!"); + + // Wait to give it time for MESSAGE_UPDATE event + await delayUntil(10000, async () => (await bot.cache.messages.get(message.id))?.content === "Goodbye World!"); + // Make sure it was edited + if ((await bot.cache.messages.get(message.id))?.content !== "Goodbye World!") { + throw new Error("The message should have been edited but it was not."); + } +} diff --git a/tests/mod.ts b/tests/mod.ts index 3dc66bdd6..1a4fa26ac 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -2,6 +2,7 @@ import { TOKEN } from "../configs.ts"; import { createBot, createEventHandlers, DiscordChannelTypes, startBot, stopBot } from "../mod.ts"; import { assertEquals, assertExists } from "./deps.ts"; import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; +import { editMessageTest } from "./helpers/messages/editMessage.ts"; import { delayUntil } from "./utils.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST @@ -104,6 +105,13 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), + t.step({ + name: "[message] edit message", + fn: async (t) => { + await editMessageTest(bot, channel.id, t); + }, + ...sanitizeMode, + }) ]); }); }); From 150fc394437b1f35e1cb4693528f718fcf66dc56 Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 11:21:33 +0200 Subject: [PATCH 03/13] [Unit Test] messages: sendMessage --- tests/helpers/messages/sendMessage.ts | 91 +++++++++++++++++++++++++++ tests/mod.ts | 38 +++++++---- 2 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 tests/helpers/messages/sendMessage.ts diff --git a/tests/helpers/messages/sendMessage.ts b/tests/helpers/messages/sendMessage.ts new file mode 100644 index 000000000..29738fea1 --- /dev/null +++ b/tests/helpers/messages/sendMessage.ts @@ -0,0 +1,91 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; +import {CreateMessage} from "../../../src/types/messages/create_message.ts"; +import { + DiscordMessageComponentTypes +} from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/message_component_types.ts"; +import { + DiscordButtonStyles +} from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/button_styles.ts"; + +async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string | CreateMessage) { + const message = await bot.helpers.sendMessage(channelId, content); + // Assertions + assertExists(message); + // Delay the execution by to allow MESSAGE_CREATE event to be processed + await delayUntil(10000, () => bot.cache.messages.has(message.id)); + // Make sure the message was created. + if (!bot.cache.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached."); + } +} + +export async function sendMessageWithTextTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, channelId, "Hello World!"); +} + +export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, channelId, { + content: "Hello World!", + components: [ + { + type: DiscordMessageComponentTypes.ActionRow, + components: [ + { + type: DiscordMessageComponentTypes.Button, + label: "Doc", + style: DiscordButtonStyles.Link, + url: `https://discordeno.mod.land/` + }, + { + type: DiscordMessageComponentTypes.Button, + label: "Server", + style: DiscordButtonStyles.Link, + url: `https://discord.gg/ddeno` + }, + ] + }, + { + type: DiscordMessageComponentTypes.ActionRow, + components: [ + { + type: DiscordMessageComponentTypes.Button, + label: "Hi", + customId: `hi`, + style: DiscordButtonStyles.Primary, + }, + ] + } + ] + }); +} + +export async function sendMessageWithEmbedsTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, channelId, { + embeds: [ + { + title: "Hello World", + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam at cursus libero. Sed egestas nec ligula sit amet sollicitudin. Curabitur.", + color: 0x00ff00, + footer: { + text: "Discordeno Best Lib" + }, + author: { + name: "Cacahe" + } + }, + { + title: "Goodbye World", + description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean libero enim, blandit tincidunt magna non, auctor pellentesque lacus. Nulla diam.", + color: 0x0000ff, + footer: { + text: "Discordeno Best Lib" + }, + author: { + name: "Wolf" + } + } + ] + }); +} diff --git a/tests/mod.ts b/tests/mod.ts index 1a4fa26ac..6604c5cf1 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -4,6 +4,11 @@ import { assertEquals, assertExists } from "./deps.ts"; import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; import { editMessageTest } from "./helpers/messages/editMessage.ts"; import { delayUntil } from "./utils.ts"; +import { + sendMessageWithComponents, + sendMessageWithEmbedsTest, + sendMessageWithTextTest +} from "./helpers/messages/sendMessage.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST import "./local.ts"; @@ -77,20 +82,29 @@ Deno.test("[Bot] - Starting Tests", async (t) => { // ALL MESSAGE RELATED TESTS THAT DEPEND ON AN EXISTING CHANNEL await t.step("Message related tests", async (t) => { - const message = await bot.helpers.sendMessage(channel.id, "Testing"); - - // Assertions - assertExists(message); - - // Delay the execution to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => bot.cache.messages.has(message.id)); - - if (!bot.cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached."); - } - // CONDUCT ALL TESTS RELATED TO A MESSAGE HERE await Promise.all([ + t.step({ + name: "[message] send message with text", + fn: async (t) => { + await sendMessageWithTextTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] send message with embeds", + fn: async (t) => { + await sendMessageWithEmbedsTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] send message with components", + fn: async (t) => { + await sendMessageWithComponents(bot, channel.id, t); + }, + ...sanitizeMode, + }), t.step({ name: "[message] delete message without a reason", fn: async (t) => { From 66700adbcba3db6dd8086a9d092fbba989728d46 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 30 Oct 2021 09:22:16 +0000 Subject: [PATCH 04/13] change: prettier code --- tests/helpers/messages/sendMessage.ts | 44 +++++++++++++-------------- tests/mod.ts | 4 +-- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/tests/helpers/messages/sendMessage.ts b/tests/helpers/messages/sendMessage.ts index 29738fea1..47e471111 100644 --- a/tests/helpers/messages/sendMessage.ts +++ b/tests/helpers/messages/sendMessage.ts @@ -1,13 +1,9 @@ import { Bot } from "../../../src/bot.ts"; import { assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; -import {CreateMessage} from "../../../src/types/messages/create_message.ts"; -import { - DiscordMessageComponentTypes -} from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/message_component_types.ts"; -import { - DiscordButtonStyles -} from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/button_styles.ts"; +import { CreateMessage } from "../../../src/types/messages/create_message.ts"; +import { DiscordMessageComponentTypes } from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/message_component_types.ts"; +import { DiscordButtonStyles } from "https://raw.githubusercontent.com/discordeno/discordeno/cool-stuff/src/types/messages/components/button_styles.ts"; async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, content: string | CreateMessage) { const message = await bot.helpers.sendMessage(channelId, content); @@ -36,15 +32,15 @@ export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: type: DiscordMessageComponentTypes.Button, label: "Doc", style: DiscordButtonStyles.Link, - url: `https://discordeno.mod.land/` + url: `https://discordeno.mod.land/`, }, { type: DiscordMessageComponentTypes.Button, label: "Server", style: DiscordButtonStyles.Link, - url: `https://discord.gg/ddeno` + url: `https://discord.gg/ddeno`, }, - ] + ], }, { type: DiscordMessageComponentTypes.ActionRow, @@ -55,9 +51,9 @@ export async function sendMessageWithComponents(bot: Bot, channelId: bigint, t: customId: `hi`, style: DiscordButtonStyles.Primary, }, - ] - } - ] + ], + }, + ], }); } @@ -66,26 +62,28 @@ export async function sendMessageWithEmbedsTest(bot: Bot, channelId: bigint, t: embeds: [ { title: "Hello World", - description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam at cursus libero. Sed egestas nec ligula sit amet sollicitudin. Curabitur.", + description: + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam at cursus libero. Sed egestas nec ligula sit amet sollicitudin. Curabitur.", color: 0x00ff00, footer: { - text: "Discordeno Best Lib" + text: "Discordeno Best Lib", }, author: { - name: "Cacahe" - } + name: "Cacahe", + }, }, { title: "Goodbye World", - description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean libero enim, blandit tincidunt magna non, auctor pellentesque lacus. Nulla diam.", + description: + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean libero enim, blandit tincidunt magna non, auctor pellentesque lacus. Nulla diam.", color: 0x0000ff, footer: { - text: "Discordeno Best Lib" + text: "Discordeno Best Lib", }, author: { - name: "Wolf" - } - } - ] + name: "Wolf", + }, + }, + ], }); } diff --git a/tests/mod.ts b/tests/mod.ts index 6604c5cf1..facb9982e 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -7,7 +7,7 @@ import { delayUntil } from "./utils.ts"; import { sendMessageWithComponents, sendMessageWithEmbedsTest, - sendMessageWithTextTest + sendMessageWithTextTest, } from "./helpers/messages/sendMessage.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST @@ -125,7 +125,7 @@ Deno.test("[Bot] - Starting Tests", async (t) => { await editMessageTest(bot, channel.id, t); }, ...sanitizeMode, - }) + }), ]); }); }); From bd8659359f90eb33d3d7b56205c8fee27009f578 Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 11:22:59 +0200 Subject: [PATCH 05/13] Revert "[Unit Test] messages: editMessage" This reverts commit 1a3123011b2b7e420287410dc6e6bcdc88fdbca1. --- tests/helpers/messages/editMessage.ts | 26 -------------------------- tests/mod.ts | 8 -------- 2 files changed, 34 deletions(-) delete mode 100644 tests/helpers/messages/editMessage.ts diff --git a/tests/helpers/messages/editMessage.ts b/tests/helpers/messages/editMessage.ts deleted file mode 100644 index 0ab4f2f8b..000000000 --- a/tests/helpers/messages/editMessage.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Bot } from "../../../src/bot.ts"; -import { assertExists } from "../../deps.ts"; -import { delayUntil } from "../../utils.ts"; - -export async function editMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { - const message = await bot.helpers.sendMessage(channelId, "Hello World!"); - - // Assertions - assertExists(message); - // Delay the execution by to allow MESSAGE_CREATE event to be processed - await delayUntil(10000, () => bot.cache.messages.has(message.id)); - // Make sure the message was created. - if (!bot.cache.messages.has(message.id)) { - throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}"); - } - - // Delete the message now - await bot.helpers.editMessage(channelId, message.id, "Goodbye World!"); - - // Wait to give it time for MESSAGE_UPDATE event - await delayUntil(10000, async () => (await bot.cache.messages.get(message.id))?.content === "Goodbye World!"); - // Make sure it was edited - if ((await bot.cache.messages.get(message.id))?.content !== "Goodbye World!") { - throw new Error("The message should have been edited but it was not."); - } -} diff --git a/tests/mod.ts b/tests/mod.ts index 6604c5cf1..ed10d2c9f 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -2,7 +2,6 @@ import { TOKEN } from "../configs.ts"; import { createBot, createEventHandlers, DiscordChannelTypes, startBot, stopBot } from "../mod.ts"; import { assertEquals, assertExists } from "./deps.ts"; import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; -import { editMessageTest } from "./helpers/messages/editMessage.ts"; import { delayUntil } from "./utils.ts"; import { sendMessageWithComponents, @@ -119,13 +118,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), - t.step({ - name: "[message] edit message", - fn: async (t) => { - await editMessageTest(bot, channel.id, t); - }, - ...sanitizeMode, - }) ]); }); }); From 4720fd0c77dd7921a43d052b0ab293dc27e94376 Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 11:35:34 +0200 Subject: [PATCH 06/13] [Unit Test] messages: deleteMessages --- tests/helpers/messages/deleteMessages.ts | 36 ++++++++++++++++++++++++ tests/mod.ts | 15 ++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/helpers/messages/deleteMessages.ts diff --git a/tests/helpers/messages/deleteMessages.ts b/tests/helpers/messages/deleteMessages.ts new file mode 100644 index 000000000..cc026eac0 --- /dev/null +++ b/tests/helpers/messages/deleteMessages.ts @@ -0,0 +1,36 @@ +import { Bot } from "../../../src/bot.ts"; +import { assertExists } from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + const secondMessage = await bot.helpers.sendMessage(channelId, "Hello World 2!"); + + // Assertions + assertExists(message); + assertExists(secondMessage); + // Delay the execution by to allow MESSAGE_CREATE event to be processed + await delayUntil(10000, () => bot.cache.messages.has(message.id) && bot.cache.messages.has(secondMessage.id)); + // Make sure the message was created. + if (!bot.cache.messages.has(message.id) || !bot.cache.messages.has(secondMessage.id)) { + throw new Error(`The message seemed to be sent but it was not cached. Reason: ${reason}`); + } + + // Delete the message now + await bot.helpers.deleteMessages(channelId, [message.id, secondMessage.id], reason); + + // Wait to give it time for MESSAGE_DELETE event + await delayUntil(10000, () => !bot.cache.messages.has(message.id) && !bot.cache.messages.has(secondMessage.id)); + // Make sure it is gone from cache + if (bot.cache.messages.has(message.id) || bot.cache.messages.has(secondMessage.id)) { + throw new Error("The messages should have been deleted but they are still in cache."); + } +} + +export async function deleteMessagesWithoutReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, channelId); +} + +export async function deleteMessagesWithReasonTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + await ifItFailsBlameWolf(bot, channelId, "with a reason"); +} diff --git a/tests/mod.ts b/tests/mod.ts index 3dc66bdd6..b6b47442c 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -2,6 +2,7 @@ import { TOKEN } from "../configs.ts"; import { createBot, createEventHandlers, DiscordChannelTypes, startBot, stopBot } from "../mod.ts"; import { assertEquals, assertExists } from "./deps.ts"; import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts"; +import { deleteMessagesWithoutReasonTest, deleteMessagesWithReasonTest } from "./helpers/messages/deleteMessages.ts"; import { delayUntil } from "./utils.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST @@ -104,6 +105,20 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), + t.step({ + name: "[message] delete messages without a reason", + fn: async (t) => { + await deleteMessagesWithoutReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] delete messages with a reason", + fn: async (t) => { + await deleteMessagesWithReasonTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), ]); }); }); From 8c853766b323bfc0e29a05110639b3c7fc87907a Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 13:51:40 +0200 Subject: [PATCH 07/13] [Unit Test] messages: getMessage --- tests/helpers/messages/getMessage.ts | 22 ++++++++++++++++++++++ tests/mod.ts | 8 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/helpers/messages/getMessage.ts diff --git a/tests/helpers/messages/getMessage.ts b/tests/helpers/messages/getMessage.ts new file mode 100644 index 000000000..8b4e8fff0 --- /dev/null +++ b/tests/helpers/messages/getMessage.ts @@ -0,0 +1,22 @@ +import { Bot } from "../../../src/bot.ts"; +import {assertEquals, assertExists} from "../../deps.ts"; +import { delayUntil } from "../../utils.ts"; + +export async function getMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { + const message = await bot.helpers.sendMessage(channelId, "Hello World!"); + + // Assertions + assertExists(message); + // Delay the execution by to allow MESSAGE_CREATE event to be processed + await delayUntil(10000, () => bot.cache.messages.has(message.id)); + // Make sure the message was created. + if (!bot.cache.messages.has(message.id)) { + throw new Error("The message seemed to be sent but it was not cached. Reason: ${reason}"); + } + + // Fetch the message + const fetchedMessage = await bot.helpers.getMessage(channelId, message.id); + // Check if getMessage has worked + assertEquals(fetchedMessage.id, message.id); + assertEquals(fetchedMessage.content, message.content); +} diff --git a/tests/mod.ts b/tests/mod.ts index 3dc66bdd6..36a48fe00 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -6,6 +6,7 @@ import { delayUntil } from "./utils.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST import "./local.ts"; +import {getMessageTest} from "./helpers/messages/getMessage.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS @@ -104,6 +105,13 @@ Deno.test("[Bot] - Starting Tests", async (t) => { }, ...sanitizeMode, }), + t.step({ + name: "[message] fetch a message", + fn: async (t) => { + await getMessageTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), ]); }); }); From 73fea75ff7bea35ad441479e530499ff429a488f Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 30 Oct 2021 11:52:20 +0000 Subject: [PATCH 08/13] change: prettier code --- tests/helpers/messages/getMessage.ts | 2 +- tests/mod.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/helpers/messages/getMessage.ts b/tests/helpers/messages/getMessage.ts index 8b4e8fff0..58c037322 100644 --- a/tests/helpers/messages/getMessage.ts +++ b/tests/helpers/messages/getMessage.ts @@ -1,5 +1,5 @@ import { Bot } from "../../../src/bot.ts"; -import {assertEquals, assertExists} from "../../deps.ts"; +import { assertEquals, assertExists } from "../../deps.ts"; import { delayUntil } from "../../utils.ts"; export async function getMessageTest(bot: Bot, channelId: bigint, t: Deno.TestContext) { diff --git a/tests/mod.ts b/tests/mod.ts index 36a48fe00..5afc7cacc 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -6,7 +6,7 @@ import { delayUntil } from "./utils.ts"; // CONDUCT LOCAL TESTS FIRST BEFORE RUNNING API TEST import "./local.ts"; -import {getMessageTest} from "./helpers/messages/getMessage.ts"; +import { getMessageTest } from "./helpers/messages/getMessage.ts"; Deno.test("[Bot] - Starting Tests", async (t) => { // CHANGE TO TRUE WHEN DEBUGGING SANITIZATION ERRORS From 96fd804628f29d47f1ef5612bfd8a21539e8d322 Mon Sep 17 00:00:00 2001 From: Quentin Nicolini Date: Sat, 30 Oct 2021 13:56:56 +0200 Subject: [PATCH 09/13] Fix comments --- tests/helpers/messages/deleteMessages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/helpers/messages/deleteMessages.ts b/tests/helpers/messages/deleteMessages.ts index cc026eac0..592417057 100644 --- a/tests/helpers/messages/deleteMessages.ts +++ b/tests/helpers/messages/deleteMessages.ts @@ -16,12 +16,12 @@ async function ifItFailsBlameWolf(bot: Bot, channelId: bigint, reason?: string) throw new Error(`The message seemed to be sent but it was not cached. Reason: ${reason}`); } - // Delete the message now + // Delete the messages now await bot.helpers.deleteMessages(channelId, [message.id, secondMessage.id], reason); // Wait to give it time for MESSAGE_DELETE event await delayUntil(10000, () => !bot.cache.messages.has(message.id) && !bot.cache.messages.has(secondMessage.id)); - // Make sure it is gone from cache + // Make sure they are gone from cache if (bot.cache.messages.has(message.id) || bot.cache.messages.has(secondMessage.id)) { throw new Error("The messages should have been deleted but they are still in cache."); } From 1367d34982832e5d9e507353e5f8a96017871f72 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 30 Oct 2021 14:50:27 +0200 Subject: [PATCH 10/13] Add missing interaction data --- src/transformers/interaction.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/transformers/interaction.ts b/src/transformers/interaction.ts index e7dc45590..260fe065d 100644 --- a/src/transformers/interaction.ts +++ b/src/transformers/interaction.ts @@ -22,6 +22,8 @@ export function transformInteraction(bot: Bot, payload: SnakeCasedPropertiesDeep message: payload.message ? bot.transformers.message(bot, payload.message) : undefined, channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined, member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, user.id) : undefined, + // TODO: CamelCase INTERACTION DATA + data: payload.data }; } From 1a3e821f7ab8151f0dbb77feb39453a1e7b1fff8 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 30 Oct 2021 12:50:56 +0000 Subject: [PATCH 11/13] change: prettier code --- src/transformers/interaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/interaction.ts b/src/transformers/interaction.ts index 260fe065d..a104aad1c 100644 --- a/src/transformers/interaction.ts +++ b/src/transformers/interaction.ts @@ -23,7 +23,7 @@ export function transformInteraction(bot: Bot, payload: SnakeCasedPropertiesDeep channelId: payload.channel_id ? bot.transformers.snowflake(payload.channel_id) : undefined, member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, user.id) : undefined, // TODO: CamelCase INTERACTION DATA - data: payload.data + data: payload.data, }; } From 844019c4a4a9dce44aaf5ad36fb075262ff1005b Mon Sep 17 00:00:00 2001 From: TriForMine Date: Sat, 30 Oct 2021 14:58:14 +0200 Subject: [PATCH 12/13] Fix: sendInteractionResponse --- .../interactions/send_interaction_response.ts | 64 +++++++++++++++++-- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/src/helpers/interactions/send_interaction_response.ts b/src/helpers/interactions/send_interaction_response.ts index 65cdf4d7a..6568b4009 100644 --- a/src/helpers/interactions/send_interaction_response.ts +++ b/src/helpers/interactions/send_interaction_response.ts @@ -39,13 +39,63 @@ export async function sendInteractionResponse( 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, - allowed_mentions: { - parse: allowedMentions.parse, - roles: allowedMentions.roles, - users: allowedMentions.users, - replied_user: allowedMentions.repliedUser, - }, + 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: allowedMentions + ? { + parse: allowedMentions?.parse, + roles: allowedMentions?.roles, + users: allowedMentions?.users, + replied_user: allowedMentions?.repliedUser, + } + : undefined, file: options.data.file, // TODO: Snakelize components?? components: options.data.components, From a01f1c08cd2217d76f62c43b2ca3e2458b4d8ba6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Sat, 30 Oct 2021 13:42:22 +0000 Subject: [PATCH 13/13] change: prettier code --- tests/mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mod.ts b/tests/mod.ts index 6e2b2f1e1..51a3b73d7 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -131,7 +131,7 @@ Deno.test("[Bot] - Starting Tests", async (t) => { name: "[message] delete messages with a reason", fn: async (t) => { await deleteMessagesWithReasonTest(bot, channel.id, t); - }, + }, ...sanitizeMode, }), t.step({