feat: MessageEmbed#length (#3003)

* add MessageEmbed#length

* update typings (+MessageEmbed#length)

* eslint: L181 (max line length), L183 (missing semi)

* eslint: L181 (trailing space)
This commit is contained in:
Rattmann (fallen)
2019-02-02 19:29:10 +00:00
committed by Crawl
parent db3ae0159b
commit 1db78994dd
2 changed files with 15 additions and 0 deletions

View File

@@ -169,6 +169,20 @@ class MessageEmbed {
return this.color ? `#${this.color.toString(16).padStart(6, '0')}` : null;
}
/**
* The accumulated length for the embed title, description, fields and footer text
* @type {number}
* @readonly
*/
get length() {
return (
(this.title ? this.title.length : 0) +
(this.description ? this.description.length : 0) +
(this.fields.length >= 1 ? this.fields.reduce((prev, curr) =>
prev + curr.name.length + curr.value.length, 0) : 0) +
(this.footer ? this.footer.text.length : 0));
}
/**
* Adds a field to the embed (max 25).
* @param {StringResolvable} name The name of the field

1
typings/index.d.ts vendored
View File

@@ -729,6 +729,7 @@ declare module 'discord.js' {
public footer: { text?: string; iconURL?: string; proxyIconURL?: string };
public readonly hexColor: string;
public image: { url: string; proxyURL?: string; height?: number; width?: number; };
public readonly length: number;
public provider: { name: string; url: string; };
public thumbnail: { url: string; proxyURL?: string; height?: number; width?: number; };
public timestamp: number;