feat: support user guilds (#10962)

* feat: support user guilds

* chore: add cdn test

* chore: suggested changes

* refactor: move to user primary guild to its own class

* docs: update description of `badgeHash` parameter

* chore: export UserPrimaryGuild

* refactor: revert to no `UserPrimaryGuild`

* fix: use key in data

* fix: both `in` and is truthy check

* docs: remove `-`

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Danial Raza
2025-07-16 09:26:00 +02:00
committed by GitHub
parent d03cacbde4
commit 9ff04820b3
4 changed files with 95 additions and 20 deletions

View File

@@ -134,8 +134,11 @@ test('soundboardSound', () => {
expect(cdn.soundboardSound(id)).toEqual(`${baseCDN}/soundboard-sounds/${id}`);
});
test('guildTagBadge', () => {
expect(cdn.guildTagBadge(id, hash)).toEqual(`${baseCDN}/guild-tag-badges/${id}/${hash}.webp`);
});
test('makeURL throws on invalid size', () => {
// @ts-expect-error: Invalid size
expect(() => cdn.avatar(id, animatedHash, { size: 5 })).toThrow(RangeError);
});

View File

@@ -340,6 +340,17 @@ export class CDN {
return `${this.cdn}${CDNRoutes.soundboardSound(soundId)}`;
}
/**
* Generates a URL for a guild tag badge.
*
* @param guildId - The guild id
* @param badgeHash - The hash of the badge
* @param options - Optional options for the badge
*/
public guildTagBadge(guildId: string, badgeHash: string, options?: Readonly<BaseImageURLOptions>): string {
return this.makeURL(`/guild-tag-badges/${guildId}/${badgeHash}`, options);
}
/**
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
*