diff --git a/src/api/discord/message.ts b/src/api/discord/message.ts index c815e80..e4c22b7 100644 --- a/src/api/discord/message.ts +++ b/src/api/discord/message.ts @@ -6,7 +6,7 @@ import { ICreateThread } from '../../modules/message/interface/messages.interfac @injectable() export class MessageAPI extends DiscordBaseAPI { - ///Send Message to a channel + /** Send Message to a channel */ sendMessage(channelId: string, body: any) { return { method: 'POST', @@ -20,7 +20,7 @@ export class MessageAPI extends DiscordBaseAPI { } as IDiscordAxiosConfig; } - ///Reply to a message with plain message + /** Reply to a message with plain message */ replyMessage(channelId: string, body: any) { return { method: 'POST', @@ -34,7 +34,7 @@ export class MessageAPI extends DiscordBaseAPI { } as IDiscordAxiosConfig; } - ///Create message from thread + /** Create message from thread */ createThread(channelId: string, messageId: string, payload: ICreateThread) { return { method: 'POST', @@ -48,7 +48,7 @@ export class MessageAPI extends DiscordBaseAPI { } as IDiscordAxiosConfig; } - ///Edit a message + /** Edit a message */ editMessage(channelId: string, messageId: string, body: any) { return { method: 'PATCH', @@ -62,7 +62,7 @@ export class MessageAPI extends DiscordBaseAPI { } as IDiscordAxiosConfig; } - ///React to a message + /** React to a message */ messageReact(channelId: string, messageId: string, reaction: string) { return { method: 'PUT', @@ -74,11 +74,31 @@ export class MessageAPI extends DiscordBaseAPI { data: { emoji: reaction, }, - endpointType: `channelReactMessage:{${channelId}}`, + endpointType: `channelMessageReaction:{${channelId}}`, } as IDiscordAxiosConfig; } - ///Delete a message in a channel + /** Remove message reaction */ + removeMessageReaction( + channelId: string, + messageId: string, + reaction: string, + ) { + return { + method: 'DELETE', + url: `${this.DISCORD_API}/channels/${channelId}/messages/${messageId}/reactions/${reaction}/@me`, + headers: { + Authorization: this.authorization(configStore.clientOptions.token), + ...this.headers, + }, + data: { + emoji: reaction, + }, + endpointType: `channelMessageReactionRemove:{${channelId}}`, + } as IDiscordAxiosConfig; + } + + /** Delete a message in a channel */ deleteMessage(channelId: string, messageId: string) { return { method: 'DELETE', diff --git a/src/modules/message/message.ts b/src/modules/message/message.ts index c24ddf5..d8c9476 100644 --- a/src/modules/message/message.ts +++ b/src/modules/message/message.ts @@ -58,6 +58,15 @@ export class Message { return this.messageService.messageReact(channelId, messageId, reaction); } + /**Remove message reaction */ + async removeReaction(channelId: string, messageId: string, reaction: string) { + return this.messageService.messageReactionRemove( + channelId, + messageId, + reaction, + ); + } + /**Delete message */ async delete(channelId: string, messageId: string) { return this.messageService.deleteMessage(channelId, messageId); diff --git a/src/modules/message/service/message.service.ts b/src/modules/message/service/message.service.ts index f85753d..064cc1e 100644 --- a/src/modules/message/service/message.service.ts +++ b/src/modules/message/service/message.service.ts @@ -62,6 +62,7 @@ export class MessageService { return this.axiosService.discordRequest(apiConfig); } + /**Embed Message Patch */ async editEmbed( channelId: string, @@ -91,6 +92,26 @@ export class MessageService { return this.axiosService.discordRequest(apiConfig); } + /**REact to a message */ + async messageReactionRemove( + channelId: string, + messageId: string, + reaction: string, + ) { + //Check and decode emoji if not already done + if (reaction === decodeURIComponent(reaction)) { + reaction = encodeURIComponent(reaction); + } + + const apiConfig = this.messageAPI.removeMessageReaction( + channelId, + messageId, + reaction, + ); + + return this.axiosService.discordRequest(apiConfig); + } + /**Message Delete */ async deleteMessage(channelId: string, messageId: string) { const apiConfig = this.messageAPI.deleteMessage(channelId, messageId);