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

Add excluded_roles to logs

This commit is contained in:
Dragory 2021-05-22 14:05:09 +03:00
parent eed4fd586b
commit 6038996f10
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 22 additions and 1 deletions

View file

@ -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,

View file

@ -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<LogsPluginType>, type: LogType, data: any) {
const logChannels: TLogChannelMap = pluginData.config.get().channels;
@ -36,6 +41,21 @@ export async function log(pluginData: GuildPluginData<LogsPluginType>, 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 (