refactor(MessageEmbed): Utilise an object approach for .setAuthor() (#6966)

Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
Jiralite
2021-11-16 17:31:08 +00:00
committed by GitHub
parent 5e0a7d51fc
commit 73854ee852
2 changed files with 36 additions and 5 deletions

View File

@@ -345,15 +345,38 @@ class MessageEmbed {
return this;
}
/**
* The options to provide for setting an author for a {@link MessageEmbed}.
* @typedef {Object} EmbedAuthorData
* @property {string} name The name of this author.
* @property {string} [url] The URL of this author.
* @property {string} [iconURL] The icon URL of this author.
*/
// TODO: Remove the deprecated code in the following method and typings.
/**
* Sets the author of this embed.
* @param {string} name The name of the author
* @param {string} [iconURL] The icon URL of the author
* @param {string} [url] The URL of the author
* @param {string|EmbedAuthorData|null} options The options to provide for the author.
* A string may simply be provided if only the author name is desirable.
* Provide `null` to remove the author data.
* @param {string} [deprecatedIconURL] The icon URL of this author.
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
* @param {string} [deprecatedURL] The URL of this author.
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
* @returns {MessageEmbed}
*/
setAuthor(name, iconURL, url) {
this.author = { name: Util.verifyString(name, RangeError, 'EMBED_AUTHOR_NAME'), iconURL, url };
setAuthor(options, deprecatedIconURL, deprecatedURL) {
if (options === null) {
this.author = {};
return this;
}
if (typeof options === 'string') {
options = { name: options, url: deprecatedURL, iconURL: deprecatedIconURL };
}
const { name, url, iconURL } = options;
this.author = { name: Util.verifyString(name, RangeError, 'EMBED_AUTHOR_NAME'), url, iconURL };
return this;
}