From 0c24cc8ec0d818315cc8f8bcf74fce060847ac79 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 7 Jan 2022 22:40:36 +0000 Subject: [PATCH] refactor: Remove `Util.removeMentions()` (#6530) --- packages/discord.js/src/util/Util.js | 35 +++----------------------- packages/discord.js/typings/index.d.ts | 3 --- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/packages/discord.js/src/util/Util.js b/packages/discord.js/src/util/Util.js index 249360ae0..868391fad 100644 --- a/packages/discord.js/src/util/Util.js +++ b/packages/discord.js/src/util/Util.js @@ -1,7 +1,6 @@ 'use strict'; const { parse } = require('node:path'); -const process = require('node:process'); const { Collection } = require('@discordjs/collection'); const fetch = require('node-fetch'); const { Colors, Endpoints } = require('./Constants'); @@ -9,8 +8,6 @@ const Options = require('./Options'); const { Error: DiscordError, RangeError, TypeError } = require('../errors'); const isObject = d => typeof d === 'object' && d !== null; -let deprecationEmittedForRemoveMentions = false; - /** * Contains various general-purpose utility methods. */ @@ -521,34 +518,8 @@ class Util extends null { const res = parse(path); return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0]; } - - /** - * Breaks user, role and everyone/here mentions by adding a zero width space after every @ character - * @param {string} str The string to sanitize - * @returns {string} - * @deprecated Use {@link BaseMessageOptions#allowedMentions} instead. - */ - static removeMentions(str) { - if (!deprecationEmittedForRemoveMentions) { - process.emitWarning( - 'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.', - 'DeprecationWarning', - ); - - deprecationEmittedForRemoveMentions = true; - } - - return Util._removeMentions(str); - } - - static _removeMentions(str) { - return str.replaceAll('@', '@\u200b'); - } - /** * The content to have all mentions replaced by the equivalent text. - * When {@link Util.removeMentions} is removed, this method will no longer sanitize mentions. - * Use {@link BaseMessageOptions#allowedMentions} instead to prevent mentions when sending a message. * @param {string} str The string to be converted * @param {TextBasedChannels} channel The channel the string was sent in * @returns {string} @@ -559,15 +530,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 ? `@${user.username}` : input; } const member = channel.guild.members.cache.get(id); if (member) { - return Util._removeMentions(`@${member.displayName}`); + return `@${member.displayName}`; } else { const user = channel.client.users.cache.get(id); - return user ? Util._removeMentions(`@${user.username}`) : input; + return user ? `@${user.username}` : input; } }) .replace(/<#[0-9]+>/g, input => { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 8a1a8bad9..2ba9a42ce 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2416,9 +2416,6 @@ export class Util extends null { public static archivedThreadSweepFilter(lifetime?: number): SweepFilter; public static basename(path: string, ext?: string): string; 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): string; public static cloneObject(obj: unknown): unknown; public static discordSort( collection: Collection,