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

@@ -91,8 +91,16 @@ class APIMessage {
const disableMentions = typeof this.options.disableMentions === 'undefined' ?
this.target.client.options.disableMentions :
this.options.disableMentions;
if (disableMentions) {
if (disableMentions === 'all') {
content = Util.removeMentions(content || '');
} else if (disableMentions === 'everyone') {
content = (content || '').replace(/@([^<>@ ]*)/gsmu, (match, target) => {
if (target.match(/^[&!]?\d+$/)) {
return `@${target}`;
} else {
return `@\u200b${target}`;
}
});
}
const isSplit = typeof this.options.split !== 'undefined' && this.options.split !== false;

View File

@@ -85,8 +85,8 @@ class Webhook {
* @property {string} [nonce=''] The nonce for the message
* @property {Object[]} [embeds] An array of embeds for the message
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
* @property {boolean} [disableMentions=this.client.options.disableMentions] Whether or not a zero width space
* should be placed after every @ character to prevent unexpected mentions
* @property {'none' | 'all' | 'everyone'} [disableMentions=this.client.options.disableMentions] Whether or not
* all mentions or everyone/here mentions should be sanitized to prevent unexpected mentions
* @property {FileOptions[]|string[]} [files] Files to send with the message
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if

View File

@@ -57,8 +57,8 @@ class TextBasedChannel {
* @property {string} [content=''] The content for the message
* @property {MessageEmbed|Object} [embed] An embed for the message
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
* @property {boolean} [disableMentions=this.client.options.disableMentions] Whether or not a zero width space
* should be placed after every @ character to prevent unexpected mentions
* @property {'none' | 'all' | 'everyone'} [disableMentions=this.client.options.disableMentions] Whether or not
* all mentionsor everyone/here mentions should be sanitized to prevent unexpected mentions
* @property {FileOptions[]|BufferResolvable[]} [files] Files to send with the message
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if