Skip to content

Commit

Permalink
Revert "refactor(Messages): Improve ColorConvert error (discordjs#1…
Browse files Browse the repository at this point in the history
…0108)"

This reverts commit fc1f8ae.
  • Loading branch information
IRONM00N committed Feb 2, 2024
1 parent 5a4b40d commit 2772c9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Messages = {
`Calculated invalid shard ${shard} for guild ${guild} with ${count} shards.`,

[DjsErrorCodes.ColorRange]: 'Color must be within the range 0 - 16777215 (0xFFFFFF).',
[DjsErrorCodes.ColorConvert]: color => `Unable to convert "${color}" to a number.`,
[DjsErrorCodes.ColorConvert]: 'Unable to convert color to a number.',

[DjsErrorCodes.InviteOptionsMissingChannel]:
'A valid guild channel must be provided when GuildScheduledEvent is EXTERNAL.',
Expand Down
17 changes: 5 additions & 12 deletions packages/discord.js/src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,26 +278,19 @@ function verifyString(
* @returns {number} A color
*/
function resolveColor(color) {
let resolvedColor;

if (typeof color === 'string') {
if (color === 'Random') return Math.floor(Math.random() * (0xffffff + 1));
if (color === 'Default') return 0;
if (/^#?[\da-f]{6}$/i.test(color)) return parseInt(color.replace('#', ''), 16);
resolvedColor = Colors[color];
color = Colors[color];
} else if (Array.isArray(color)) {
resolvedColor = (color[0] << 16) + (color[1] << 8) + color[2];
}

if (resolvedColor < 0 || resolvedColor > 0xffffff) {
throw new DiscordjsRangeError(ErrorCodes.ColorRange);
color = (color[0] << 16) + (color[1] << 8) + color[2];
}

if (typeof resolvedColor !== 'number' || Number.isNaN(resolvedColor)) {
throw new DiscordjsTypeError(ErrorCodes.ColorConvert, color);
}
if (color < 0 || color > 0xffffff) throw new DiscordjsRangeError(ErrorCodes.ColorRange);
if (typeof color !== 'number' || Number.isNaN(color)) throw new DiscordjsTypeError(ErrorCodes.ColorConvert);

return resolvedColor;
return color;
}

/**
Expand Down

0 comments on commit 2772c9e

Please sign in to comment.