From b79a91b3a9b2a7e23bad978eeb785818d3579aaf Mon Sep 17 00:00:00 2001 From: Slamakans Date: Sat, 10 Dec 2016 04:09:55 +0100 Subject: [PATCH] new errors for richembed yay (#966) * Update faq.md (#949) * fix docs * Revert "fixed typo in documentation" (#950) * new errors for richembed yay Simplified the parsing for color arrays. Throwing some errors on values that would result in Bad Requests. Changed setAuthor and setFooter's icon parameter to icon_url to match the embed object's property name. Changed the docs for setFooter to reflect that icon_url is optional. * changed docs instead of arg names * capitalization --- src/structures/RichEmbed.js | 11 ++++++++--- test/random.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/structures/RichEmbed.js b/src/structures/RichEmbed.js index a62e58833..c135a6219 100644 --- a/src/structures/RichEmbed.js +++ b/src/structures/RichEmbed.js @@ -104,10 +104,15 @@ class RichEmbed { */ setColor(color) { if (color instanceof Array) { - color = parseInt(((1 << 24) + (color[0] << 16) + (color[1] << 8) + color[2]).toString(16).slice(1), 16); + color = (color[0] << 16) + (color[1] << 8) + color[2]; } else if (typeof color === 'string' && color.startsWith('#')) { color = parseInt(color.replace('#', ''), 16); } + if (color < 0 || color > 0xFFFFFF) { + throw new RangeError('RichEmbed color must be within the range 0 - 16777215 (0xFFFFFF).'); + } else if (color && isNaN(parseInt(color))) { + throw new TypeError('Unable to convert RichEmbed color to a number.'); + } this.color = color; return this; } @@ -115,7 +120,7 @@ class RichEmbed { /** * Sets the author of this embed * @param {string} name The name of the author - * @param {string} [icon] The icon of the author + * @param {string} [icon] The icon URL of the author * @returns {RichEmbed} This embed */ setAuthor(name, icon) { @@ -171,7 +176,7 @@ class RichEmbed { /** * Sets the footer of this embed * @param {string} text The text of the footer - * @param {string} icon The icon of the footer + * @param {string} [icon] The icon URL of the footer * @returns {RichEmbed} This embed */ setFooter(text, icon) { diff --git a/test/random.js b/test/random.js index f3af346a7..d6c761ea5 100644 --- a/test/random.js +++ b/test/random.js @@ -13,7 +13,7 @@ client.login(token).then(atoken => console.log('logged in with token ' + atoken) client.ws.on('send', console.log); client.on('ready', () => { - console.log('ready!'); + console.log('ready'); }); client.on('userUpdate', (o, n) => {