From b91559bdf1a1cd906da21520de6b80e5431f29b9 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 13 Nov 2021 17:42:37 +0100 Subject: [PATCH 1/6] fix(helpers): addReaction --- src/helpers/messages/add_reaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index cb085f02a..3ed2edb7a 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -11,6 +11,6 @@ export async function addReaction(bot: Bot, channelId: bigint, messageId: bigint return await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction) + bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)) ); } From e03ec5134d9d3edf8cf7097900b769c973f192e1 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 13 Nov 2021 17:42:43 +0100 Subject: [PATCH 2/6] fix(helpers): getReactions --- src/helpers/messages/get_reactions.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/messages/get_reactions.ts b/src/helpers/messages/get_reactions.ts index 6258df559..8943c9fb9 100644 --- a/src/helpers/messages/get_reactions.ts +++ b/src/helpers/messages/get_reactions.ts @@ -11,10 +11,16 @@ export async function getReactions( reaction: string, options?: GetReactions ) { + if (reaction.startsWith("<:")) { + reaction = reaction.substring(2, reaction.length - 1); + } else if (reaction.startsWith("( bot.rest, "get", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), + bot.constants.endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, encodeURIComponent(reaction)), options ); From 1912e4e242eff6462c581e68ac9f62dfff1264ec Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 13 Nov 2021 17:42:50 +0100 Subject: [PATCH 3/6] fix(helpers): removeReaction --- src/helpers/messages/remove_reaction.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index d43b84f5c..e15274565 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -18,7 +18,12 @@ export async function removeReaction( bot.rest, "delete", options?.userId - ? bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_USER(channelId, messageId, reaction, options.userId) - : bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction) + ? bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_USER( + channelId, + messageId, + encodeURIComponent(reaction), + options.userId + ) + : bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)) ); } From 711f6ba4246653f7b8011cbb7b5c61ea8e2150e7 Mon Sep 17 00:00:00 2001 From: ITOH Date: Sat, 13 Nov 2021 18:26:07 +0100 Subject: [PATCH 4/6] Update mod.ts --- tests/mod.ts | 126 +++++++++++++++++++++++++-------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/tests/mod.ts b/tests/mod.ts index 19c2531fd..8cefc6d31 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -324,69 +324,69 @@ Deno.test({ }, ...sanitizeMode, }), - // t.step({ - // name: "[message] add a reaction", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] add a custom reaction", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] add multiple reactions", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] add multiple custom reactions", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] add multiple reactions in order", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] add multiple custom reactions in order", - // fn: async (t) => { - // await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] remove a reaction.", - // fn: async (t) => { - // await removeReactionTest(bot, channel.id, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] remove all reactions.", - // fn: async (t) => { - // await removeAllReactionTests(bot, channel.id, t); - // }, - // ...sanitizeMode, - // }), - // t.step({ - // name: "[message] remove emoji reactions.", - // fn: async (t) => { - // await removeReactionEmojiTest(bot, channel.id, t); - // }, - // ...sanitizeMode, - // }), + t.step({ + name: "[message] add a reaction", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: true, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add a custom reaction", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: true, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple reactions", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple custom reactions", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: false }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple reactions in order", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: false, single: false, ordered: true }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] add multiple custom reactions in order", + fn: async (t) => { + await addReactionTest(bot, guild.id, channel.id, { custom: true, single: false, ordered: true }, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove a reaction.", + fn: async (t) => { + await removeReactionTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove all reactions.", + fn: async (t) => { + await removeAllReactionTests(bot, channel.id, t); + }, + ...sanitizeMode, + }), + t.step({ + name: "[message] remove emoji reactions.", + fn: async (t) => { + await removeReactionEmojiTest(bot, channel.id, t); + }, + ...sanitizeMode, + }), // t.step({ // name: "[message] pin a message", // fn: async (t) => { From 99e7317490031c996abdd0fcd8eb23108b82e3d6 Mon Sep 17 00:00:00 2001 From: ITOH Date: Wed, 17 Nov 2021 19:26:20 +0100 Subject: [PATCH 5/6] ifk --- src/helpers/messages/addReaction.ts | 3 ++- src/rest/createRequestBody.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helpers/messages/addReaction.ts b/src/helpers/messages/addReaction.ts index 3ed2edb7a..1f4390a49 100644 --- a/src/helpers/messages/addReaction.ts +++ b/src/helpers/messages/addReaction.ts @@ -11,6 +11,7 @@ export async function addReaction(bot: Bot, channelId: bigint, messageId: bigint return await bot.rest.runMethod( bot.rest, "put", - bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)) + bot.constants.endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, encodeURIComponent(reaction)), + {} ); } diff --git a/src/rest/createRequestBody.ts b/src/rest/createRequestBody.ts index cba842825..9512bbaeb 100644 --- a/src/rest/createRequestBody.ts +++ b/src/rest/createRequestBody.ts @@ -45,7 +45,7 @@ export function createRequestBody(rest: RestManager, queuedRequest: { request: R if (!queuedRequest.payload.body) headers["Content-Length"] = "0"; return { headers, - body: (queuedRequest.payload.body?.file || JSON.stringify(queuedRequest.payload.body)) as FormData | string, + body: (queuedRequest.payload.body?.file ?? JSON.stringify(queuedRequest.payload.body)) as FormData | string, method: queuedRequest.request.method.toUpperCase(), }; } From 6a09988c01d635415a400e5f65afdcfcffe0f91b Mon Sep 17 00:00:00 2001 From: ITOH Date: Thu, 18 Nov 2021 18:43:12 +0100 Subject: [PATCH 6/6] impr --- src/helpers/interactions/sendInteractionResponse.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/helpers/interactions/sendInteractionResponse.ts b/src/helpers/interactions/sendInteractionResponse.ts index b0f92b449..8d59568fb 100644 --- a/src/helpers/interactions/sendInteractionResponse.ts +++ b/src/helpers/interactions/sendInteractionResponse.ts @@ -134,9 +134,7 @@ export async function sendInteractionResponse( }; // A reply has never been send - if (bot.cache.unrepliedInteractions.has(id)) { - bot.cache.unrepliedInteractions.delete(id); - + if (bot.cache.unrepliedInteractions.delete(id)) { return await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.INTERACTION_ID_TOKEN(id, token), { type: options.type, data,