add color resolvable, and color constants from the client (#1080)

* add color resolvable, and color constants from the client

* fix up docs

* Update ClientDataResolver.js

* add easter eggs

* Update ClientDataResolver.js

* Update RESTMethods.js
This commit is contained in:
Gus Caplan
2017-01-12 12:43:22 -06:00
committed by Amish Shah
parent a3091f5262
commit 0d4eab8d24
5 changed files with 122 additions and 47 deletions

View File

@@ -1,3 +1,5 @@
const ClientDataResolver = require('../client/ClientDataResolver');
/**
* A rich embed to be sent with a message with a fluent interface for creation
* @param {Object} [data] Data to set in the rich embed
@@ -101,24 +103,11 @@ class RichEmbed {
/**
* Sets the color of this embed
* @param {string|number|number[]} color The color to set
* @param {ColorResolvable} color The color to set
* @returns {RichEmbed} This embed
*/
setColor(color) {
let radix = 10;
if (color instanceof Array) {
color = (color[0] << 16) + (color[1] << 8) + color[2];
} else if (typeof color === 'string' && color.startsWith('#')) {
radix = 16;
color = color.replace('#', '');
}
color = parseInt(color, radix);
if (color < 0 || color > 0xFFFFFF) {
throw new RangeError('RichEmbed color must be within the range 0 - 16777215 (0xFFFFFF).');
} else if (color && isNaN(color)) {
throw new TypeError('Unable to convert RichEmbed color to a number.');
}
this.color = color;
this.color = ClientDataResolver.resolveColor(color);
return this;
}

View File

@@ -180,7 +180,7 @@ class Role {
* The data for a role
* @typedef {Object} RoleData
* @property {string} [name] The name of the role
* @property {number|string} [color] The color of the role, either a hex string or a base 10 number
* @property {ColorResolvable} [color] The color of the role, either a hex string or a base 10 number
* @property {boolean} [hoist] Whether or not the role should be hoisted
* @property {number} [position] The position of the role
* @property {string[]} [permissions] The permissions of the role