From 6038996f103840ef071df3bb56449dd83249b04b Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 22 May 2021 14:05:09 +0300 Subject: [PATCH] Add excluded_roles to logs --- backend/src/plugins/Logs/types.ts | 1 + backend/src/plugins/Logs/util/log.ts | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/Logs/types.ts b/backend/src/plugins/Logs/types.ts index 34e4b3d9..5ae37c26 100644 --- a/backend/src/plugins/Logs/types.ts +++ b/backend/src/plugins/Logs/types.ts @@ -21,6 +21,7 @@ const LogChannel = t.partial({ excluded_channels: t.array(t.string), excluded_categories: t.array(t.string), exclude_bots: t.boolean, + excluded_roles: t.array(t.string), format: tNullable(tLogFormats), timestamp_format: t.string, include_embed_timestamp: t.boolean, diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index aed24f3f..7c205579 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -2,11 +2,16 @@ import { GuildPluginData } from "knub"; import { LogsPluginType, TLogChannelMap } from "../types"; import { LogType } from "../../../data/LogType"; import { TextChannel } from "eris"; -import { createChunkedMessage, noop } from "../../../utils"; +import { createChunkedMessage, get, noop } from "../../../utils"; import { getLogMessage } from "./getLogMessage"; import { allowTimeout } from "../../../RegExpRunner"; const excludedUserProps = ["user", "member", "mod"]; +const excludedRoleProps = ["message.member.roles", "member.roles"]; + +function isRoleArray(value: any): value is string[] { + return Array.isArray(value); +} export async function log(pluginData: GuildPluginData, type: LogType, data: any) { const logChannels: TLogChannelMap = pluginData.config.get().channels; @@ -36,6 +41,21 @@ export async function log(pluginData: GuildPluginData, type: Log } } + if (opts.excluded_roles) { + for (const prop of excludedRoleProps) { + const roles = get(data, prop); + if (!isRoleArray(roles)) { + continue; + } + + for (const role of roles) { + if (opts.excluded_roles.includes(role)) { + continue logChannelLoop; + } + } + } + } + // If this entry is from an excluded channel, skip it if (opts.excluded_channels) { if (