mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
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:
@@ -433,9 +433,9 @@ class Guild extends Base {
|
|||||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||||
* @returns {?string}
|
* @returns {?string}
|
||||||
*/
|
*/
|
||||||
iconURL({ format, size } = {}) {
|
iconURL({ format, size, dynamic } = {}) {
|
||||||
if (!this.icon) return null;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -140,9 +140,9 @@ class User extends Base {
|
|||||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||||
* @returns {?string}
|
* @returns {?string}
|
||||||
*/
|
*/
|
||||||
avatarURL({ format, size } = {}) {
|
avatarURL({ format, size, dynamic } = {}) {
|
||||||
if (!this.avatar) return null;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ function makeImageUrl(root, { format = 'webp', size } = {}) {
|
|||||||
* Options for Image URLs.
|
* Options for Image URLs.
|
||||||
* @typedef {Object} ImageURLOptions
|
* @typedef {Object} ImageURLOptions
|
||||||
* @property {string} [format] One of `webp`, `png`, `jpg`, `gif`. If no format is provided,
|
* @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`
|
* @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}`,
|
Emoji: (emojiID, format = 'png') => `${root}/emojis/${emojiID}.${format}`,
|
||||||
Asset: name => `${root}/assets/${name}`,
|
Asset: name => `${root}/assets/${name}`,
|
||||||
DefaultAvatar: discriminator => `${root}/embed/avatars/${discriminator}.png`,
|
DefaultAvatar: discriminator => `${root}/embed/avatars/${discriminator}.png`,
|
||||||
Avatar: (userID, hash, format = 'default', size) => {
|
Avatar: (userID, hash, format = 'webp', size, dynamic = false) => {
|
||||||
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
|
if (dynamic) format = hash.startsWith('a_') ? 'gif' : format;
|
||||||
return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size });
|
return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size });
|
||||||
},
|
},
|
||||||
Banner: (guildID, hash, format = 'webp', size) =>
|
Banner: (guildID, hash, format = 'webp', size) =>
|
||||||
makeImageUrl(`${root}/banners/${guildID}/${hash}`, { format, size }),
|
makeImageUrl(`${root}/banners/${guildID}/${hash}`, { format, size }),
|
||||||
Icon: (guildID, hash, format = 'default', size) => {
|
Icon: (guildID, hash, format = 'webp', size, dynamic = false) => {
|
||||||
if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp';
|
if (dynamic) format = hash.startsWith('a_') ? 'gif' : format;
|
||||||
return makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size });
|
return makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size });
|
||||||
},
|
},
|
||||||
AppIcon: (clientID, hash, { format = 'webp', size } = {}) =>
|
AppIcon: (clientID, hash, { format = 'webp', size } = {}) =>
|
||||||
|
|||||||
22
typings/index.d.ts
vendored
22
typings/index.d.ts
vendored
@@ -272,9 +272,9 @@ declare module 'discord.js' {
|
|||||||
public name: string;
|
public name: string;
|
||||||
public owner: User | Team | null;
|
public owner: User | Team | null;
|
||||||
public rpcOrigins: string[];
|
public rpcOrigins: string[];
|
||||||
public coverImage(options?: AvatarOptions): string;
|
public coverImage(options?: ImageURLOptions): string;
|
||||||
public fetchAssets(): Promise<ClientApplicationAsset>;
|
public fetchAssets(): Promise<ClientApplicationAsset>;
|
||||||
public iconURL(options?: AvatarOptions): string;
|
public iconURL(options?: ImageURLOptions): string;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ declare module 'discord.js' {
|
|||||||
public readonly createdAt: Date;
|
public readonly createdAt: Date;
|
||||||
public readonly createdTimestamp: number;
|
public readonly createdTimestamp: number;
|
||||||
|
|
||||||
public iconURL(options?: AvatarOptions): string;
|
public iconURL(options?: ImageURLOptions): string;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
}
|
}
|
||||||
@@ -726,7 +726,7 @@ declare module 'discord.js' {
|
|||||||
public widgetChannelID: Snowflake | null;
|
public widgetChannelID: Snowflake | null;
|
||||||
public widgetEnabled: boolean | null;
|
public widgetEnabled: boolean | null;
|
||||||
public addMember(user: UserResolvable, options: AddGuildMemberOptions): Promise<GuildMember>;
|
public addMember(user: UserResolvable, options: AddGuildMemberOptions): Promise<GuildMember>;
|
||||||
public bannerURL(options?: AvatarOptions): string | null;
|
public bannerURL(options?: ImageURLOptions): string | null;
|
||||||
public createIntegration(data: IntegrationData, reason?: string): Promise<Guild>;
|
public createIntegration(data: IntegrationData, reason?: string): Promise<Guild>;
|
||||||
public delete(): Promise<Guild>;
|
public delete(): Promise<Guild>;
|
||||||
public edit(data: GuildEditData, reason?: string): Promise<Guild>;
|
public edit(data: GuildEditData, reason?: string): Promise<Guild>;
|
||||||
@@ -740,7 +740,7 @@ declare module 'discord.js' {
|
|||||||
public fetchVanityCode(): Promise<string>;
|
public fetchVanityCode(): Promise<string>;
|
||||||
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
|
||||||
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
|
||||||
public iconURL(options?: AvatarOptions): string | null;
|
public iconURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
|
||||||
public leave(): Promise<Guild>;
|
public leave(): Promise<Guild>;
|
||||||
public member(user: UserResolvable): GuildMember | null;
|
public member(user: UserResolvable): GuildMember | null;
|
||||||
public setAFKChannel(afkChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
public setAFKChannel(afkChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
@@ -759,7 +759,7 @@ declare module 'discord.js' {
|
|||||||
public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
|
||||||
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
|
||||||
public setVerificationLevel(verificationLevel: number, reason?: string): Promise<Guild>;
|
public setVerificationLevel(verificationLevel: number, reason?: string): Promise<Guild>;
|
||||||
public splashURL(options?: AvatarOptions): string | null;
|
public splashURL(options?: ImageURLOptions): string | null;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
}
|
}
|
||||||
@@ -1189,8 +1189,8 @@ declare module 'discord.js' {
|
|||||||
public largeText: string | null;
|
public largeText: string | null;
|
||||||
public smallImage: Snowflake | null;
|
public smallImage: Snowflake | null;
|
||||||
public smallText: string | null;
|
public smallText: string | null;
|
||||||
public largeImageURL(options: AvatarOptions): string | null;
|
public largeImageURL(options: ImageURLOptions): string | null;
|
||||||
public smallImageURL(options: AvatarOptions): string | null;
|
public smallImageURL(options: ImageURLOptions): string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Role extends Base {
|
export class Role extends Base {
|
||||||
@@ -1421,10 +1421,10 @@ declare module 'discord.js' {
|
|||||||
public system?: boolean;
|
public system?: boolean;
|
||||||
public readonly tag: string;
|
public readonly tag: string;
|
||||||
public username: string;
|
public username: string;
|
||||||
public avatarURL(options?: AvatarOptions): string | null;
|
public avatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null;
|
||||||
public createDM(): Promise<DMChannel>;
|
public createDM(): Promise<DMChannel>;
|
||||||
public deleteDM(): Promise<DMChannel>;
|
public deleteDM(): Promise<DMChannel>;
|
||||||
public displayAvatarURL(options?: AvatarOptions): string;
|
public displayAvatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string;
|
||||||
public equals(user: User): boolean;
|
public equals(user: User): boolean;
|
||||||
public fetch(): Promise<User>;
|
public fetch(): Promise<User>;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
@@ -2011,7 +2011,7 @@ declare module 'discord.js' {
|
|||||||
new?: any;
|
new?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AvatarOptions {
|
interface ImageURLOptions {
|
||||||
format?: ImageExt;
|
format?: ImageExt;
|
||||||
size?: ImageSize;
|
size?: ImageSize;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user