mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(MessageReaction): inaccurate count
also works towards async rewrite goal fixes #2404
This commit is contained in:
@@ -45,7 +45,7 @@ class MessageStore extends DataStore {
|
||||
* .catch(console.error);
|
||||
* @example
|
||||
* // Get messages
|
||||
* channel.messages.fetch({limit: 10})
|
||||
* channel.messages.fetch({ limit: 10 })
|
||||
* .then(messages => console.log(`Received ${messages.size} messages`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
@@ -67,26 +67,22 @@ class MessageStore extends DataStore {
|
||||
});
|
||||
}
|
||||
|
||||
_fetchId(messageID) {
|
||||
async _fetchId(messageID) {
|
||||
if (!this.client.user.bot) {
|
||||
return this._fetchMany({ limit: 1, around: messageID })
|
||||
.then(messages => {
|
||||
const msg = messages.get(messageID);
|
||||
if (!msg) throw new Error('MESSAGE_MISSING');
|
||||
return msg;
|
||||
});
|
||||
const messages = await this._fetchMany({ limit: 1, around: messageID });
|
||||
const msg = messages.get(messageID);
|
||||
if (!msg) throw new Error('MESSAGE_MISSING');
|
||||
return msg;
|
||||
}
|
||||
return this.client.api.channels[this.channel.id].messages[messageID].get()
|
||||
.then(data => this.add(data));
|
||||
const data = await this.client.api.channels[this.channel.id].messages[messageID].get();
|
||||
return this.add(data);
|
||||
}
|
||||
|
||||
_fetchMany(options = {}) {
|
||||
return this.client.api.channels[this.channel.id].messages.get({ query: options })
|
||||
.then(data => {
|
||||
const messages = new Collection();
|
||||
for (const message of data) messages.set(message.id, this.add(message));
|
||||
return messages;
|
||||
});
|
||||
async _fetchMany(options = {}) {
|
||||
const data = await this.client.api.channels[this.channel.id].messages.get({ query: options });
|
||||
const messages = new Collection();
|
||||
for (const message of data) messages.set(message.id, this.add(message));
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -62,21 +62,17 @@ class MessageReaction {
|
||||
}
|
||||
|
||||
_add(user) {
|
||||
if (!this.users.has(user.id)) {
|
||||
this.users.set(user.id, user);
|
||||
if (!this.me || user.id !== this.message.client.user.id) this.count++;
|
||||
}
|
||||
this.users.set(user.id, user);
|
||||
if (!this.me || user.id !== this.message.client.user.id || this.count === 0) this.count++;
|
||||
if (!this.me) this.me = user.id === this.message.client.user.id;
|
||||
}
|
||||
|
||||
_remove(user) {
|
||||
if (this.users.has(user.id)) {
|
||||
this.users.delete(user.id);
|
||||
this.count--;
|
||||
if (user.id === this.message.client.user.id) this.me = false;
|
||||
if (this.count <= 0) {
|
||||
this.message.reactions.remove(this.emoji.id || this.emoji.name);
|
||||
}
|
||||
this.users.delete(user.id);
|
||||
if (!this.me || user.id !== this.message.client.user.id) this.count--;
|
||||
if (user.id === this.message.client.user.id) this.me = false;
|
||||
if (this.count <= 0) {
|
||||
this.message.reactions.remove(this.emoji.id || this.emoji.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user