From 19fecf620e659f6bb6f675b37916334255919442 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 7 Sep 2021 16:56:43 -0400 Subject: [PATCH 01/12] Create deprecation helper, use for existing warns --- lib/Client.js | 8 ++++++++ lib/structures/Member.js | 2 ++ lib/structures/PrivateChannel.js | 2 ++ lib/util/emitDeprecation.js | 9 +++++++++ 4 files changed, 21 insertions(+) create mode 100644 lib/util/emitDeprecation.js diff --git a/lib/Client.js b/lib/Client.js index 3b8593b25..9ae52e766 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -4,6 +4,7 @@ const Base = require("./structures/Base"); const Channel = require("./structures/Channel"); const Collection = require("./util/Collection"); const Constants = require("./Constants"); +const emitDeprecation = require("./util/emitDeprecation"); const Endpoints = require("./rest/Endpoints"); const ExtendedUser = require("./structures/ExtendedUser"); const GroupChannel = require("./structures/GroupChannel"); @@ -286,6 +287,7 @@ class Client extends EventEmitter { */ addMessageReaction(channelID, messageID, reaction, userID) { if(userID !== undefined) { + emitDeprecation("eris:1", "addMessageReaction() was called without an \"@me\" `userID` argument"); this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument"); } if(reaction === decodeURI(reaction)) { @@ -418,12 +420,14 @@ class Client extends EventEmitter { */ createChannel(guildID, name, type, reason, options = {}) { if(typeof options === "string") { // This used to be parentID, back-compat + emitDeprecation("eris:2", "createChannel() was called with a string `options` argument"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `options` argument"); options = { parentID: options }; } if(typeof reason === "string") { // Reason is deprecated, will be folded into options + emitDeprecation("eris:3", "createChannel() was called with a string `reason` argument"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; @@ -623,6 +627,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { + emitDeprecation("eris:4", "content.embed is deprecated. Use content.embeds instead"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -647,6 +652,7 @@ class Client extends EventEmitter { content.messageReference.failIfNotExists = undefined; } } else if(content.messageReferenceID) { + emitDeprecation("eris:5", "content.messageReferenceID is deprecated. Use content.messageReference instead"); this.emit("warn", "[DEPRECATED] content.messageReferenceID is deprecated. Use content.messageReference instead"); content.message_reference = {message_id: content.messageReferenceID}; } @@ -1280,6 +1286,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { + emitDeprecation("eris:6", "content.embed is deprecated. Use content.embeds instead"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -1968,6 +1975,7 @@ class Client extends EventEmitter { options.after = after; } if(options.before) { + emitDeprecation("eris:7", "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); this.emit("warn", "[DEPRECATED] getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); } return this.requestHandler.request("GET", Endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction), true, options).then((users) => users.map((user) => new User(user, this))); diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 26b0681a7..37b7ba99e 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -1,6 +1,7 @@ "use strict"; const Base = require("./Base"); +const emitDeprecation = require("../util/emitDeprecation"); const Endpoints = require("../rest/Endpoints"); const User = require("./User"); const VoiceState = require("./VoiceState"); @@ -133,6 +134,7 @@ class Member extends Base { } get permission() { + emitDeprecation("eris:8", "Member#permission is deprecated. Use Member#permissions instead"); this.guild.shard.client.emit("warn", "[DEPRECATED] Member#permission is deprecated. Use Member#permissions instead"); return this.permissions; } diff --git a/lib/structures/PrivateChannel.js b/lib/structures/PrivateChannel.js index 54ff072f8..604abd6aa 100644 --- a/lib/structures/PrivateChannel.js +++ b/lib/structures/PrivateChannel.js @@ -2,6 +2,7 @@ const Channel = require("./Channel"); const Collection = require("../util/Collection"); +const emitDeprecation = require("../util/emitDeprecation"); const Endpoints = require("../rest/Endpoints"); const Message = require("./Message"); const {GatewayOPCodes, ChannelTypes} = require("../Constants"); @@ -203,6 +204,7 @@ class PrivateChannel extends Channel { */ removeMessageReaction(messageID, reaction, userID) { if(userID !== undefined) { + emitDeprecation("eris:9", "removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); this.emit("warn", "[DEPRECATED] removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); } return this.client.removeMessageReaction.call(this.client, this.id, messageID, reaction, userID); diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js new file mode 100644 index 000000000..8bb1745b5 --- /dev/null +++ b/lib/util/emitDeprecation.js @@ -0,0 +1,9 @@ +const emittedCodes = new Set(); + +module.exports = function emitDeprecation(code, description) { + if(emittedCodes.includes(code) ) { + return; + } + emittedCodes.add(code); + process.emitWarning(description, "DeprecationWarning", code); +}; From adc33532fa23bccd4275c81d22cc762aa20b23ee Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 7 Sep 2021 17:08:51 -0400 Subject: [PATCH 02/12] use correct Set method, derp --- lib/util/emitDeprecation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 8bb1745b5..96abfc047 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,7 +1,7 @@ const emittedCodes = new Set(); module.exports = function emitDeprecation(code, description) { - if(emittedCodes.includes(code) ) { + if(emittedCodes.has(code) ) { return; } emittedCodes.add(code); From e3313be82ba6b4d2b7db237a19588ab3b7847b79 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 8 Sep 2021 15:05:01 -0400 Subject: [PATCH 03/12] Use array for emittedCodes Array ops are apparently faster than Set ops in V8? https://discord.com/channels/831967755447828491/884930349119991849/885222846815678495 --- lib/util/emitDeprecation.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 96abfc047..046732c72 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,9 +1,9 @@ -const emittedCodes = new Set(); +const emittedCodes = []; module.exports = function emitDeprecation(code, description) { - if(emittedCodes.has(code) ) { + if(emittedCodes.includes(code) ) { return; } - emittedCodes.add(code); + emittedCodes.push(code); process.emitWarning(description, "DeprecationWarning", code); }; From 12565561a77dfcbf2cb0b813f6c3e663ff62389d Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 14 Sep 2021 16:49:40 -0400 Subject: [PATCH 04/12] Move warning messages to a single location --- lib/Client.js | 14 +++++++------- lib/structures/Member.js | 2 +- lib/structures/PrivateChannel.js | 2 +- lib/util/emitDeprecation.js | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 9ae52e766..7a09e94a3 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -287,7 +287,7 @@ class Client extends EventEmitter { */ addMessageReaction(channelID, messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:1", "addMessageReaction() was called without an \"@me\" `userID` argument"); + emitDeprecation("eris:1"); this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument"); } if(reaction === decodeURI(reaction)) { @@ -420,14 +420,14 @@ class Client extends EventEmitter { */ createChannel(guildID, name, type, reason, options = {}) { if(typeof options === "string") { // This used to be parentID, back-compat - emitDeprecation("eris:2", "createChannel() was called with a string `options` argument"); + emitDeprecation("eris:2"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `options` argument"); options = { parentID: options }; } if(typeof reason === "string") { // Reason is deprecated, will be folded into options - emitDeprecation("eris:3", "createChannel() was called with a string `reason` argument"); + emitDeprecation("eris:3"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; @@ -627,7 +627,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:4", "content.embed is deprecated. Use content.embeds instead"); + emitDeprecation("eris:4"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -652,7 +652,7 @@ class Client extends EventEmitter { content.messageReference.failIfNotExists = undefined; } } else if(content.messageReferenceID) { - emitDeprecation("eris:5", "content.messageReferenceID is deprecated. Use content.messageReference instead"); + emitDeprecation("eris:5"); this.emit("warn", "[DEPRECATED] content.messageReferenceID is deprecated. Use content.messageReference instead"); content.message_reference = {message_id: content.messageReferenceID}; } @@ -1286,7 +1286,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:6", "content.embed is deprecated. Use content.embeds instead"); + emitDeprecation("eris:6"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -1975,7 +1975,7 @@ class Client extends EventEmitter { options.after = after; } if(options.before) { - emitDeprecation("eris:7", "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); + emitDeprecation("eris:7"); this.emit("warn", "[DEPRECATED] getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); } return this.requestHandler.request("GET", Endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction), true, options).then((users) => users.map((user) => new User(user, this))); diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 37b7ba99e..1dcba9223 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -134,7 +134,7 @@ class Member extends Base { } get permission() { - emitDeprecation("eris:8", "Member#permission is deprecated. Use Member#permissions instead"); + emitDeprecation("eris:8"); this.guild.shard.client.emit("warn", "[DEPRECATED] Member#permission is deprecated. Use Member#permissions instead"); return this.permissions; } diff --git a/lib/structures/PrivateChannel.js b/lib/structures/PrivateChannel.js index 604abd6aa..50fe3e2c7 100644 --- a/lib/structures/PrivateChannel.js +++ b/lib/structures/PrivateChannel.js @@ -204,7 +204,7 @@ class PrivateChannel extends Channel { */ removeMessageReaction(messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:9", "removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); + emitDeprecation("eris:9"); this.emit("warn", "[DEPRECATED] removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); } return this.client.removeMessageReaction.call(this.client, this.id, messageID, reaction, userID); diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 046732c72..c64aa1ff2 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,9 +1,21 @@ +const warningMessages = { + "eris:1": "addMessageReaction() was called without an \"@me\" `userID` argument", + "eris:2": "createChannel() was called with a string `options` argument", + "eris:3": "createChannel() was called with a string `reason` argument", + "eris:4": "content.embed is deprecated. Use content.embeds instead", + "eris:5": "content.messageReferenceID is deprecated. Use content.messageReference instead", + "eris:6": "content.embed is deprecated. Use content.embeds instead", + "eris:7": "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", + "eris:8": "Member#permission is deprecated. Use Member#permissions instead", + "eris:9": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument" +}; + const emittedCodes = []; -module.exports = function emitDeprecation(code, description) { +module.exports = function emitDeprecation(code) { if(emittedCodes.includes(code) ) { return; } emittedCodes.push(code); - process.emitWarning(description, "DeprecationWarning", code); + process.emitWarning(warningMessages[code], "DeprecationWarning", code); }; From 672183b0e9a3404c95af9e1ea053404a1e9d7ead Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 14 Sep 2021 16:59:58 -0400 Subject: [PATCH 05/12] Use named warning codes See https://github.com/abalabahaha/eris/discussions/1274#discussioncomment-1293529 --- lib/Client.js | 14 +++++++------- lib/structures/Member.js | 2 +- lib/structures/PrivateChannel.js | 2 +- lib/util/emitDeprecation.js | 17 ++++++++--------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index 7a09e94a3..aead14776 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -287,7 +287,7 @@ class Client extends EventEmitter { */ addMessageReaction(channelID, messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:1"); + emitDeprecation("eris:REACTION_USER"); this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument"); } if(reaction === decodeURI(reaction)) { @@ -420,14 +420,14 @@ class Client extends EventEmitter { */ createChannel(guildID, name, type, reason, options = {}) { if(typeof options === "string") { // This used to be parentID, back-compat - emitDeprecation("eris:2"); + emitDeprecation("eris:CREATE_CHANNEL_OPTIONS"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `options` argument"); options = { parentID: options }; } if(typeof reason === "string") { // Reason is deprecated, will be folded into options - emitDeprecation("eris:3"); + emitDeprecation("eris:CREATE_CHANNEL_REASON"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; @@ -627,7 +627,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:4"); + emitDeprecation("eris:SINGLE_EMBED"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -652,7 +652,7 @@ class Client extends EventEmitter { content.messageReference.failIfNotExists = undefined; } } else if(content.messageReferenceID) { - emitDeprecation("eris:5"); + emitDeprecation("eris:MESSAGE_REFERENCE"); this.emit("warn", "[DEPRECATED] content.messageReferenceID is deprecated. Use content.messageReference instead"); content.message_reference = {message_id: content.messageReferenceID}; } @@ -1286,7 +1286,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:6"); + emitDeprecation("eris:SINGLE_EMBED"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -1975,7 +1975,7 @@ class Client extends EventEmitter { options.after = after; } if(options.before) { - emitDeprecation("eris:7"); + emitDeprecation("eris:GET_REACTION_BEFORE"); this.emit("warn", "[DEPRECATED] getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); } return this.requestHandler.request("GET", Endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction), true, options).then((users) => users.map((user) => new User(user, this))); diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 1dcba9223..92fdcb37c 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -134,7 +134,7 @@ class Member extends Base { } get permission() { - emitDeprecation("eris:8"); + emitDeprecation("eris:MEMBER_PERMISSION"); this.guild.shard.client.emit("warn", "[DEPRECATED] Member#permission is deprecated. Use Member#permissions instead"); return this.permissions; } diff --git a/lib/structures/PrivateChannel.js b/lib/structures/PrivateChannel.js index 50fe3e2c7..d01cda161 100644 --- a/lib/structures/PrivateChannel.js +++ b/lib/structures/PrivateChannel.js @@ -204,7 +204,7 @@ class PrivateChannel extends Channel { */ removeMessageReaction(messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:9"); + emitDeprecation("eris:DM_REACTION_BEFORE"); this.emit("warn", "[DEPRECATED] removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); } return this.client.removeMessageReaction.call(this.client, this.id, messageID, reaction, userID); diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index c64aa1ff2..dcb39e6c7 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,13 +1,12 @@ const warningMessages = { - "eris:1": "addMessageReaction() was called without an \"@me\" `userID` argument", - "eris:2": "createChannel() was called with a string `options` argument", - "eris:3": "createChannel() was called with a string `reason` argument", - "eris:4": "content.embed is deprecated. Use content.embeds instead", - "eris:5": "content.messageReferenceID is deprecated. Use content.messageReference instead", - "eris:6": "content.embed is deprecated. Use content.embeds instead", - "eris:7": "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", - "eris:8": "Member#permission is deprecated. Use Member#permissions instead", - "eris:9": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument" + "eris:REACTION_USER": "addMessageReaction() was called without an \"@me\" `userID` argument", + "eris:CREATE_CHANNEL_OPTIONS": "createChannel() was called with a string `options` argument", + "eris:CREATE_CHANNEL_REASON": "createChannel() was called with a string `reason` argument", + "eris:SINGLE_EMBED": "content.embed is deprecated. Use content.embeds instead", + "eris:MESSAGE_REFERENCE": "content.messageReferenceID is deprecated. Use content.messageReference instead", + "eris:GET_REACTION_BEFORE": "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", + "eris:MEMBER_PERMISSION": "Member#permission is deprecated. Use Member#permissions instead", + "eris:DM_REACTION_REMOVE": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument" }; const emittedCodes = []; From 83720a7642a36ff5ff8481883e0fcbfe782bd9dc Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 14 Sep 2021 17:01:08 -0400 Subject: [PATCH 06/12] Alphabetize deprecation codes --- lib/util/emitDeprecation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index dcb39e6c7..40c7394b5 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,12 +1,12 @@ const warningMessages = { - "eris:REACTION_USER": "addMessageReaction() was called without an \"@me\" `userID` argument", "eris:CREATE_CHANNEL_OPTIONS": "createChannel() was called with a string `options` argument", "eris:CREATE_CHANNEL_REASON": "createChannel() was called with a string `reason` argument", - "eris:SINGLE_EMBED": "content.embed is deprecated. Use content.embeds instead", - "eris:MESSAGE_REFERENCE": "content.messageReferenceID is deprecated. Use content.messageReference instead", + "eris:DM_REACTION_REMOVE": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument", "eris:GET_REACTION_BEFORE": "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", "eris:MEMBER_PERMISSION": "Member#permission is deprecated. Use Member#permissions instead", - "eris:DM_REACTION_REMOVE": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument" + "eris:MESSAGE_REFERENCE": "content.messageReferenceID is deprecated. Use content.messageReference instead", + "eris:REACTION_USER": "addMessageReaction() was called without an \"@me\" `userID` argument", + "eris:SINGLE_EMBED": "content.embed is deprecated. Use content.embeds instead" }; const emittedCodes = []; From 1936c23e9cf050ecb89c05e03573eeb7b8a189a9 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 14 Sep 2021 17:03:11 -0400 Subject: [PATCH 07/12] Don't include `eris:` in every code manually --- lib/Client.js | 14 +++++++------- lib/structures/Member.js | 2 +- lib/structures/PrivateChannel.js | 2 +- lib/util/emitDeprecation.js | 18 +++++++++--------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index aead14776..dd9d4c061 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -287,7 +287,7 @@ class Client extends EventEmitter { */ addMessageReaction(channelID, messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:REACTION_USER"); + emitDeprecation("REACTION_USER"); this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument"); } if(reaction === decodeURI(reaction)) { @@ -420,14 +420,14 @@ class Client extends EventEmitter { */ createChannel(guildID, name, type, reason, options = {}) { if(typeof options === "string") { // This used to be parentID, back-compat - emitDeprecation("eris:CREATE_CHANNEL_OPTIONS"); + emitDeprecation("CREATE_CHANNEL_OPTIONS"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `options` argument"); options = { parentID: options }; } if(typeof reason === "string") { // Reason is deprecated, will be folded into options - emitDeprecation("eris:CREATE_CHANNEL_REASON"); + emitDeprecation("CREATE_CHANNEL_REASON"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; @@ -627,7 +627,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:SINGLE_EMBED"); + emitDeprecation("SINGLE_EMBED"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -652,7 +652,7 @@ class Client extends EventEmitter { content.messageReference.failIfNotExists = undefined; } } else if(content.messageReferenceID) { - emitDeprecation("eris:MESSAGE_REFERENCE"); + emitDeprecation("MESSAGE_REFERENCE"); this.emit("warn", "[DEPRECATED] content.messageReferenceID is deprecated. Use content.messageReference instead"); content.message_reference = {message_id: content.messageReferenceID}; } @@ -1286,7 +1286,7 @@ class Client extends EventEmitter { } else if(content.content !== undefined && typeof content.content !== "string") { content.content = "" + content.content; } else if(content.embed && !content.embeds) { - emitDeprecation("eris:SINGLE_EMBED"); + emitDeprecation("SINGLE_EMBED"); this.emit("warn", "[DEPRECATED] content.embed is deprecated. Use content.embeds instead"); content.embeds = [content.embed]; } @@ -1975,7 +1975,7 @@ class Client extends EventEmitter { options.after = after; } if(options.before) { - emitDeprecation("eris:GET_REACTION_BEFORE"); + emitDeprecation("GET_REACTION_BEFORE"); this.emit("warn", "[DEPRECATED] getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter"); } return this.requestHandler.request("GET", Endpoints.CHANNEL_MESSAGE_REACTION(channelID, messageID, reaction), true, options).then((users) => users.map((user) => new User(user, this))); diff --git a/lib/structures/Member.js b/lib/structures/Member.js index 92fdcb37c..7febffb75 100644 --- a/lib/structures/Member.js +++ b/lib/structures/Member.js @@ -134,7 +134,7 @@ class Member extends Base { } get permission() { - emitDeprecation("eris:MEMBER_PERMISSION"); + emitDeprecation("MEMBER_PERMISSION"); this.guild.shard.client.emit("warn", "[DEPRECATED] Member#permission is deprecated. Use Member#permissions instead"); return this.permissions; } diff --git a/lib/structures/PrivateChannel.js b/lib/structures/PrivateChannel.js index d01cda161..eac1c00da 100644 --- a/lib/structures/PrivateChannel.js +++ b/lib/structures/PrivateChannel.js @@ -204,7 +204,7 @@ class PrivateChannel extends Channel { */ removeMessageReaction(messageID, reaction, userID) { if(userID !== undefined) { - emitDeprecation("eris:DM_REACTION_BEFORE"); + emitDeprecation("DM_REACTION_BEFORE"); this.emit("warn", "[DEPRECATED] removeMessageReaction() was called on a PrivateChannel with a `userID` argument"); } return this.client.removeMessageReaction.call(this.client, this.id, messageID, reaction, userID); diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 40c7394b5..b25429bff 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,12 +1,12 @@ const warningMessages = { - "eris:CREATE_CHANNEL_OPTIONS": "createChannel() was called with a string `options` argument", - "eris:CREATE_CHANNEL_REASON": "createChannel() was called with a string `reason` argument", - "eris:DM_REACTION_REMOVE": "removeMessageReaction() was called on a PrivateChannel with a `userID` argument", - "eris:GET_REACTION_BEFORE": "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", - "eris:MEMBER_PERMISSION": "Member#permission is deprecated. Use Member#permissions instead", - "eris:MESSAGE_REFERENCE": "content.messageReferenceID is deprecated. Use content.messageReference instead", - "eris:REACTION_USER": "addMessageReaction() was called without an \"@me\" `userID` argument", - "eris:SINGLE_EMBED": "content.embed is deprecated. Use content.embeds instead" + CREATE_CHANNEL_OPTIONS: "createChannel() was called with a string `options` argument", + CREATE_CHANNEL_REASON: "createChannel() was called with a string `reason` argument", + DM_REACTION_REMOVE: "removeMessageReaction() was called on a PrivateChannel with a `userID` argument", + GET_REACTION_BEFORE: "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", + MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead", + MESSAGE_REFERENCE: "content.messageReferenceID is deprecated. Use content.messageReference instead", + REACTION_USER: "addMessageReaction() was called without an \"@me\" `userID` argument", + SINGLE_EMBED: "content.embed is deprecated. Use content.embeds instead" }; const emittedCodes = []; @@ -16,5 +16,5 @@ module.exports = function emitDeprecation(code) { return; } emittedCodes.push(code); - process.emitWarning(warningMessages[code], "DeprecationWarning", code); + process.emitWarning(warningMessages[code], "DeprecationWarning", `eris:${code}`); }; From b3a75e40b29e0918fe727e75c6f349e4f3dba860 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 20 Sep 2021 14:10:24 -0400 Subject: [PATCH 08/12] Merge + rewrite createChannel deprecations --- lib/Client.js | 2 +- lib/util/emitDeprecation.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Client.js b/lib/Client.js index dd9d4c061..23ad274c6 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -427,7 +427,7 @@ class Client extends EventEmitter { }; } if(typeof reason === "string") { // Reason is deprecated, will be folded into options - emitDeprecation("CREATE_CHANNEL_REASON"); + emitDeprecation("CREATE_CHANNEL_OPTIONS"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index b25429bff..37b9c20c2 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,6 +1,5 @@ const warningMessages = { - CREATE_CHANNEL_OPTIONS: "createChannel() was called with a string `options` argument", - CREATE_CHANNEL_REASON: "createChannel() was called with a string `reason` argument", + CREATE_CHANNEL_OPTIONS: "Passing parentID or reason strings directly to createChannel() is deprecated. Use an options object that provides these instead.", DM_REACTION_REMOVE: "removeMessageReaction() was called on a PrivateChannel with a `userID` argument", GET_REACTION_BEFORE: "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead", From 2b27b08c6a3200cee294d11839e006587f706fd1 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 20 Sep 2021 14:16:33 -0400 Subject: [PATCH 09/12] rewrite all the other deprecation warnings --- lib/util/emitDeprecation.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 37b9c20c2..e1fc8236c 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -1,11 +1,11 @@ const warningMessages = { - CREATE_CHANNEL_OPTIONS: "Passing parentID or reason strings directly to createChannel() is deprecated. Use an options object that provides these instead.", - DM_REACTION_REMOVE: "removeMessageReaction() was called on a PrivateChannel with a `userID` argument", - GET_REACTION_BEFORE: "getMessageReaction() was called with a `before` parameter. Discord no longer supports this parameter", - MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead", - MESSAGE_REFERENCE: "content.messageReferenceID is deprecated. Use content.messageReference instead", - REACTION_USER: "addMessageReaction() was called without an \"@me\" `userID` argument", - SINGLE_EMBED: "content.embed is deprecated. Use content.embeds instead" + CREATE_CHANNEL_OPTIONS: "Passing parentID or reason string arguments directly to createChannel() is deprecated. Use an options object instead.", + DM_REACTION_REMOVE: "Passing a userID when using removeMessageReaction() in a PrivateChannel is deprecated. This behavior is no longer supported by Discord.", + GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.", + MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.", + MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.", + REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.", + SINGLE_EMBED: "Passing the content.embed option to createMessage() or editMessage() is deprecated. Use the content.embeds option instead." }; const emittedCodes = []; From bc83b95246f20222e3216dfc19c6875f14824f83 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 3 Oct 2021 17:07:51 -0400 Subject: [PATCH 10/12] Include fallback message for invalid warning codes --- lib/util/emitDeprecation.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index e1fc8236c..098a2bcdf 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -7,6 +7,7 @@ const warningMessages = { REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.", SINGLE_EMBED: "Passing the content.embed option to createMessage() or editMessage() is deprecated. Use the content.embeds option instead." }; +const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue."; const emittedCodes = []; @@ -15,5 +16,5 @@ module.exports = function emitDeprecation(code) { return; } emittedCodes.push(code); - process.emitWarning(warningMessages[code], "DeprecationWarning", `eris:${code}`); + process.emitWarning(warningMessages[code] || unknownCodeMessage, "DeprecationWarning", `eris:${code}`); }; From 608c58bd820c11eaad8a57de2bd97a62e3d37fb4 Mon Sep 17 00:00:00 2001 From: Erin Date: Sat, 18 Dec 2021 11:53:07 -0500 Subject: [PATCH 11/12] Remove now-unused deprecation code Single `embed` options were un-deprecated in dc72ad9 --- lib/util/emitDeprecation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 098a2bcdf..9eb32e62b 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -5,7 +5,6 @@ const warningMessages = { MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.", MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.", REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.", - SINGLE_EMBED: "Passing the content.embed option to createMessage() or editMessage() is deprecated. Use the content.embeds option instead." }; const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue."; From 05b2cc2d9e2c5dde7d5ac717b882499e853d99ea Mon Sep 17 00:00:00 2001 From: Erin Date: Sat, 18 Dec 2021 11:53:42 -0500 Subject: [PATCH 12/12] eslint --- lib/util/emitDeprecation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/emitDeprecation.js b/lib/util/emitDeprecation.js index 9eb32e62b..fc959c26f 100644 --- a/lib/util/emitDeprecation.js +++ b/lib/util/emitDeprecation.js @@ -4,7 +4,7 @@ const warningMessages = { GET_REACTION_BEFORE: "Passing the before parameter to getMessageReaction() is deprecated. Discord no longer supports this parameter.", MEMBER_PERMISSION: "Member#permission is deprecated. Use Member#permissions instead.", MESSAGE_REFERENCE: "Passing the content.messageReferenceID option to createMessage() is deprecated. Use the content.messageReference option instead.", - REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter.", + REACTION_USER: "Passing a userID other than \"@me\" to addMessageReaction() is deprecated. Discord no longer supports this parameter." }; const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue.";