Clean up reactions, add remove all reactions (#890)

* Clean up reactions, add remove all reactions

* Reorganize reactions

* Re-add Gawdl3y's precious little inline

* Update Message.js
This commit is contained in:
Programmix
2016-11-12 23:29:26 -08:00
committed by Schuyler Cebulskie
parent a359f344d8
commit 5ed8098af8
9 changed files with 97 additions and 26 deletions

View File

@@ -26,7 +26,7 @@ class Message {
if (data) this.setup(data);
}
setup(data) {
setup(data) { // eslint-disable-line complexity
/**
* The ID of the message (unique in the channel it was sent)
* @type {string}
@@ -389,20 +389,23 @@ class Message {
}
/**
* Adds a reaction to the message
* @param {Emoji|ReactionEmoji|string} emoji Emoji to react with
* Add a reaction to the message
* @param {string|Emoji|ReactionEmoji} emoji Emoji to react with
* @returns {Promise<MessageReaction>}
*/
react(emoji) {
if (emoji.identifier) {
emoji = emoji.identifier;
} else if (typeof emoji === 'string') {
if (!emoji.includes('%')) emoji = encodeURIComponent(emoji);
} else {
return Promise.reject('The emoji must be a string or an Emoji/ReactionEmoji.');
}
emoji = this.client.resolver.resolveEmojiIdentifier(emoji);
if (!emoji) throw new TypeError('Emoji must be a string or Emoji/ReactionEmoji');
return this.client.rest.methods.addMessageReaction(this.channel.id, this.id, emoji);
return this.client.rest.methods.addMessageReaction(this, emoji);
}
/**
* Remove all reactions from a message
* @returns {Promise<Message>}
*/
clearReactions() {
return this.client.rest.methods.removeMessageReactions(this);
}
/**
@@ -523,6 +526,10 @@ class Message {
}
return null;
}
_clearReactions() {
this.reactions.clear();
}
}
module.exports = Message;