feat: add helper getters for messages

This commit is contained in:
Paul Makles
2022-10-09 10:25:02 +01:00
parent 5e2b82c2a9
commit 2d139c3140
3 changed files with 62 additions and 0 deletions
+14
View File
@@ -230,6 +230,20 @@ export class Member {
}
}
/**
* Get a pre-configured avatar URL of a member
*/
get avatarURL() {
return this.generateAvatarURL({ max_side: 256 }) ?? this.user?.avatarURL;
}
/**
* Get a pre-configured animated avatar URL of a member
*/
get animatedAvatarURL() {
return this.generateAvatarURL({ max_side: 256 }, true) ?? this.user?.animatedAvatarURL;
}
/**
* Generate URL to this member's avatar
* @param args File parameters
+34
View File
@@ -86,6 +86,40 @@ export class Message {
return this.client.configuration?.app + this.path;
}
/**
* Get the username for this message.
*/
get username() {
return this.masquerade?.name ?? this.member?.nickname ?? this.author?.username;
}
/**
* Get the role colour for this message.
*/
get roleColour() {
return this.member?.roleColour;
}
/**
* Get the avatar URL for this message.
*/
get avatarURL() {
return this.generateMasqAvatarURL()
?? (this.member
? this.member?.avatarURL
: this.author?.avatarURL);
}
/**
* Get the animated avatar URL for this message.
*/
get animatedAvatarURL() {
return this.generateMasqAvatarURL()
?? (this.member
? this.member?.animatedAvatarURL
: this.author?.animatedAvatarURL);
}
@computed generateMasqAvatarURL() {
const avatar = this.masquerade?.avatar;
return avatar ? this.client.proxyFile(avatar) : undefined;
+14
View File
@@ -179,6 +179,20 @@ export class User {
return `${this.client.apiURL}/users/${this._id}/default_avatar`;
}
/**
* Get a pre-configured avatar URL of a user
*/
get avatarURL() {
return this.generateAvatarURL({ max_side: 256 });
}
/**
* Get a pre-configured animated avatar URL of a user
*/
get animatedAvatarURL() {
return this.generateAvatarURL({ max_side: 256 }, true);
}
@computed generateAvatarURL(...args: FileArgs) {
return (
this.client.generateFileURL(this.avatar ?? undefined, ...args) ??