feat: new changes to avatarURL method over GuildMember & User (#194)

* fix(GuildMember#avatarURL): use dynamic response, to return gif avatar if the avatar is a gif

* fix(User#avatarURL): dynamic response, if avatar is a gif return gif

* fix(avatarURL): specified extension is being overriden by gif if avatar starts with a_

* chore: change in parseCDNURL so it's effective for almost everything

* chore: re-add GuildMember#dynamicAvatarURL

* fix(GuildEmoji#create): returns void while it should return the resolve promise of the created emoji

---------

Co-authored-by: NotAditya69 <90441096+NotAditya69@users.noreply.github.com>
This commit is contained in:
Xeno 2024-05-31 00:47:59 +05:30 committed by GitHub
parent 42b682d8fd
commit 00640bfda7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 1 deletions

View File

@ -73,6 +73,7 @@ export interface CDNUrlOptions extends BaseCDNUrlOptions {
export function parseCDNURL(route: string, options: CDNUrlOptions = {}) {
if (options.forceStatic && route.includes('a_')) options.extension = 'png';
if (!options.extension && route.includes('a_')) options.extension = 'gif';
const url = new URL(`${route}.${options.extension || 'png'}`);

View File

@ -39,7 +39,9 @@ export class EmojiShorter extends BaseShorter {
const emoji = await this.client.proxy.guilds(guildId).emojis.post({
body: bodyResolved,
});
await this.client.cache.emojis?.setIfNI('GuildEmojisAndStickers', emoji.id!, guildId, emoji);
return new GuildEmoji(this.client, emoji, guildId);
}

View File

@ -177,7 +177,11 @@ export class GuildMember extends BaseGuildMember {
}
avatarURL(options?: ImageOptions) {
return this.user.avatarURL(options);
if (!this.avatar) {
return null;
}
return this.rest.cdn.guilds(this.guildId).users(this.id).avatars(this.avatar).get(options);
}
dynamicAvatarURL(options?: ImageOptions) {

View File

@ -37,6 +37,7 @@ export class User extends DiscordBase<APIUser> {
if (!this.avatar) {
return this.rest.cdn.embed.avatars.get(calculateUserDefaultAvatarIndex(this.id, this.discriminator));
}
return this.rest.cdn.avatars(this.id).get(this.avatar, options);
}