From 9e6d2c10474928673a71251527a0b1b7d65a547f Mon Sep 17 00:00:00 2001 From: Helloyunho Date: Thu, 24 Dec 2020 09:37:57 +0900 Subject: [PATCH] Add reactions --- src/structures/message.ts | 9 ++++++++ src/structures/textChannel.ts | 40 ++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/structures/message.ts b/src/structures/message.ts index d8e6325..7e32b18 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -17,6 +17,7 @@ import { TextChannel } from './textChannel.ts' import { Guild } from './guild.ts' import { MessageReactionsManager } from '../managers/messageReactions.ts' import { MessageSticker } from './messageSticker.ts' +import { Emoji } from './emoji.ts' type AllMessageOptions = MessageOption | Embed @@ -129,4 +130,12 @@ export class Message extends Base { async delete(): Promise { return this.client.rest.delete(CHANNEL_MESSAGE(this.channelID, this.id)) } + + async addReaction(emoji: string | Emoji): Promise { + return this.channel.addReaction(this, emoji) + } + + async removeReaction(emoji: string | Emoji): Promise { + return this.channel.removeReaction(this, emoji) + } } diff --git a/src/structures/textChannel.ts b/src/structures/textChannel.ts index 699b4ad..a95bc6f 100644 --- a/src/structures/textChannel.ts +++ b/src/structures/textChannel.ts @@ -12,10 +12,12 @@ import { import { CHANNEL, CHANNEL_MESSAGE, - CHANNEL_MESSAGES + CHANNEL_MESSAGES, + MESSAGE_REACTION_ME } from '../types/endpoint.ts' import { Channel } from './channel.ts' import { Embed } from './embed.ts' +import { Emoji } from './emoji.ts' import { Guild } from './guild.ts' import { Message } from './message.ts' @@ -124,6 +126,42 @@ export class TextChannel extends Channel { await res.mentions.fromPayload(newMsg) return res } + + async addReaction( + message: Message | string, + emoji: Emoji | string + ): Promise { + if (emoji instanceof Emoji) { + emoji = emoji.getEmojiString + } + if (message instanceof Message) { + message = message.id + } + + const encodedEmoji = encodeURI(emoji) + + await this.client.rest.put( + MESSAGE_REACTION_ME(this.id, message, encodedEmoji) + ) + } + + async removeReaction( + message: Message | string, + emoji: Emoji | string + ): Promise { + if (emoji instanceof Emoji) { + emoji = emoji.getEmojiString + } + if (message instanceof Message) { + message = message.id + } + + const encodedEmoji = encodeURI(emoji) + + await this.client.rest.delete( + MESSAGE_REACTION_ME(this.id, message, encodedEmoji) + ) + } } export class GuildTextChannel extends TextChannel {