feat: reimplement disableEveryone into disableMentions

* User input sanitation: reimplement disableEveryone into disableMentions

* Change default value of ClientOptions#disableMentions to 'none'

* Update type declarations of disableMentions to include default

* update for compliance with ESLint

* Overlooked these files. Updated for complete compliance with ESLint
This commit is contained in:
Papa
2020-02-29 06:20:39 -07:00
committed by GitHub
parent bbe169deac
commit 9c8aaf1bbc
8 changed files with 51 additions and 29 deletions

View File

@@ -534,22 +534,30 @@ class Util {
* @returns {string}
*/
static cleanContent(str, message) {
return Util.removeMentions(str
.replace(/<@!?[0-9]+>/g, input => {
const id = input.replace(/<|!|>|@/g, '');
if (message.channel.type === 'dm') {
const user = message.client.users.cache.get(id);
return user ? `@${user.username}` : input;
}
const member = message.channel.guild.members.cache.get(id);
if (member) {
return `@${member.displayName}`;
if (message.client.options.disableMentions === 'everyone') {
str = str.replace(/@([^<>@ ]*)/gsmu, (match, target) => {
if (target.match(/^[&!]?\d+$/)) {
return `@${target}`;
} else {
const user = message.client.users.cache.get(id);
return user ? `@${user.username}` : input;
return `@\u200b${target}`;
}
})
});
}
str = str.replace(/<@!?[0-9]+>/g, input => {
const id = input.replace(/<|!|>|@/g, '');
if (message.channel.type === 'dm') {
const user = message.client.users.cache.get(id);
return user ? `@${user.username}` : input;
}
const member = message.channel.guild.members.cache.get(id);
if (member) {
return `@${member.displayName}`;
} else {
const user = message.client.users.cache.get(id);
return user ? `@${user.username}` : input;
}
})
.replace(/<#[0-9]+>/g, input => {
const channel = message.client.channels.cache.get(input.replace(/<|#|>/g, ''));
return channel ? `#${channel.name}` : input;
@@ -558,7 +566,12 @@ class Util {
if (message.channel.type === 'dm') return input;
const role = message.guild.roles.cache.get(input.replace(/<|@|>|&/g, ''));
return role ? `@${role.name}` : input;
}));
});
if (message.client.options.disableMentions === 'all') {
return Util.removeMentions(str);
} else {
return str;
}
}
/**