mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat: replace disableEveryone with disableMentions (#3830)
* add ClientOptions#disableMentions and MessageOptions#disableMentions * provide tests * don't sanitize controlled mentions * add @here mentions to tests * fix indents (6 spaces instead of 8) * add Util#cleanContent tests * add typings for removeMentions * replace @ with @\u200b AFTER cleaning content as suggested instead of using removeMentions * better explanation of this option * no newline in Util.removeMentions * fix long line * remove double space * remove comments (change has been reverted) * Use Util.removeMentions to remove mentions * use Util.removeMentions in Util.cleanContent
This commit is contained in:
@@ -88,6 +88,13 @@ class APIMessage {
|
||||
content = Util.resolveString(this.options.content);
|
||||
}
|
||||
|
||||
const disableMentions = typeof this.options.disableMentions === 'undefined' ?
|
||||
this.target.client.options.disableMentions :
|
||||
this.options.disableMentions;
|
||||
if (disableMentions) {
|
||||
content = Util.removeMentions(content || '');
|
||||
}
|
||||
|
||||
const isSplit = typeof this.options.split !== 'undefined' && this.options.split !== false;
|
||||
const isCode = typeof this.options.code !== 'undefined' && this.options.code !== false;
|
||||
const splitOptions = isSplit ? { ...this.options.split } : undefined;
|
||||
@@ -113,13 +120,6 @@ class APIMessage {
|
||||
content = `${mentionPart}${content || ''}`;
|
||||
}
|
||||
|
||||
const disableEveryone = typeof this.options.disableEveryone === 'undefined' ?
|
||||
this.target.client.options.disableEveryone :
|
||||
this.options.disableEveryone;
|
||||
if (disableEveryone) {
|
||||
content = (content || '').replace(/@(everyone|here)/g, '@\u200b$1');
|
||||
}
|
||||
|
||||
if (isSplit) {
|
||||
content = Util.splitMessage(content || '', splitOptions);
|
||||
}
|
||||
|
||||
@@ -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} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
|
||||
* should be replaced with plain-text
|
||||
* @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 {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
|
||||
|
||||
@@ -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} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
|
||||
* should be replaced with plain-text
|
||||
* @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 {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
|
||||
|
||||
Reference in New Issue
Block a user