chore: Emit deprecation messages (#6994)

This commit is contained in:
Jiralite
2021-11-23 09:29:45 +00:00
committed by GitHub
parent 7efeff461f
commit 2a0dedf3e9
5 changed files with 70 additions and 1 deletions

View File

@@ -34,6 +34,9 @@ const DataResolver = require('../util/DataResolver');
const SystemChannelFlags = require('../util/SystemChannelFlags'); const SystemChannelFlags = require('../util/SystemChannelFlags');
const Util = require('../util/Util'); const Util = require('../util/Util');
let deprecationEmittedForSetChannelPositions = false;
let deprecationEmittedForSetRolePositions = false;
/** /**
* Represents a guild (or a server) on Discord. * Represents a guild (or a server) on Discord.
* <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can * <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
@@ -1195,6 +1198,15 @@ class Guild extends AnonymousGuild {
* .catch(console.error); * .catch(console.error);
*/ */
setChannelPositions(channelPositions) { setChannelPositions(channelPositions) {
if (!deprecationEmittedForSetChannelPositions) {
process.emitWarning(
'The Guild#setChannelPositions method is deprecated. Use GuildChannelManager#setPositions instead.',
'DeprecationWarning',
);
deprecationEmittedForSetChannelPositions = true;
}
return this.channels.setPositions(channelPositions); return this.channels.setPositions(channelPositions);
} }
@@ -1216,6 +1228,15 @@ class Guild extends AnonymousGuild {
* .catch(console.error); * .catch(console.error);
*/ */
setRolePositions(rolePositions) { setRolePositions(rolePositions) {
if (!deprecationEmittedForSetRolePositions) {
process.emitWarning(
'The Guild#setRolePositions method is deprecated. Use RoleManager#setPositions instead.',
'DeprecationWarning',
);
deprecationEmittedForSetRolePositions = true;
}
return this.roles.setPositions(rolePositions); return this.roles.setPositions(rolePositions);
} }

View File

@@ -3,6 +3,8 @@
const { RangeError } = require('../errors'); const { RangeError } = require('../errors');
const Util = require('../util/Util'); const Util = require('../util/Util');
let deprecationEmittedForSetAuthor = false;
/** /**
* Represents an embed in a message (image/video preview, rich embed, etc.) * Represents an embed in a message (image/video preview, rich embed, etc.)
*/ */
@@ -372,6 +374,19 @@ class MessageEmbed {
} }
if (typeof options === 'string') { if (typeof options === 'string') {
if (
!deprecationEmittedForSetAuthor &&
(typeof deprecatedIconURL !== 'undefined' || typeof deprecatedURL !== 'undefined')
) {
process.emitWarning(
// eslint-disable-next-line max-len
"Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.",
'DeprecationWarning',
);
deprecationEmittedForSetAuthor = true;
}
options = { name: options, url: deprecatedURL, iconURL: deprecatedIconURL }; options = { name: options, url: deprecatedURL, iconURL: deprecatedIconURL };
} }

View File

@@ -3,6 +3,8 @@
const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel'); const BaseGuildVoiceChannel = require('./BaseGuildVoiceChannel');
const Permissions = require('../util/Permissions'); const Permissions = require('../util/Permissions');
let deprecationEmittedForEditable = false;
/** /**
* Represents a guild voice channel on Discord. * Represents a guild voice channel on Discord.
* @extends {BaseGuildVoiceChannel} * @extends {BaseGuildVoiceChannel}
@@ -15,6 +17,15 @@ class VoiceChannel extends BaseGuildVoiceChannel {
* @deprecated Use {@link VoiceChannel#manageable} instead * @deprecated Use {@link VoiceChannel#manageable} instead
*/ */
get editable() { get editable() {
if (!deprecationEmittedForEditable) {
process.emitWarning(
'The VoiceChannel#editable getter is deprecated. Use VoiceChannel#manageable instead.',
'DeprecationWarning',
);
deprecationEmittedForEditable = true;
}
return this.manageable; return this.manageable;
} }

View File

@@ -6,6 +6,8 @@ const { WebhookTypes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver'); const DataResolver = require('../util/DataResolver');
const SnowflakeUtil = require('../util/SnowflakeUtil'); const SnowflakeUtil = require('../util/SnowflakeUtil');
let deprecationEmittedForFetchMessage = false;
/** /**
* Represents a webhook. * Represents a webhook.
*/ */
@@ -270,12 +272,21 @@ class Webhook {
* Gets a message that was sent by this webhook. * Gets a message that was sent by this webhook.
* @param {Snowflake|'@original'} message The id of the message to fetch * @param {Snowflake|'@original'} message The id of the message to fetch
* @param {WebhookFetchMessageOptions|boolean} [cacheOrOptions={}] The options to provide to fetch the message. * @param {WebhookFetchMessageOptions|boolean} [cacheOrOptions={}] The options to provide to fetch the message.
* A **deprecated** boolean may be passed instead to specify whether to cache the message. * <warn>A **deprecated** boolean may be passed instead to specify whether to cache the message.</warn>
* @returns {Promise<Message|APIMessage>} Returns the raw message data if the webhook was instantiated as a * @returns {Promise<Message|APIMessage>} Returns the raw message data if the webhook was instantiated as a
* {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned * {@link WebhookClient} or if the channel is uncached, otherwise a {@link Message} will be returned
*/ */
async fetchMessage(message, cacheOrOptions = { cache: true }) { async fetchMessage(message, cacheOrOptions = { cache: true }) {
if (typeof cacheOrOptions === 'boolean') { if (typeof cacheOrOptions === 'boolean') {
if (!deprecationEmittedForFetchMessage) {
process.emitWarning(
'Passing a boolean to cache the message in Webhook#fetchMessage is deprecated. Pass an object instead.',
'DeprecationWarning',
);
deprecationEmittedForFetchMessage = true;
}
cacheOrOptions = { cache: cacheOrOptions }; cacheOrOptions = { cache: cacheOrOptions };
} }

View File

@@ -9,6 +9,8 @@ const { Error: DiscordError, RangeError, TypeError } = require('../errors');
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k); const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
const isObject = d => typeof d === 'object' && d !== null; const isObject = d => typeof d === 'object' && d !== null;
let deprecationEmittedForRemoveMentions = false;
/** /**
* Contains various general-purpose utility methods. * Contains various general-purpose utility methods.
*/ */
@@ -578,6 +580,15 @@ class Util extends null {
* @deprecated Use {@link BaseMessageOptions#allowedMentions} instead. * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead.
*/ */
static removeMentions(str) { static removeMentions(str) {
if (!deprecationEmittedForRemoveMentions) {
process.emitWarning(
'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.',
'DeprecationWarning',
);
deprecationEmittedForRemoveMentions = true;
}
return str.replaceAll('@', '@\u200b'); return str.replaceAll('@', '@\u200b');
} }