Role hex stuff

This commit is contained in:
Amish Shah
2016-08-27 17:46:08 +01:00
parent f2708dd26f
commit 50c6fa3433
3 changed files with 20 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -354,6 +354,10 @@ class RESTMethods {
data.position = _data.position || role.position;
data.color = _data.color || role.color;
if (data.color.startsWith('#')) {
data.color = parseInt(data.color.replace('#', ''), 16);
}
if (typeof _data.hoist !== 'undefined') {
data.hoist = _data.hoist;
} else {

View File

@@ -114,11 +114,11 @@ class Role {
/**
* Set a new color for the role
* @param {Number} color the new color for the role
* @param {Number|String} color the new color for the role, either a hex string or a base 10 number
* @returns {Promise<Role, Error>}
* @example
* // set the color of a role
* role.setColor(parseInt('FF0000', 16))
* role.setColor('#FF0000')
* .then(r => console.log(`Set color of role ${r}`))
* .catch(console.log);
*/
@@ -222,6 +222,19 @@ class Role {
toString() {
return `<@&${this.id}>`;
}
/**
* The hexadecimal version of the role color, with a leading hashtag.
* @type {String}
* @readonly
*/
get hexColor() {
let col = (this.color).toString(16);
while (col.length < 6) {
col = `0${col}`;
}
return `#${col}`;
}
}
module.exports = Role;