From 94062d19dd1c4b10af1177bc6b574e6c6148a8ea Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Thu, 16 Mar 2017 08:38:12 -0500 Subject: [PATCH] Add message/channel/guild acknowledging (#1239) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add acking * 👀 * Update RESTMethods.js * Update TextBasedChannel.js * Update RESTMethods.js * Update Guild.js * Update TextBasedChannel.js * Update Message.js * super shitty names * Update GroupDMChannel.js * Update DMChannel.js * Update TextChannel.js --- src/client/rest/RESTMethods.js | 28 ++++++++++++++++++++ src/structures/DMChannel.js | 1 + src/structures/GroupDMChannel.js | 1 + src/structures/Guild.js | 9 +++++++ src/structures/Message.js | 9 +++++++ src/structures/TextChannel.js | 1 + src/structures/interface/TextBasedChannel.js | 9 +++++++ 7 files changed, 58 insertions(+) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 306749b14..015a1e14d 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -23,6 +23,7 @@ class RESTMethods { constructor(restManager) { this.rest = restManager; this.client = restManager.client; + this._ackToken = null; } login(token = this.client.token) { @@ -151,6 +152,33 @@ class RESTMethods { ); } + ackMessage(message) { + return this.rest.makeRequest('post', + `${Constants.Endpoints.channelMessage(message.channel.id, message.id)}/ack`, + true, + { token: this._ackToken } + ).then(res => { + this._ackToken = res.token; + return message; + }); + } + + ackTextChannel(channel) { + return this.rest.makeRequest('post', + `${Constants.Endpoints.channel(channel.id)}/ack`, + true, + { token: this._ackToken } + ).then(res => { + this._ackToken = res.token; + return channel; + }); + } + + ackGuild(guild) { + return this.rest.makeRequest('post', `${Constants.Endpoints.guild(guild.id)}/ack`, true) + .then(() => guild); + } + bulkDeleteMessages(channel, messages, filterOld) { if (filterOld) { messages = messages.filter(id => diff --git a/src/structures/DMChannel.js b/src/structures/DMChannel.js index aa7d5c5cc..4eefa79c8 100644 --- a/src/structures/DMChannel.js +++ b/src/structures/DMChannel.js @@ -54,6 +54,7 @@ class DMChannel extends Channel { createCollector() { return; } awaitMessages() { return; } // doesn't work on DM channels; bulkDelete() { return; } + acknowledge() { return; } _cacheMessage() { return; } } diff --git a/src/structures/GroupDMChannel.js b/src/structures/GroupDMChannel.js index 073520a9d..74a7945d3 100644 --- a/src/structures/GroupDMChannel.js +++ b/src/structures/GroupDMChannel.js @@ -170,6 +170,7 @@ class GroupDMChannel extends Channel { createCollector() { return; } awaitMessages() { return; } // doesn't work on group DMs; bulkDelete() { return; } + acknowledge() { return; } _cacheMessage() { return; } } diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 617ce1e79..cdaf3fd4d 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -770,6 +770,15 @@ class Guild { return this.client.rest.methods.deleteGuild(this); } + /** + * Marks all messages in this guild as read + * This is only available when using a user account. + * @returns {Promise} this guild + */ + acknowledge() { + return this.client.rest.methods.ackGuild(this); + } + /** * Whether this Guild equals another Guild. It compares all properties, so for most operations * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often diff --git a/src/structures/Message.js b/src/structures/Message.js index 13aff164a..f075cdd33 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -493,6 +493,15 @@ class Message { return this.channel.send(content, Object.assign(options, { reply: this.member || this.author })); } + /** + * Marks the message as read + * This is only available when using a user account. + * @returns {Promise} + */ + acknowledge() { + return this.client.rest.methods.ackMessage(this); + } + /** * Fetches the webhook used to create this message. * @returns {Promise} diff --git a/src/structures/TextChannel.js b/src/structures/TextChannel.js index 9e0ca96a9..f6b8de38d 100644 --- a/src/structures/TextChannel.js +++ b/src/structures/TextChannel.js @@ -90,6 +90,7 @@ class TextChannel extends GuildChannel { createCollector() { return; } awaitMessages() { return; } bulkDelete() { return; } + acknowledge() { return; } _cacheMessage() { return; } } diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index c05906764..0d9cdf4e5 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -423,6 +423,15 @@ class TextBasedChannel { throw new TypeError('The messages must be an Array, Collection, or number.'); } + /** + * Marks all messages in this channel as read + * This is only available when using a user account. + * @returns {Promise} + */ + acknowledge() { + return this.client.rest.methods.ackTextMessage(this); + } + _cacheMessage(message) { const maxSize = this.client.options.messageCacheMaxSize; if (maxSize === 0) return null;