mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Add message/channel/guild acknowledging (#1239)
* 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
This commit is contained in:
committed by
Schuyler Cebulskie
parent
fa609caee2
commit
94062d19dd
@@ -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 =>
|
||||
|
||||
@@ -54,6 +54,7 @@ class DMChannel extends Channel {
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
// doesn't work on DM channels; bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +170,7 @@ class GroupDMChannel extends Channel {
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
// doesn't work on group DMs; bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
}
|
||||
|
||||
|
||||
@@ -770,6 +770,15 @@ class Guild {
|
||||
return this.client.rest.methods.deleteGuild(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks all messages in this guild as read
|
||||
* <warn>This is only available when using a user account.</warn>
|
||||
* @returns {Promise<Guild>} 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
|
||||
|
||||
@@ -493,6 +493,15 @@ class Message {
|
||||
return this.channel.send(content, Object.assign(options, { reply: this.member || this.author }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the message as read
|
||||
* <warn>This is only available when using a user account.</warn>
|
||||
* @returns {Promise<Message>}
|
||||
*/
|
||||
acknowledge() {
|
||||
return this.client.rest.methods.ackMessage(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the webhook used to create this message.
|
||||
* @returns {Promise<?Webhook>}
|
||||
|
||||
@@ -90,6 +90,7 @@ class TextChannel extends GuildChannel {
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
* <warn>This is only available when using a user account.</warn>
|
||||
* @returns {Promise<TextChannel|GroupDMChannel|DMChannel>}
|
||||
*/
|
||||
acknowledge() {
|
||||
return this.client.rest.methods.ackTextMessage(this);
|
||||
}
|
||||
|
||||
_cacheMessage(message) {
|
||||
const maxSize = this.client.options.messageCacheMaxSize;
|
||||
if (maxSize === 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user