Skip to content

Commit

Permalink
feat(APIMessage): remove disableMentions (#4836)
Browse files Browse the repository at this point in the history
* chore: remove disableMentions

* style: fix eslint
  • Loading branch information
advaith1 committed Dec 14, 2020
1 parent 9c7fe34 commit 4107899
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 94 deletions.
3 changes: 0 additions & 3 deletions src/client/Client.js
Expand Up @@ -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');
}
Expand Down
16 changes: 0 additions & 16 deletions src/structures/APIMessage.js
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/structures/Webhook.js
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/structures/interfaces/TextBasedChannel.js
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/util/Constants.js
Expand Up @@ -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
Expand All @@ -47,7 +46,6 @@ exports.DefaultOptions = {
messageSweepInterval: 0,
messageEditHistoryMaxSize: -1,
fetchAllMembers: false,
disableMentions: 'none',
partials: [],
restWsBridgeTimeout: 5000,
restRequestTimeout: 15000,
Expand Down
15 changes: 1 addition & 14 deletions src/util/Util.js
Expand Up @@ -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;
}

/**
Expand Down
44 changes: 0 additions & 44 deletions test/disableMentions.js

This file was deleted.

3 changes: 0 additions & 3 deletions typings/index.d.ts
Expand Up @@ -2327,7 +2327,6 @@ declare module 'discord.js' {
messageSweepInterval?: number;
messageEditHistoryMaxSize?: number;
fetchAllMembers?: boolean;
disableMentions?: 'none' | 'all' | 'everyone';
allowedMentions?: MessageMentionOptions;
partials?: PartialTypes[];
restWsBridgeTimeout?: number;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4107899

Please sign in to comment.