diff --git a/lib/Client.js b/lib/Client.js index 32079551e..4be94f285 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"); @@ -323,6 +324,7 @@ class Client extends EventEmitter { */ addMessageReaction(channelID, messageID, reaction, userID) { if(userID !== undefined) { + emitDeprecation("REACTION_USER"); this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument"); } if(reaction === decodeURI(reaction)) { @@ -517,12 +519,14 @@ class Client extends EventEmitter { */ createChannel(guildID, name, type, reason, options = {}) { if(typeof options === "string") { // This used to be parentID, back-compat + 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("CREATE_CHANNEL_OPTIONS"); this.emit("warn", "[DEPRECATED] createChannel() was called with a string `reason` argument"); options.reason = reason; reason = undefined; @@ -914,6 +918,7 @@ class Client extends EventEmitter { content.messageReference.failIfNotExists = undefined; } } else if(content.messageReferenceID) { + emitDeprecation("MESSAGE_REFERENCE"); this.emit("warn", "[DEPRECATED] content.messageReferenceID is deprecated. Use content.messageReference instead"); content.message_reference = {message_id: content.messageReferenceID}; } @@ -2764,6 +2769,7 @@ class Client extends EventEmitter { options.after = after; } if(options.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 9897f16f2..57c23657e 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"); @@ -160,6 +161,7 @@ class Member extends Base { } get 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 a2a41216b..e338e7134 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"); @@ -212,6 +213,7 @@ class PrivateChannel extends Channel { */ removeMessageReaction(messageID, reaction, userID) { if(userID !== undefined) { + 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 new file mode 100644 index 000000000..fc959c26f --- /dev/null +++ b/lib/util/emitDeprecation.js @@ -0,0 +1,19 @@ +const warningMessages = { + 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." +}; +const unknownCodeMessage = "You have triggered a deprecated behavior whose warning was implemented improperly. Please report this issue."; + +const emittedCodes = []; + +module.exports = function emitDeprecation(code) { + if(emittedCodes.includes(code) ) { + return; + } + emittedCodes.push(code); + process.emitWarning(warningMessages[code] || unknownCodeMessage, "DeprecationWarning", `eris:${code}`); +};