mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: move Message#cleanContent function to Util (#2703)
* refactor: move Message#cleanContent function to Util * suggested changes
This commit is contained in:
@@ -257,35 +257,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get cleanContent() {
|
||||
return this.content
|
||||
.replace(/@(everyone|here)/g, '@\u200b$1')
|
||||
.replace(/<@!?[0-9]+>/g, input => {
|
||||
const id = input.replace(/<|!|>|@/g, '');
|
||||
if (this.channel.type === 'dm' || this.channel.type === 'group') {
|
||||
return this.client.users.has(id) ? `@${this.client.users.get(id).username}` : input;
|
||||
}
|
||||
|
||||
const member = this.channel.guild.members.get(id);
|
||||
if (member) {
|
||||
if (member.nickname) return `@${member.nickname}`;
|
||||
return `@${member.user.username}`;
|
||||
} else {
|
||||
const user = this.client.users.get(id);
|
||||
if (user) return `@${user.username}`;
|
||||
return input;
|
||||
}
|
||||
})
|
||||
.replace(/<#[0-9]+>/g, input => {
|
||||
const channel = this.client.channels.get(input.replace(/<|#|>/g, ''));
|
||||
if (channel) return `#${channel.name}`;
|
||||
return input;
|
||||
})
|
||||
.replace(/<@&[0-9]+>/g, input => {
|
||||
if (this.channel.type === 'dm' || this.channel.type === 'group') return input;
|
||||
const role = this.guild.roles.get(input.replace(/<|@|>|&/g, ''));
|
||||
if (role) return `@${role.name}`;
|
||||
return input;
|
||||
});
|
||||
return Util.cleanContent(this.content, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user