3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 04:25:01 +00:00

More work on permission utils and eager permission checks

This commit is contained in:
Dragory 2020-08-07 01:21:31 +03:00
parent 8af64a6944
commit 6d4a7cdafd
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
11 changed files with 189 additions and 79 deletions

View file

@ -4,7 +4,9 @@ import { LogType } from "src/data/LogType";
import { logger } from "../../../logger";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { Constants, GuildChannel } from "eris";
import { memberHasChannelPermissions } from "../../../utils/memberHasChannelPermissions";
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
import { missingPermissionError } from "../../../utils/missingPermissionError";
const p = Constants.Permissions;
@ -17,16 +19,16 @@ export const AddReactionsEvt = autoReactionsEvt({
const autoReaction = await pluginData.state.autoReactions.getForChannel(message.channel.id);
if (!autoReaction) return;
if (
!memberHasChannelPermissions(message.member, message.channel as GuildChannel, [
p.readMessages,
p.readMessageHistory,
p.addReactions,
])
) {
const me = pluginData.guild.members.get(pluginData.client.user.id);
const missingPermissions = getMissingChannelPermissions(
me,
message.channel as GuildChannel,
readChannelPermissions | p.addReactions,
);
if (missingPermissions) {
const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to apply auto-reactions in <#${message.channel.id}>. Ensure I can read messages, read message history, and add reactions.`,
body: `Cannot apply auto-reactions in <#${message.channel.id}>. ${missingPermissionError(missingPermissions)}`,
});
return;
}