3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

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.
This commit is contained in:
Dragory 2021-04-29 01:00:06 +03:00
parent b541d5d087
commit b8c436731c
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -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();
}