Skip to content

Commit

Permalink
feat: globalName and avatarDecoration
Browse files Browse the repository at this point in the history
  • Loading branch information
liy77 committed Feb 4, 2024
1 parent 94941e9 commit 9d7472e
Show file tree
Hide file tree
Showing 5 changed files with 1,165 additions and 2,737 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
"build": "node scripts/build.js"
},
"devDependencies": {
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"@types/node": "^18.19.14",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"darkcord": "workspace:^",
"eslint": "^8.34.0",
"eslint-plugin-import": "^2.27.5",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"interactions": "^0.0.1",
"prettier": "^2.8.4",
"ts-node": "^10.9.1",
"prettier": "^2.8.8",
"ts-node": "^10.9.2",
"tscpaths": "^0.0.9",
"typescript": "^4.9.5",
"unocss": "^0.49.7"
"unocss": "^0.49.8"
},
"dependencies": {
"tsup": "^6.6.3"
"tsup": "^6.7.0"
}
}
2 changes: 1 addition & 1 deletion packages/darkcord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@darkcord/rest": "workspace:^",
"@darkcord/utils": "workspace:^",
"@darkcord/ws": "workspace:^",
"discord-api-types": "^0.37.33",
"discord-api-types": "^0.37.67",
"ts-mixer": "^6.0.3",
"undici": "^5.19.1",
"ws": "^8.12.0"
Expand Down
27 changes: 26 additions & 1 deletion packages/darkcord/src/resources/User.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataWithClient, DisplayUserAvatarOptions } from "@typings/index";
import { DataWithClient, DisplayUserAvatarOptions, ImageSize } from "@typings/index";
import { userMention } from "@utils/Constants";
import {
APIDMChannel,
Expand Down Expand Up @@ -72,6 +72,14 @@ export class User extends Base {
* The public flags on a user's account
*/
publicFlags: UserFlags | null;
/**
* The user's display name, if it is set. For bots, this is the application name
*/
globalName: string | null;
/**
* The user's avatar decoration hash
*/
avatarDecoration: string | null | undefined;

constructor(data: DataWithClient<APIUser>) {
super(data, data.client);
Expand All @@ -81,6 +89,9 @@ export class User extends Base {

_update(data: APIUser) {
if ("username" in data) this.username = data.username;
if ("global_name" in data) this.globalName = data.global_name;
if ("avatar_decoration" in data)
this.avatarDecoration = data.avatar_decoration;
if ("discriminator" in data) this.discriminator = data.discriminator;
if ("avatar" in data) this.avatar = data.avatar;
if ("banner" in data) this.banner = data.banner;
Expand All @@ -106,6 +117,20 @@ export class User extends Base {
return this;
}

avatarDecorationURL(options?: ImageSize) {
if (!this.avatarDecoration) {
return null;
}

let url = RouteBases.cdn + CDNRoutes.userAvatarDecoration(this.id, this.avatarDecoration)

if (options?.size) {
url += "?size=" + options.size.toString();
}

return url;
}

/**
* The default user's avatar url
* @returns
Expand Down
7 changes: 5 additions & 2 deletions packages/darkcord/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ import { DataCache } from "../manager/DataManager";

export type { MessageAttachment, MessagePostData } from "@darkcord/utils";

export interface DisplayUserAvatarOptions {
format?: UserAvatarFormat;
export interface ImageSize {
size?: number;
}

export interface DisplayUserAvatarOptions extends ImageSize {
format?: UserAvatarFormat;
}

export type GuildDataModel<T> = T & { guild: Guild };

export interface BaseClientOptions {
Expand Down
Loading

0 comments on commit 9d7472e

Please sign in to comment.