mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
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:
@@ -163,33 +163,33 @@ class ClientDataResolver {
|
||||
* Possible strings:
|
||||
* ```js
|
||||
* [
|
||||
* "CREATE_INSTANT_INVITE",
|
||||
* "KICK_MEMBERS",
|
||||
* "BAN_MEMBERS",
|
||||
* "ADMINISTRATOR",
|
||||
* "MANAGE_CHANNELS",
|
||||
* "MANAGE_GUILD",
|
||||
* "ADD_REACTIONS", // add reactions to messages
|
||||
* "READ_MESSAGES",
|
||||
* "SEND_MESSAGES",
|
||||
* "SEND_TTS_MESSAGES",
|
||||
* "MANAGE_MESSAGES",
|
||||
* "EMBED_LINKS",
|
||||
* "ATTACH_FILES",
|
||||
* "READ_MESSAGE_HISTORY",
|
||||
* "MENTION_EVERYONE",
|
||||
* "EXTERNAL_EMOJIS", // use external emojis
|
||||
* "CONNECT", // connect to voice
|
||||
* "SPEAK", // speak on voice
|
||||
* "MUTE_MEMBERS", // globally mute members on voice
|
||||
* "DEAFEN_MEMBERS", // globally deafen members on voice
|
||||
* "MOVE_MEMBERS", // move member's voice channels
|
||||
* "USE_VAD", // use voice activity detection
|
||||
* "CHANGE_NICKNAME",
|
||||
* "MANAGE_NICKNAMES", // change nicknames of others
|
||||
* "MANAGE_ROLES_OR_PERMISSIONS",
|
||||
* "MANAGE_WEBHOOKS",
|
||||
* "MANAGE_EMOJIS"
|
||||
* 'CREATE_INSTANT_INVITE',
|
||||
* 'KICK_MEMBERS',
|
||||
* 'BAN_MEMBERS',
|
||||
* 'ADMINISTRATOR',
|
||||
* 'MANAGE_CHANNELS',
|
||||
* 'MANAGE_GUILD',
|
||||
* 'ADD_REACTIONS', // add reactions to messages
|
||||
* 'READ_MESSAGES',
|
||||
* 'SEND_MESSAGES',
|
||||
* 'SEND_TTS_MESSAGES',
|
||||
* 'MANAGE_MESSAGES',
|
||||
* 'EMBED_LINKS',
|
||||
* 'ATTACH_FILES',
|
||||
* 'READ_MESSAGE_HISTORY',
|
||||
* 'MENTION_EVERYONE',
|
||||
* 'EXTERNAL_EMOJIS', // use external emojis
|
||||
* 'CONNECT', // connect to voice
|
||||
* 'SPEAK', // speak on voice
|
||||
* 'MUTE_MEMBERS', // globally mute members on voice
|
||||
* 'DEAFEN_MEMBERS', // globally deafen members on voice
|
||||
* 'MOVE_MEMBERS', // move member's voice channels
|
||||
* 'USE_VAD', // use voice activity detection
|
||||
* 'CHANGE_NICKNAME',
|
||||
* 'MANAGE_NICKNAMES', // change nicknames of others
|
||||
* 'MANAGE_ROLES_OR_PERMISSIONS',
|
||||
* 'MANAGE_WEBHOOKS',
|
||||
* 'MANAGE_EMOJIS'
|
||||
* ]
|
||||
* ```
|
||||
* @typedef {string|number} PermissionResolvable
|
||||
@@ -317,6 +317,67 @@ class ClientDataResolver {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be a Hex Literal, Hex String, Number, RGB Array, or one of the following
|
||||
* ```
|
||||
* [
|
||||
* 'DEFAULT',
|
||||
* 'AQUA',
|
||||
* 'GREEN',
|
||||
* 'BLUE',
|
||||
* 'PURPLE',
|
||||
* 'GOLD',
|
||||
* 'ORANGE',
|
||||
* 'RED',
|
||||
* 'GREY',
|
||||
* 'DARKER_GREY',
|
||||
* 'NAVY',
|
||||
* 'DARK_AQUA',
|
||||
* 'DARK_GREEN',
|
||||
* 'DARK_BLUE',
|
||||
* 'DARK_PURPLE',
|
||||
* 'DARK_GOLD',
|
||||
* 'DARK_ORANGE',
|
||||
* 'DARK_RED',
|
||||
* 'DARK_GREY',
|
||||
* 'LIGHT_GREY',
|
||||
* 'DARK_NAVY',
|
||||
* ]
|
||||
* ```
|
||||
* or something like
|
||||
* ```
|
||||
* [255, 0, 255]
|
||||
* ```
|
||||
* for purple
|
||||
* @typedef {String|number|Array} ColorResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {ColorResolvable} color Color to resolve
|
||||
* @returns {number} A color
|
||||
*/
|
||||
static resolveColor(color) {
|
||||
if (typeof color === 'string') {
|
||||
color = Constants.Colors[color] || parseInt(color.replace('#', ''), 16);
|
||||
} else if (color instanceof Array) {
|
||||
color = (color[0] << 16) + (color[1] << 8) + color[2];
|
||||
}
|
||||
if (color < 0 || color > 0xFFFFFF) {
|
||||
throw new RangeError('Color must be within the range 0 - 16777215 (0xFFFFFF).');
|
||||
} else if (color && isNaN(color)) {
|
||||
throw new TypeError('Unable to convert color to a number.');
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ColorResolvable} color Color to resolve
|
||||
* @returns {number} A color
|
||||
*/
|
||||
resolveColor(color) {
|
||||
return ClientDataResolver.resolveColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientDataResolver;
|
||||
|
||||
@@ -459,10 +459,7 @@ class RESTMethods {
|
||||
const data = {};
|
||||
data.name = _data.name || role.name;
|
||||
data.position = typeof _data.position !== 'undefined' ? _data.position : role.position;
|
||||
data.color = _data.color || role.color;
|
||||
if (typeof data.color === 'string' && data.color.startsWith('#')) {
|
||||
data.color = parseInt(data.color.replace('#', ''), 16);
|
||||
}
|
||||
data.color = this.client.resolver.resolveColor(_data.color || role.color);
|
||||
data.hoist = typeof _data.hoist !== 'undefined' ? _data.hoist : role.hoist;
|
||||
data.mentionable = typeof _data.mentionable !== 'undefined' ? _data.mentionable : role.mentionable;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user