From 63cb6430823a227f1f647be6cdddfb0f188025ab Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 24 Dec 2021 15:50:17 +0000 Subject: [PATCH 1/3] fix: no warning --- src/util/Util.js | 12 ++++++++---- typings/index.d.ts | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/Util.js b/src/util/Util.js index 47ceef45b73e..36f73924ddba 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -529,7 +529,11 @@ class Util extends null { * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead. */ static removeMentions(str) { - if (!deprecationEmittedForRemoveMentions) { + return Util._removeMentions(str, false); + } + + static _removeMentions(str, fromCleanContent) { + if (!deprecationEmittedForRemoveMentions && !fromCleanContent) { process.emitWarning( 'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.', 'DeprecationWarning', @@ -555,15 +559,15 @@ class Util extends null { const id = input.replace(/<|!|>|@/g, ''); if (channel.type === 'DM') { const user = channel.client.users.cache.get(id); - return user ? Util.removeMentions(`@${user.username}`) : input; + return user ? Util._removeMentions(`@${user.username}`, true) : input; } const member = channel.guild.members.cache.get(id); if (member) { - return Util.removeMentions(`@${member.displayName}`); + return Util._removeMentions(`@${member.displayName}`, true); } else { const user = channel.client.users.cache.get(id); - return user ? Util.removeMentions(`@${user.username}`) : input; + return user ? Util._removeMentions(`@${user.username}`, true) : input; } }) .replace(/<#[0-9]+>/g, input => { diff --git a/typings/index.d.ts b/typings/index.d.ts index 0206ffd7dd7d..595f0695931f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2416,6 +2416,7 @@ export class Util extends null { public static cleanContent(str: string, channel: TextBasedChannel): string; /** @deprecated Use {@link MessageOptions.allowedMentions} to control mentions in a message instead. */ public static removeMentions(str: string): string; + private static _removeMentions(str: string, fromCleanContent: boolean): string; public static cloneObject(obj: unknown): unknown; public static discordSort( collection: Collection, From 4b673e506fc471e605ba5267bd04d640156a241c Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 24 Dec 2021 19:05:01 +0000 Subject: [PATCH 2/3] refactor(Util): clean approach --- src/util/Util.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/Util.js b/src/util/Util.js index 36f73924ddba..f7d5487f51e3 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -529,11 +529,7 @@ class Util extends null { * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead. */ static removeMentions(str) { - return Util._removeMentions(str, false); - } - - static _removeMentions(str, fromCleanContent) { - if (!deprecationEmittedForRemoveMentions && !fromCleanContent) { + if (!deprecationEmittedForRemoveMentions) { process.emitWarning( 'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.', 'DeprecationWarning', @@ -542,6 +538,10 @@ class Util extends null { deprecationEmittedForRemoveMentions = true; } + return Util._removeMentions(str); + } + + static _removeMentions(str) { return str.replaceAll('@', '@\u200b'); } @@ -559,15 +559,15 @@ class Util extends null { const id = input.replace(/<|!|>|@/g, ''); if (channel.type === 'DM') { const user = channel.client.users.cache.get(id); - return user ? Util._removeMentions(`@${user.username}`, true) : input; + return user ? Util._removeMentions(`@${user.username}`) : input; } const member = channel.guild.members.cache.get(id); if (member) { - return Util._removeMentions(`@${member.displayName}`, true); + return Util._removeMentions(`@${member.displayName}`); } else { const user = channel.client.users.cache.get(id); - return user ? Util._removeMentions(`@${user.username}`, true) : input; + return user ? Util._removeMentions(`@${user.username}`) : input; } }) .replace(/<#[0-9]+>/g, input => { From e7112b2e5249b69056718995e62da3a9eb16801e Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 24 Dec 2021 19:06:58 +0000 Subject: [PATCH 3/3] types: forgot to remove parameter --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 595f0695931f..0dd89f258116 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2416,7 +2416,7 @@ export class Util extends null { public static cleanContent(str: string, channel: TextBasedChannel): string; /** @deprecated Use {@link MessageOptions.allowedMentions} to control mentions in a message instead. */ public static removeMentions(str: string): string; - private static _removeMentions(str: string, fromCleanContent: boolean): string; + private static _removeMentions(str: string): string; public static cloneObject(obj: unknown): unknown; public static discordSort( collection: Collection,