THIS IS A VALID URL BTCICH

This commit is contained in:
Emily 2020-10-28 13:03:09 +11:00
parent 19cb9be261
commit 7bb31fd82d

View file

@ -1,6 +1,5 @@
const colours = require('../constants/colours.json'); const colours = require('../constants/colours.json');
const HEX_REGEX = /^#?([a-fA-F0-9]{6})$/; const HEX_REGEX = /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
const URL_REGEX = /^http(s)?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/;
class RichEmbed { class RichEmbed {
/** /**
@ -44,7 +43,6 @@ class RichEmbed {
*/ */
setURL (url) { setURL (url) {
if (typeof url !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof url}'`); if (typeof url !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof url}'`);
if (!URL_REGEX.test(url)) throw new Error('Not a well formed URL');
this.url = url; this.url = url;
return this; return this;
} }
@ -89,7 +87,6 @@ class RichEmbed {
if (iconURL !== undefined) { if (iconURL !== undefined) {
if (typeof iconURL !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof iconURL}'`); if (typeof iconURL !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof iconURL}'`);
if (!iconURL.startsWith('attachment://') && !URL_REGEX.test(iconURL)) throw new Error('Not a well formed URL');
this.footer.icon_url = iconURL; this.footer.icon_url = iconURL;
} }
@ -110,7 +107,6 @@ class RichEmbed {
*/ */
setThumbnail (thumbnailURL) { setThumbnail (thumbnailURL) {
if (typeof thumbnailURL !== 'string') throw new TypeError(`Expected type 'string', received type ${typeof thumbnailURL}`); if (typeof thumbnailURL !== 'string') throw new TypeError(`Expected type 'string', received type ${typeof thumbnailURL}`);
if (!thumbnailURL.startsWith('attachment://') && !URL_REGEX.test(thumbnailURL)) throw new Error('Not a well formed URL');
this.thumbnail = { url: thumbnailURL }; this.thumbnail = { url: thumbnailURL };
return this; return this;
} }
@ -127,13 +123,11 @@ class RichEmbed {
if (url !== undefined) { if (url !== undefined) {
if (typeof url !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof url}'`); if (typeof url !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof url}'`);
if (!URL_REGEX.test(url)) throw new Error('Not a well formed URL');
this.author.url = url; this.author.url = url;
} }
if (iconURL !== undefined) { if (iconURL !== undefined) {
if (typeof iconURL !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof iconURL}'`); if (typeof iconURL !== 'string') throw new TypeError(`Expected type 'string', received type '${typeof iconURL}'`);
if (!iconURL.startsWith('attachment://') && !URL_REGEX.test(iconURL)) throw new Error('Not a well formed URL');
this.author.icon_url = iconURL; this.author.icon_url = iconURL;
} }