Quality of life changes (#968)

* + Added function to get a user's default avatar
+ Added HOST constant to Constants
+ Added assets endpoint
+ Added quality of life function to get a user's avatar or default avatar
+ Added quality of life function to get member's nickname or username

* * Fixed invocation of a getter.

* Fixed lint issue

* Made the API constant use the HOST constant for DRY-ness
Changed DOC comment to be more descriptive

* Update GuildMember.js
This commit is contained in:
Cole
2016-12-12 21:34:19 -06:00
committed by Schuyler Cebulskie
parent 3193df792e
commit 586d652c16
3 changed files with 40 additions and 1 deletions

View File

@@ -182,6 +182,15 @@ class GuildMember {
return this.user.id;
}
/**
* The nickname of the member, or their username if they don't have one
* @type {string}
* @readonly
*/
get displayName() {
return this.nickname || this.user.username;
}
/**
* The overall set of permissions for the guild member, taking only roles into account
* @type {EvaluatedPermissions}

View File

@@ -104,6 +104,26 @@ class User {
return Constants.Endpoints.avatar(this.id, this.avatar);
}
/**
* A link to the user's default avatar
* @type {string}
* @readonly
*/
get defaultAvatarURL() {
let defaultAvatars = Object.values(Constants.DefaultAvatars);
let defaultAvatar = this.discriminator % defaultAvatars.length;
return Constants.endpoints.assets(`${defaultAvatars[defaultAvatar]}.png`);
}
/**
* A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned
* @type {string}
* @readonly
*/
get displayAvatarURL() {
return this.avatarURL || this.defaultAvatarURL;
}
/**
* The note that is set for the user
* <warn>This is only available when using a user account.</warn>

View File

@@ -71,7 +71,8 @@ exports.Errors = {
};
const PROTOCOL_VERSION = exports.PROTOCOL_VERSION = 6;
const API = exports.API = `https://discordapp.com/api/v${PROTOCOL_VERSION}`;
const HOST = exports.HOST = `https://discordapp.com`;
const API = exports.API = `${HOST}/api/v${PROTOCOL_VERSION}`;
const Endpoints = exports.Endpoints = {
// general
login: `${API}/auth/login`,
@@ -80,6 +81,7 @@ const Endpoints = exports.Endpoints = {
botGateway: `${API}/gateway/bot`,
invite: (id) => `${API}/invite/${id}`,
inviteLink: (id) => `https://discord.gg/${id}`,
assets: (asset) => `${HOST}/assets/${asset}`,
CDN: 'https://cdn.discordapp.com',
// users
@@ -311,6 +313,14 @@ exports.MessageTypes = {
6: 'PINS_ADD',
};
exports.DefaultAvatars = {
BLURPLE: '6debd47ed13483642cf09e832ed0bc1b',
GREY: '322c936a8c8be1b803cd94861bdfa868',
GREEN: 'dd4dbc0016779df1378e7812eabaa04d',
ORANGE: '0e291f67c9274a1abdddeb3fd919cbaa',
RED: '1cbd08c76f8af6dddce02c5138971129',
};
const PermissionFlags = exports.PermissionFlags = {
CREATE_INSTANT_INVITE: 1 << 0,
KICK_MEMBERS: 1 << 1,