diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index b8bd2f707..1be275af9 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -1,12 +1,18 @@ import { rest } from "../../rest/rest.ts"; import { endpoints } from "../../util/constants.ts"; +import { requireBotChannelPermissions } from "../../util/permissions.ts"; -/** Removes a reaction from the bot on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ +/** Removes a reaction from the given user on this message, defaults to bot. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ export async function removeReaction( channelId: string, messageId: string, reaction: string, + userId?: string, ) { + if (userId) { + await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); + } + if (reaction.startsWith("<:")) { reaction = reaction.substring(2, reaction.length - 1); } else if (reaction.startsWith("( "delete", - endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), + userId + ? endpoints.CHANNEL_MESSAGE_REACTION_USER( + channelId, + messageId, + reaction, + userId, + ) + : endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction), ); } diff --git a/src/helpers/messages/remove_user_reaction.ts b/src/helpers/messages/remove_user_reaction.ts deleted file mode 100644 index 7f5b67dfd..000000000 --- a/src/helpers/messages/remove_user_reaction.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { rest } from "../../rest/rest.ts"; -import { endpoints } from "../../util/constants.ts"; -import { requireBotChannelPermissions } from "../../util/permissions.ts"; - -/** Removes a reaction from the specified user on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */ -export async function removeUserReaction( - channelId: string, - messageId: string, - reaction: string, - userId: string, -) { - await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]); - - if (reaction.startsWith("<:")) { - reaction = reaction.substring(2, reaction.length - 1); - } else if (reaction.startsWith("( - "delete", - endpoints.CHANNEL_MESSAGE_REACTION_USER( - channelId, - messageId, - reaction, - userId, - ), - ); -} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index ee1de11cb..483f7378f 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -93,7 +93,6 @@ import { publishMessage } from "./messages/publish_message.ts"; import { removeAllReactions } from "./messages/remove_all_reactions.ts"; import { removeReaction } from "./messages/remove_reaction.ts"; import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts"; -import { removeUserReaction } from "./messages/remove_user_reaction.ts"; import { sendMessage } from "./messages/send_message.ts"; import { unpin, unpinMessage } from "./messages/unpin_message.ts"; import { editBotStatus } from "./misc/edit_bot_status.ts"; @@ -240,7 +239,6 @@ export { removeReaction, removeReactionEmoji, removeRole, - removeUserReaction, sendDirectMessage, sendInteractionResponse, sendMessage, @@ -361,7 +359,6 @@ export let helpers = { removeAllReactions, removeReactionEmoji, removeReaction, - removeUserReaction, sendMessage, unpinMessage, // misc diff --git a/src/structures/message.ts b/src/structures/message.ts index 9f24937ee..add15b8c4 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -121,8 +121,8 @@ const baseMessage: Partial = { removeReactionEmoji(reaction) { return removeReactionEmoji(this.channelId!, this.id!, reaction); }, - removeReaction(reaction) { - return removeReaction(this.channelId!, this.id!, reaction); + removeReaction(reaction, userId) { + return removeReaction(this.channelId!, this.id!, reaction, userId); }, }; @@ -255,5 +255,8 @@ export interface DiscordenoMessage /** Remove all reactions */ removeReactionEmoji(reaction: string): ReturnType; /** Remove all reactions */ - removeReaction(reaction: string): ReturnType; + removeReaction( + reaction: string, + userId?: string, + ): ReturnType; } diff --git a/tests/messages/remove_user_reaction.ts b/tests/messages/remove_user_reaction.ts index 0662738b4..4c3859c03 100644 --- a/tests/messages/remove_user_reaction.ts +++ b/tests/messages/remove_user_reaction.ts @@ -1,12 +1,7 @@ -import { - addReaction, - cache, - removeUserReaction, - sendMessage, -} from "../../mod.ts"; -import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; +import { addReaction, cache, removeReaction, sendMessage } from "../../mod.ts"; import { assertEquals, assertExists } from "../deps.ts"; import { delayUntil } from "../util/delay_until.ts"; +import { defaultTestOptions, tempData } from "../ws/start_bot.ts"; async function ifItFailsBlameWolf(type: "getter" | "raw") { const message = await sendMessage(tempData.channelId, "Hello World!"); @@ -32,7 +27,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw") { assertEquals(await cache.messages.get(message.id)?.reactions?.length, 1); if (type === "raw") { - await removeUserReaction( + await removeReaction( message.channelId, message.id, "❤",