feat: dynamic property for ImageURLOptions (#3530)

* Added dynamic property to ImageURLOptions

* fixes

* order

* typings fix

* made dynamic false by default

* add curly spaces
This commit is contained in:
Tenpi
2020-01-13 09:32:29 -05:00
committed by Amish Shah
parent 400cb56358
commit 8014ddcd1c
4 changed files with 22 additions and 20 deletions

View File

@@ -433,9 +433,9 @@ class Guild extends Base {
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
iconURL({ format, size } = {}) {
iconURL({ format, size, dynamic } = {}) {
if (!this.icon) return null;
return this.client.rest.cdn.Icon(this.id, this.icon, format, size);
return this.client.rest.cdn.Icon(this.id, this.icon, format, size, dynamic);
}
/**

View File

@@ -140,9 +140,9 @@ class User extends Base {
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
avatarURL({ format, size } = {}) {
avatarURL({ format, size, dynamic } = {}) {
if (!this.avatar) return null;
return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size);
return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size, dynamic);
}
/**

View File

@@ -119,7 +119,9 @@ function makeImageUrl(root, { format = 'webp', size } = {}) {
* Options for Image URLs.
* @typedef {Object} ImageURLOptions
* @property {string} [format] One of `webp`, `png`, `jpg`, `gif`. If no format is provided,
* it will be `gif` for animated avatars or otherwise `webp`
* defaults to `webp`.
* @property {boolean} [dynamic] If true, the format will dynamically change to `gif` for
* animated avatars; the default is false.
* @property {number} [size] One of `16`, `32`, `64`, `128`, `256`, `512`, `1024`, `2048`
*/
@@ -129,14 +131,14 @@ exports.Endpoints = {
Emoji: (emojiID, format = 'png') => `${root}/emojis/${emojiID}.${format}`,
Asset: name => `${root}/assets/${name}`,
DefaultAvatar: discriminator => `${root}/embed/avatars/${discriminator}.png`,
Avatar: (userID, hash, format = 'default', size) => {
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
Avatar: (userID, hash, format = 'webp', size, dynamic = false) => {
if (dynamic) format = hash.startsWith('a_') ? 'gif' : format;
return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size });
},
Banner: (guildID, hash, format = 'webp', size) =>
makeImageUrl(`${root}/banners/${guildID}/${hash}`, { format, size }),
Icon: (guildID, hash, format = 'default', size) => {
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
Icon: (guildID, hash, format = 'webp', size, dynamic = false) => {
if (dynamic) format = hash.startsWith('a_') ? 'gif' : format;
return makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size });
},
AppIcon: (clientID, hash, { format = 'webp', size } = {}) =>