From 6f9d07f2c5c377750a13f624716ecb8419390d87 Mon Sep 17 00:00:00 2001 From: Skillz Date: Tue, 14 Jul 2020 14:30:15 -0400 Subject: [PATCH] add allowed mentions support --- handlers/channel.ts | 26 ++++++++++++++++++++++++++ types/channel.ts | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/handlers/channel.ts b/handlers/channel.ts index ee0f3f89d..71b34ec3a 100644 --- a/handlers/channel.ts +++ b/handlers/channel.ts @@ -134,6 +134,32 @@ export async function sendMessage( throw new Error(Errors.MESSAGE_MAX_LENGTH); } + if (content.mentions) { + if (content.mentions.users?.length) { + if (content.mentions.parse.includes("users")) { + content.mentions.parse = content.mentions.parse.filter((p) => + p !== "users" + ); + } + + if (content.mentions.users.length > 100) { + content.mentions.users = content.mentions.users.slice(0, 100); + } + } + + if (content.mentions.roles?.length) { + if (content.mentions.parse.includes("roles")) { + content.mentions.parse = content.mentions.parse.filter((p) => + p !== "roles" + ); + } + + if (content.mentions.roles.length > 100) { + content.mentions.roles = content.mentions.roles.slice(0, 100); + } + } + } + const result = await RequestManager.post( endpoints.CHANNEL_MESSAGES(channel.id), content, diff --git a/types/channel.ts b/types/channel.ts index 93be9766b..a3eb7f5ab 100644 --- a/types/channel.ts +++ b/types/channel.ts @@ -105,6 +105,14 @@ export enum ChannelTypes { // } export interface MessageContent { + mentions?: { + /** An array of allowed mention types to parse from the content. */ + parse: ("roles" | "users" | "everyone")[], + /** Array of role_ids to mention (Max size of 100) */ + roles?: string[], + /** Array of user_ids to mention (Max size of 100) */ + users?: string[] + }, /** The message contents, up to 2000 characters */ content?: string; /** A nonce that can be used for optimistic message sending. */