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

fix: Remove deprecation warning on Message#cleanContent #7143

Merged
merged 3 commits into from Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/util/Util.js
Expand Up @@ -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(
kyranet marked this conversation as resolved.
Show resolved Hide resolved
'The Util.removeMentions method is deprecated. Use MessageOptions#allowedMentions instead.',
'DeprecationWarning',
Expand All @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -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<K, V extends { rawPosition: number; id: Snowflake }>(
collection: Collection<K, V>,
Expand Down