3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +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 { GuildPluginData } from "knub";
import { PostPluginType } from "../types"; import { PostPluginType } from "../types";
import { TextChannel, MessageContent, Attachment, Message, Role } from "eris"; import { Attachment, Message, MessageContent, TextChannel } from "eris";
import { downloadFile, getRoleMentions } from "../../../utils"; import { downloadFile } from "../../../utils";
import fs from "fs"; import fs from "fs";
import { formatContent } from "./formatContent"; import { formatContent } from "./formatContent";
@ -32,34 +32,17 @@ export async function postMessage(
}; };
} }
const rolesMadeMentionable: Role[] = []; if (enableMentions) {
if (enableMentions && content.content) { content.allowedMentions = {
const mentionedRoleIds = getRoleMentions(content.content); everyone: true,
if (mentionedRoleIds != null) { users: true,
for (const roleId of mentionedRoleIds) { roles: true,
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;
} }
const createdMsg = await channel.createMessage(content, file); const createdMsg = await channel.createMessage(content, file);
pluginData.state.savedMessages.setPermanent(createdMsg.id); pluginData.state.savedMessages.setPermanent(createdMsg.id);
for (const role of rolesMadeMentionable) {
role.edit({
mentionable: false,
});
}
if (downloadedAttachment) { if (downloadedAttachment) {
downloadedAttachment.deleteFn(); downloadedAttachment.deleteFn();
} }