mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: Remove Util.removeMentions() (#6530)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { parse } = require('node:path');
|
const { parse } = require('node:path');
|
||||||
const process = require('node:process');
|
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const { Colors, Endpoints } = require('./Constants');
|
const { Colors, Endpoints } = require('./Constants');
|
||||||
@@ -9,8 +8,6 @@ const Options = require('./Options');
|
|||||||
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||||
const isObject = d => typeof d === 'object' && d !== null;
|
const isObject = d => typeof d === 'object' && d !== null;
|
||||||
|
|
||||||
let deprecationEmittedForRemoveMentions = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains various general-purpose utility methods.
|
* Contains various general-purpose utility methods.
|
||||||
*/
|
*/
|
||||||
@@ -521,34 +518,8 @@ class Util extends null {
|
|||||||
const res = parse(path);
|
const res = parse(path);
|
||||||
return ext && res.ext.startsWith(ext) ? res.name : res.base.split('?')[0];
|
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.
|
* The content to have all mentions replaced by the equivalent text.
|
||||||
* <warn>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.</warn>
|
|
||||||
* @param {string} str The string to be converted
|
* @param {string} str The string to be converted
|
||||||
* @param {TextBasedChannels} channel The channel the string was sent in
|
* @param {TextBasedChannels} channel The channel the string was sent in
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@@ -559,15 +530,15 @@ class Util extends null {
|
|||||||
const id = input.replace(/<|!|>|@/g, '');
|
const id = input.replace(/<|!|>|@/g, '');
|
||||||
if (channel.type === 'DM') {
|
if (channel.type === 'DM') {
|
||||||
const user = channel.client.users.cache.get(id);
|
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);
|
const member = channel.guild.members.cache.get(id);
|
||||||
if (member) {
|
if (member) {
|
||||||
return Util._removeMentions(`@${member.displayName}`);
|
return `@${member.displayName}`;
|
||||||
} else {
|
} else {
|
||||||
const user = channel.client.users.cache.get(id);
|
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 => {
|
.replace(/<#[0-9]+>/g, input => {
|
||||||
|
|||||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -2416,9 +2416,6 @@ export class Util extends null {
|
|||||||
public static archivedThreadSweepFilter<K, V>(lifetime?: number): SweepFilter<K, V>;
|
public static archivedThreadSweepFilter<K, V>(lifetime?: number): SweepFilter<K, V>;
|
||||||
public static basename(path: string, ext?: string): string;
|
public static basename(path: string, ext?: string): string;
|
||||||
public static cleanContent(str: string, channel: TextBasedChannel): 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 cloneObject(obj: unknown): unknown;
|
||||||
public static discordSort<K, V extends { rawPosition: number; id: Snowflake }>(
|
public static discordSort<K, V extends { rawPosition: number; id: Snowflake }>(
|
||||||
collection: Collection<K, V>,
|
collection: Collection<K, V>,
|
||||||
|
|||||||
Reference in New Issue
Block a user