Add support for notes (#860)

* Add support for notes

* Ensure consistency with notes from ready payload

* Add getter method for users

* Minor tweaks

* Update warning messages

* More minor fixes
This commit is contained in:
Programmix
2016-10-30 20:06:09 -07:00
committed by Schuyler Cebulskie
parent a673a97441
commit 6dc95cd084
9 changed files with 92 additions and 0 deletions

View File

@@ -36,6 +36,13 @@ class ClientUser extends User {
* @type {Collection<string, User>}
*/
this.blocked = new Collection();
/**
* A Collection of notes for the logged in user.
* <warn>This is only filled for user accounts, not bot accounts.</warn>
* @type {Collection<string, string>}
*/
this.notes = new Collection();
}
edit(data) {

View File

@@ -97,6 +97,16 @@ class User {
return Constants.Endpoints.avatar(this.id, this.avatar);
}
/**
* The note that is set for the user
* <warn>This is only available for user accounts.</warn>
* @type {?string}
* @readonly
*/
get note() {
return this.client.user.notes.get(this.id) || null;
}
/**
* Check whether the user is typing in a channel.
* @param {ChannelResolvable} channel The channel to check in
@@ -137,6 +147,7 @@ class User {
/**
* Sends a friend request to the user
* <warn>This is only available for user accounts.</warn>
* @returns {Promise<User>}
*/
addFriend() {
@@ -145,6 +156,7 @@ class User {
/**
* Removes the user from your friends
* <warn>This is only available for user accounts.</warn>
* @returns {Promise<User>}
*/
removeFriend() {
@@ -153,6 +165,7 @@ class User {
/**
* Blocks the user
* <warn>This is only available for user accounts.</warn>
* @returns {Promise<User>}
*/
block() {
@@ -161,6 +174,7 @@ class User {
/**
* Unblocks the user
* <warn>This is only available for user accounts.</warn>
* @returns {Promise<User>}
*/
unblock() {
@@ -175,6 +189,16 @@ class User {
return this.client.rest.methods.fetchUserProfile(this);
}
/**
* Sets a note for the user
* <warn>This is only available for user accounts.</warn>
* @param {string} note The note to set for the user
* @returns {Promise<User>}
*/
setNote(note) {
return this.client.rest.methods.setNote(this, note);
}
/**
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.