From 41078997aefce2a9e683b9805aad6436612a3aa7 Mon Sep 17 00:00:00 2001 From: Advaith Date: Mon, 14 Dec 2020 04:51:31 -0800 Subject: [PATCH] feat(APIMessage): remove disableMentions (#4836) * chore: remove disableMentions * style: fix eslint --- src/client/Client.js | 3 -- src/structures/APIMessage.js | 16 ------- src/structures/Webhook.js | 2 - src/structures/interfaces/TextBasedChannel.js | 10 ----- src/util/Constants.js | 2 - src/util/Util.js | 15 +------ test/disableMentions.js | 44 ------------------- typings/index.d.ts | 3 -- 8 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 test/disableMentions.js diff --git a/src/client/Client.js b/src/client/Client.js index f3fd68a20..5972f20c5 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -470,9 +470,6 @@ class Client extends BaseClient { if (typeof options.fetchAllMembers !== 'boolean') { throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean'); } - if (typeof options.disableMentions !== 'string') { - throw new TypeError('CLIENT_INVALID_OPTION', 'disableMentions', 'a string'); - } if (!Array.isArray(options.partials)) { throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array'); } diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index bd7cc610e..1ddf67fa6 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -88,22 +88,6 @@ class APIMessage { if (typeof content !== 'string') return content; - const disableMentions = - typeof this.options.disableMentions === 'undefined' - ? this.target.client.options.disableMentions - : this.options.disableMentions; - if (disableMentions === 'all') { - content = Util.removeMentions(content); - } else if (disableMentions === 'everyone') { - content = content.replace(/@([^<>@ ]*)/gmsu, (match, target) => { - if (target.match(/^[&!]?\d+$/)) { - return `@${target}`; - } else { - return `@\u200b${target}`; - } - }); - } - 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; diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index d0cf7c6e6..c51b3b2a0 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -86,8 +86,6 @@ class Webhook { * @property {Object[]} [embeds] An array of embeds for the message * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details) - * @property {DisableMentionType} [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 diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index b47409e61..744fecf8a 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -59,8 +59,6 @@ class TextBasedChannel { * @property {MessageEmbed|Object} [embed] An embed for the message * (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details) * @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content - * @property {DisableMentionType} [disableMentions=this.client.options.disableMentions] Whether or not all mentions or - * 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 @@ -85,14 +83,6 @@ class TextBasedChannel { * @typedef {string} MessageMentionTypes */ - /** - * The type of mentions to disable. - * - `none` - * - `all` - * - `everyone` - * @typedef {string} DisableMentionType - */ - /** * @typedef {Object} FileOptions * @property {BufferResolvable} attachment File to attach diff --git a/src/util/Constants.js b/src/util/Constants.js index 84a1599f2..f1c61d126 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -23,7 +23,6 @@ const browser = (exports.browser = typeof window !== 'undefined'); * (-1 or Infinity for unlimited - don't do this without sweeping, otherwise memory usage may climb indefinitely.) * @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as * upon joining a guild (should be avoided whenever possible) - * @property {DisableMentionType} [disableMentions='none'] Default value for {@link MessageOptions#disableMentions} * @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions} * @property {PartialType[]} [partials] Structures allowed to be partial. This means events can be emitted even when * they're missing all the data for a particular structure. See the "Partials" topic listed in the sidebar for some @@ -47,7 +46,6 @@ exports.DefaultOptions = { messageSweepInterval: 0, messageEditHistoryMaxSize: -1, fetchAllMembers: false, - disableMentions: 'none', partials: [], restWsBridgeTimeout: 5000, restRequestTimeout: 15000, diff --git a/src/util/Util.js b/src/util/Util.js index d1909fd95..a583649d6 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -584,20 +584,7 @@ class Util { const role = message.guild.roles.cache.get(input.replace(/<|@|>|&/g, '')); return role ? `@${role.name}` : input; }); - if (message.client.options.disableMentions === 'everyone') { - str = str.replace(/@([^<>@ ]*)/gmsu, (match, target) => { - if (target.match(/^[&!]?\d+$/)) { - return `@${target}`; - } else { - return `@\u200b${target}`; - } - }); - } - if (message.client.options.disableMentions === 'all') { - return Util.removeMentions(str); - } else { - return str; - } + return str; } /** diff --git a/test/disableMentions.js b/test/disableMentions.js deleted file mode 100644 index 0521d34cf..000000000 --- a/test/disableMentions.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -const { token, prefix } = require('./auth'); -const Discord = require('../src'); -const { Util } = Discord; - -const client = new Discord.Client({ - // To see a difference, comment out disableMentions and run the same tests using disableEveryone - // You will notice that all messages will mention @everyone - // disableEveryone: true - disableMentions: 'everyone', -}); - -const tests = [ - // Test 1 - // See https://github.com/discordapp/discord-api-docs/issues/1189 - '@\u202eeveryone @\u202ehere', - - // Test 2 - // See https://github.com/discordapp/discord-api-docs/issues/1241 - // TL;DR: Characters like \u0300 will only be stripped if more than 299 are present - `${'\u0300@'.repeat(150)}@\u0300everyone @\u0300here`, - - // Test 3 - // Normal @everyone/@here mention - '@everyone @here', -]; - -client.on('ready', () => console.log('Ready!')); - -client.on('message', message => { - // Check if message starts with prefix - if (!message.content.startsWith(prefix)) return; - const [command, ...args] = message.content.substr(prefix.length).split(' '); - - // Clean content and log each character - console.log(Util.cleanContent(args.join(' '), message).split('')); - - if (command === 'test1') message.channel.send(tests[0]); - else if (command === 'test2') message.channel.send(tests[1]); - else if (command === 'test3') message.channel.send(tests[2]); -}); - -client.login(token).catch(console.error); diff --git a/typings/index.d.ts b/typings/index.d.ts index 1806074be..8aa824613 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2327,7 +2327,6 @@ declare module 'discord.js' { messageSweepInterval?: number; messageEditHistoryMaxSize?: number; fetchAllMembers?: boolean; - disableMentions?: 'none' | 'all' | 'everyone'; allowedMentions?: MessageMentionOptions; partials?: PartialTypes[]; restWsBridgeTimeout?: number; @@ -2837,7 +2836,6 @@ declare module 'discord.js' { nonce?: string | number; content?: StringResolvable; embed?: MessageEmbed | MessageEmbedOptions; - disableMentions?: 'none' | 'all' | 'everyone'; allowedMentions?: MessageMentionOptions; files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; code?: string | boolean; @@ -3194,7 +3192,6 @@ declare module 'discord.js' { tts?: boolean; nonce?: string; embeds?: (MessageEmbed | object)[]; - disableMentions?: 'none' | 'all' | 'everyone'; allowedMentions?: MessageMentionOptions; files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; code?: string | boolean;