From ebc34a52c29a1abae3e1f4c2aabd9b780fa60afe Mon Sep 17 00:00:00 2001 From: Anson Foong Date: Sat, 23 May 2020 19:25:04 -0400 Subject: [PATCH] feat(unpin-msg): Added message.unpin() method to unpin messages. --- src/client/rest/RestAPIHandler.ts | 4 ++++ src/index.ts | 2 ++ src/models/Message.ts | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/client/rest/RestAPIHandler.ts b/src/client/rest/RestAPIHandler.ts index 8045c9c..9c7d046 100644 --- a/src/client/rest/RestAPIHandler.ts +++ b/src/client/rest/RestAPIHandler.ts @@ -77,6 +77,10 @@ export default class RestAPIHandler { return fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${channelId}/${ENDPOINTS.PINS}/${messageId}`, { method: 'PUT', headers }); } + async unpinMessage(channelId: string, messageId: string): Promise { + return fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${channelId}/${ENDPOINTS.PINS}/${messageId}`, { method: 'DELETE', headers }); + } + async createMessage(options: MessageOptions, id: string) { const response = await fetch( `${Constants.API}/${ENDPOINTS.CHANNELS}/${id}/${ENDPOINTS.MESSAGES}`, diff --git a/src/index.ts b/src/index.ts index 2539821..185b4c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,8 @@ client.on("message", async (message: Message) => { await message.fetch(); } else if (message.content === '?pin') { await message.pin(); + } else if (message.content === '?unpin') { + await message.unpin(); } }); diff --git a/src/models/Message.ts b/src/models/Message.ts index 821d6af..f4544a5 100644 --- a/src/models/Message.ts +++ b/src/models/Message.ts @@ -155,6 +155,11 @@ export class Message { await this.channel.client.rest.pinMessage(this.channel.id, this.id); return this; } + + public async unpin(): Promise { + await this.channel.client.rest.unpinMessage(this.channel.id, this.id); + return this; + } }