From b8c436731ce21c7e7025290cf29fab1c956e3906 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Thu, 29 Apr 2021 01:00:06 +0300 Subject: [PATCH] Change -allow-mentions to enable all mentions in !post Previously -allow-mentions toggled mentioned roles mentionable and then back after the message was posted. This was somewhat unintuitive. --- backend/src/plugins/Post/util/postMessage.ts | 33 +++++--------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/backend/src/plugins/Post/util/postMessage.ts b/backend/src/plugins/Post/util/postMessage.ts index b26446e5..97726869 100644 --- a/backend/src/plugins/Post/util/postMessage.ts +++ b/backend/src/plugins/Post/util/postMessage.ts @@ -1,7 +1,7 @@ import { GuildPluginData } from "knub"; import { PostPluginType } from "../types"; -import { TextChannel, MessageContent, Attachment, Message, Role } from "eris"; -import { downloadFile, getRoleMentions } from "../../../utils"; +import { Attachment, Message, MessageContent, TextChannel } from "eris"; +import { downloadFile } from "../../../utils"; import fs from "fs"; import { formatContent } from "./formatContent"; @@ -32,34 +32,17 @@ export async function postMessage( }; } - const rolesMadeMentionable: Role[] = []; - if (enableMentions && content.content) { - const mentionedRoleIds = getRoleMentions(content.content); - if (mentionedRoleIds != null) { - for (const roleId of mentionedRoleIds) { - const role = pluginData.guild.roles.get(roleId); - if (role && !role.mentionable) { - await role.edit({ - mentionable: true, - }); - rolesMadeMentionable.push(role); - } - } - } - - content.allowedMentions = content.allowedMentions || {}; - content.allowedMentions.everyone = false; + if (enableMentions) { + content.allowedMentions = { + everyone: true, + users: true, + roles: true, + }; } const createdMsg = await channel.createMessage(content, file); pluginData.state.savedMessages.setPermanent(createdMsg.id); - for (const role of rolesMadeMentionable) { - role.edit({ - mentionable: false, - }); - } - if (downloadedAttachment) { downloadedAttachment.deleteFn(); }