mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
Improve cleanContent code
This commit is contained in:
@@ -159,36 +159,29 @@ class Message {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
get cleanContent() {
|
get cleanContent() {
|
||||||
return this.content.replace(/<@!?[0-9]+>/g, input => {
|
return this.content
|
||||||
let user = this.channel.guild.members.get(input.replace(/<|!|>|@/g, ''));
|
.replace(/@everyone/g, '@\u200Beveryone')
|
||||||
|
.replace(/@here/g, '@\u200Bhere')
|
||||||
if (user) {
|
.replace(/<@!?[0-9]+>/g, input => {
|
||||||
if (user.nickname) {
|
const id = input.replace(/<|!|>|@/g, '');
|
||||||
return `@${user.nickname}`;
|
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;
|
||||||
}
|
}
|
||||||
return `@${user.user.username}`;
|
}).replace(/<#[0-9]+>/g, (input) => {
|
||||||
}
|
const channel = this.client.channels.get(input.replace(/<|#|>/g, ''));
|
||||||
|
if (channel) return `#${channel.name}`;
|
||||||
return input;
|
return input;
|
||||||
}).replace(/<#[0-9]+>/g, (input) => {
|
}).replace(/<@&[0-9]+>/g, (input) => {
|
||||||
let channel = this.client.channels.get(input.replace(/<|#|>/g, ''));
|
const role = this.guild.roles.get(input.replace(/<|@|>|&/g, ''));
|
||||||
|
if (role) return `@${role.name}`;
|
||||||
if (channel) {
|
return input;
|
||||||
return `#${channel.name}`;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
}).replace(/<@&[0-9]+>/g, (input) => {
|
|
||||||
let role = this.guild.roles.get(input.replace(/<|@|>|&/g, ''));
|
|
||||||
|
|
||||||
if (role) {
|
|
||||||
return `@${role.name}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
})
|
|
||||||
.replace(/@everyone/g, '@\u200Beveryone')
|
|
||||||
.replace(/@here/g, '@\u200Bhere');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user