Improve cleanContent code

This commit is contained in:
Schuyler Cebulskie
2016-09-08 22:05:30 -04:00
parent 9888cef486
commit bbc9df0b0d

View File

@@ -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');
} }
/** /**