Skip to content

Commit

Permalink
feat: support new username system (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ckPro authored Jun 15, 2023
1 parent e01cf7c commit 5af7147
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 20 deletions.
6 changes: 5 additions & 1 deletion deno/payloads/v10/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export interface APIUser {
*/
username: string;
/**
* The user's 4-digit discord-tag
* The user's Discord-tag
*/
discriminator: string;
/**
* The user's display name, if it is set. For bots, this is the application name
*/
global_name: string | null;
/**
* The user's avatar hash
*
Expand Down
6 changes: 5 additions & 1 deletion deno/payloads/v9/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export interface APIUser {
*/
username: string;
/**
* The user's 4-digit discord-tag
* The user's Discord-tag
*/
discriminator: string;
/**
* The user's display name, if it is set. For bots, this is the application name
*/
global_name: string | null;
/**
* The user's avatar hash
*
Expand Down
10 changes: 6 additions & 4 deletions deno/rest/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,16 @@ export const CDNRoutes = {

/**
* Route for:
* - GET `/embed/avatars/{user.discriminator % 5}.png`
* - GET `/embed/avatars/{index}.png`
*
* The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2)
* The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord).
* For users on the new username system, `index` will be `(user.id >> 22) % 6`.
* For users on the legacy username system, `index` will be `user.discriminator % 5`.
*
* This route supports the extension: PNG
*/
defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) {
return `/embed/avatars/${userDiscriminator}.png` as const;
defaultUserAvatar(index: DefaultUserAvatarAssets) {
return `/embed/avatars/${index}.png` as const;
},

/**
Expand Down
10 changes: 6 additions & 4 deletions deno/rest/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,16 @@ export const CDNRoutes = {

/**
* Route for:
* - GET `/embed/avatars/{user.discriminator % 5}.png`
* - GET `/embed/avatars/{index}.png`
*
* The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2)
* The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord).
* For users on the new username system, `index` will be `(user.id >> 22) % 6`.
* For users on the legacy username system, `index` will be `user.discriminator % 5`.
*
* This route supports the extension: PNG
*/
defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) {
return `/embed/avatars/${userDiscriminator}.png` as const;
defaultUserAvatar(index: DefaultUserAvatarAssets) {
return `/embed/avatars/${index}.png` as const;
},

/**
Expand Down
6 changes: 5 additions & 1 deletion payloads/v10/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export interface APIUser {
*/
username: string;
/**
* The user's 4-digit discord-tag
* The user's Discord-tag
*/
discriminator: string;
/**
* The user's display name, if it is set. For bots, this is the application name
*/
global_name: string | null;
/**
* The user's avatar hash
*
Expand Down
6 changes: 5 additions & 1 deletion payloads/v9/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export interface APIUser {
*/
username: string;
/**
* The user's 4-digit discord-tag
* The user's Discord-tag
*/
discriminator: string;
/**
* The user's display name, if it is set. For bots, this is the application name
*/
global_name: string | null;
/**
* The user's avatar hash
*
Expand Down
10 changes: 6 additions & 4 deletions rest/v10/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,16 @@ export const CDNRoutes = {

/**
* Route for:
* - GET `/embed/avatars/{user.discriminator % 5}.png`
* - GET `/embed/avatars/{index}.png`
*
* The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2)
* The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord).
* For users on the new username system, `index` will be `(user.id >> 22) % 6`.
* For users on the legacy username system, `index` will be `user.discriminator % 5`.
*
* This route supports the extension: PNG
*/
defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) {
return `/embed/avatars/${userDiscriminator}.png` as const;
defaultUserAvatar(index: DefaultUserAvatarAssets) {
return `/embed/avatars/${index}.png` as const;
},

/**
Expand Down
10 changes: 6 additions & 4 deletions rest/v9/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,16 @@ export const CDNRoutes = {

/**
* Route for:
* - GET `/embed/avatars/{user.discriminator % 5}.png`
* - GET `/embed/avatars/{index}.png`
*
* The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2)
* The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord).
* For users on the new username system, `index` will be `(user.id >> 22) % 6`.
* For users on the legacy username system, `index` will be `user.discriminator % 5`.
*
* This route supports the extension: PNG
*/
defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) {
return `/embed/avatars/${userDiscriminator}.png` as const;
defaultUserAvatar(index: DefaultUserAvatarAssets) {
return `/embed/avatars/${index}.png` as const;
},

/**
Expand Down

1 comment on commit 5af7147

@vercel
Copy link

@vercel vercel bot commented on 5af7147 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.