Skip to content

Commit

Permalink
feat - message reaction remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaga committed Nov 9, 2023
1 parent 91f6f93 commit a51ba3b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/api/discord/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions src/modules/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/modules/message/service/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class MessageService {

return this.axiosService.discordRequest(apiConfig);
}

/**Embed Message Patch */
async editEmbed(
channelId: string,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a51ba3b

Please sign in to comment.