refactor(MessageEmbed): Deprecate strings for setAuthor() (completely) and setFooter() (#7153)

This commit is contained in:
Jiralite
2021-12-29 10:04:16 +00:00
committed by GitHub
parent baacd6ba69
commit 3496516dc9
2 changed files with 45 additions and 13 deletions

View File

@@ -5,6 +5,9 @@ const { RangeError } = require('../errors');
const Util = require('../util/Util'); const Util = require('../util/Util');
let deprecationEmittedForSetAuthor = false; let deprecationEmittedForSetAuthor = false;
let deprecationEmittedForSetFooter = false;
// TODO: Remove the deprecated code for `setAuthor()` and `setFooter()`.
/** /**
* Represents an embed in a message (image/video preview, rich embed, etc.) * Represents an embed in a message (image/video preview, rich embed, etc.)
@@ -356,11 +359,9 @@ class MessageEmbed {
* @property {string} [iconURL] The icon 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. * Sets the author of this embed.
* @param {string|EmbedAuthorData|null} options The options to provide for 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. * Provide `null` to remove the author data.
* @param {string} [deprecatedIconURL] The icon URL of this author. * @param {string} [deprecatedIconURL] The icon URL of this author.
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn> * <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
@@ -375,13 +376,9 @@ class MessageEmbed {
} }
if (typeof options === 'string') { if (typeof options === 'string') {
if ( if (!deprecationEmittedForSetAuthor) {
!deprecationEmittedForSetAuthor &&
(typeof deprecatedIconURL !== 'undefined' || typeof deprecatedURL !== 'undefined')
) {
process.emitWarning( process.emitWarning(
// eslint-disable-next-line max-len 'Passing strings for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.',
"Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.",
'DeprecationWarning', 'DeprecationWarning',
); );
@@ -416,13 +413,41 @@ class MessageEmbed {
return this; return this;
} }
/**
* The options to provide for setting a footer for a {@link MessageEmbed}.
* @typedef {Object} EmbedFooterData
* @property {string} text The text of the footer.
* @property {string} [iconURL] The icon URL of the footer.
*/
/** /**
* Sets the footer of this embed. * Sets the footer of this embed.
* @param {string} text The text of the footer * @param {string|EmbedFooterData|null} options The options to provide for the footer.
* @param {string} [iconURL] The icon URL of the footer * Provide `null` to remove the footer data.
* @param {string} [deprecatedIconURL] The icon URL of this footer.
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
* @returns {MessageEmbed} * @returns {MessageEmbed}
*/ */
setFooter(text, iconURL) { setFooter(options, deprecatedIconURL) {
if (options === null) {
this.footer = {};
return this;
}
if (typeof options === 'string') {
if (!deprecationEmittedForSetFooter) {
process.emitWarning(
'Passing strings for MessageEmbed#setFooter is deprecated. Pass a sole object instead.',
'DeprecationWarning',
);
deprecationEmittedForSetFooter = true;
}
options = { text: options, iconURL: deprecatedIconURL };
}
const { text, iconURL } = options;
this.footer = { text: Util.verifyString(text, RangeError, 'EMBED_FOOTER_TEXT'), iconURL }; this.footer = { text: Util.verifyString(text, RangeError, 'EMBED_FOOTER_TEXT'), iconURL };
return this; return this;
} }

11
typings/index.d.ts vendored
View File

@@ -1694,11 +1694,13 @@ export class MessageEmbed {
public addField(name: string, value: string, inline?: boolean): this; public addField(name: string, value: string, inline?: boolean): this;
public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this; public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
public setFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this; public setFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
public setAuthor(options: string | EmbedAuthorData | null): this; public setAuthor(options: EmbedAuthorData | null): this;
/** @deprecated Supply a lone object of interface {@link EmbedAuthorData} instead of more parameters. */ /** @deprecated Supply a lone object of interface {@link EmbedAuthorData} instead. */
public setAuthor(name: string, iconURL?: string, url?: string): this; public setAuthor(name: string, iconURL?: string, url?: string): this;
public setColor(color: ColorResolvable): this; public setColor(color: ColorResolvable): this;
public setDescription(description: string): this; public setDescription(description: string): this;
public setFooter(options: EmbedFooterData | null): this;
/** @deprecated Supply a lone object of interface {@link EmbedFooterData} instead. */
public setFooter(text: string, iconURL?: string): this; public setFooter(text: string, iconURL?: string): this;
public setImage(url: string): this; public setImage(url: string): this;
public setThumbnail(url: string): this; public setThumbnail(url: string): this;
@@ -4318,6 +4320,11 @@ export interface EmbedFieldData {
inline?: boolean; inline?: boolean;
} }
export interface EmbedFooterData {
text: string;
iconURL?: string;
}
export type EmojiIdentifierResolvable = string | EmojiResolvable; export type EmojiIdentifierResolvable = string | EmojiResolvable;
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji; export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;