Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use process warnings for deprecations #1276

Merged
merged 22 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
19fecf6
Create deprecation helper, use for existing warns
eritbh Sep 7, 2021
adc3353
use correct Set method, derp
eritbh Sep 7, 2021
e3313be
Use array for emittedCodes
eritbh Sep 8, 2021
1256556
Move warning messages to a single location
eritbh Sep 14, 2021
672183b
Use named warning codes
eritbh Sep 14, 2021
83720a7
Alphabetize deprecation codes
eritbh Sep 14, 2021
1936c23
Don't include `eris:` in every code manually
eritbh Sep 14, 2021
b3a75e4
Merge + rewrite createChannel deprecations
eritbh Sep 20, 2021
2b27b08
rewrite all the other deprecation warnings
eritbh Sep 20, 2021
bc83b95
Include fallback message for invalid warning codes
eritbh Oct 3, 2021
3811cde
Merge branch 'dev' into deprecation-process-warnings
eritbh Dec 18, 2021
608c58b
Remove now-unused deprecation code
eritbh Dec 18, 2021
05b2cc2
eslint
eritbh Dec 18, 2021
49a0a08
Merge branch 'abalabahaha:dev' into deprecation-process-warnings
eritbh May 9, 2022
49025cd
Merge branch 'dev' into deprecation-process-warnings
eritbh May 29, 2022
c8dcd76
Merge branch 'dev' into deprecation-process-warnings
eritbh Jun 1, 2022
3b6aee9
Merge branch 'dev' into deprecation-process-warnings
eritbh Jun 5, 2022
d361a9f
Merge branch 'dev' into deprecation-process-warnings
DonovanDMC Jun 8, 2022
14afb60
Merge branch 'dev' into deprecation-process-warnings
eritbh Jun 8, 2022
8273a1c
Merge branch 'dev' into deprecation-process-warnings
DonovanDMC Jun 30, 2022
64ef526
Merge branch 'dev' into deprecation-process-warnings
eritbh Sep 2, 2022
1a0880c
Merge branch 'dev' into deprecation-process-warnings
eritbh Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
eritbh marked this conversation as resolved.
Show resolved Hide resolved
this.emit("warn", "[DEPRECATED] addMessageReaction() was called without an \"@me\" `userID` argument");
eritbh marked this conversation as resolved.
Show resolved Hide resolved
}
if(reaction === decodeURI(reaction)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand All @@ -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};
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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)));
Expand Down
2 changes: 2 additions & 0 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/structures/PrivateChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions lib/util/emitDeprecation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const emittedCodes = new Set();

module.exports = function emitDeprecation(code, description) {
if(emittedCodes.has(code) ) {
return;
}
emittedCodes.add(code);
process.emitWarning(description, "DeprecationWarning", code);
};
eritbh marked this conversation as resolved.
Show resolved Hide resolved