From df324e2c21171aa17bc4e43f4a36f78c2f0eaec1 Mon Sep 17 00:00:00 2001 From: Ryan Munro Date: Thu, 19 Mar 2020 21:56:03 +1100 Subject: [PATCH] =?UTF-8?q?feat(AllowedMentions):=20add=20support=20for=20?= =?UTF-8?q?MessageOptions#allowedMe=E2=80=A6=20(#3893)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(Allowed Mentions): Add support for new Allowed Mentions message options * fix(docs): Update JSDoc for feature * fix(apimessage): translate the propery into snake_case * fix(typings): message mention options should be optional * fix(docs): jsdoc typings for MessageMentionOptions * fix(mentions): use Resolvables for MessageMentionOptions * fix(docs): typedef for MessageMentionTypes * Update typings/index.d.ts Co-Authored-By: Sugden <28943913+NotSugden@users.noreply.github.com> * fix(mentions): drop support for Resolvables * fix(AllowedMentions): remove the whole resolve function * fix(docs): revert change to Resolvables Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> --- src/structures/APIMessage.js | 1 + src/structures/Webhook.js | 1 + src/structures/interfaces/TextBasedChannel.js | 14 ++++++++++++++ typings/index.d.ts | 10 ++++++++++ 4 files changed, 26 insertions(+) diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index a7bf63de4..3c8742558 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -184,6 +184,7 @@ class APIMessage { embeds, username, avatar_url: avatarURL, + allowed_mentions: this.options.allowedMentions, flags, }; return this; diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index d129d6b7b..4dd8d1951 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -84,6 +84,7 @@ class Webhook { * @property {boolean} [tts=false] Whether or not the message should be spoken aloud * @property {string} [nonce=''] The nonce for the message * @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://discordapp.com/developers/docs/resources/channel#embed-object) for more details) * @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 diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index 940ff4b93..609a05050 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -58,6 +58,7 @@ 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 {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content * @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[]|BufferResolvable[]} [files] Files to send with the message @@ -67,6 +68,19 @@ class TextBasedChannel { * @property {UserResolvable} [reply] User to reply to (prefixes the message with a mention, except in DMs) */ + /** + * Options provided to control parsing of mentions by Discord + * @typedef {Object} MessageMentionOptions + * @property {MessageMentionTypes[]} [parse] Types of mentions to be parsed + * @property {Snowflake[]} [users] Snowflakes of Users to be parsed as mentions + * @property {Snowflake[]} [roles] Snowflakes of Roles to be parsed as mentions + */ + + /** + * Types of mentions to enable in MessageMentionOptions + * @typedef {'role' | 'users' | 'everyone'} MessageMentionTypes + */ + /** * @typedef {Object} FileOptions * @property {BufferResolvable} attachment File to attach diff --git a/typings/index.d.ts b/typings/index.d.ts index a5897eba0..4cc9bb698 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2646,12 +2646,21 @@ declare module 'discord.js' { type MessageFlagsString = 'CROSSPOSTED' | 'IS_CROSSPOST' | 'SUPPRESS_EMBEDS' | 'SOURCE_MESSAGE_DELETED' | 'URGENT'; + interface MessageMentionOptions { + parse?: MessageMentionTypes[]; + roles?: Snowflake[]; + users?: Snowflake[]; + } + + type MessageMentionTypes = 'roles' | 'users' | 'everyone'; + interface MessageOptions { tts?: boolean; nonce?: string; content?: string; embed?: MessageEmbed | MessageEmbedOptions; disableMentions?: 'none' | 'all' | 'everyone'; + allowedMentions?: MessageMentionOptions; files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; code?: string | boolean; split?: boolean | SplitOptions; @@ -2971,6 +2980,7 @@ declare module 'discord.js' { nonce?: string; embeds?: (MessageEmbed | object)[]; disableMentions?: 'none' | 'all' | 'everyone'; + allowedMentions?: MessageMentionOptions; files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[]; code?: string | boolean; split?: boolean | SplitOptions;