From b0df86692f7d164482973205f5c1e3a9ef85c246 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Thu, 28 Nov 2019 18:34:48 +0200 Subject: [PATCH] automod: simplify preprocessStaticConfig --- backend/src/plugins/Automod.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/Automod.ts b/backend/src/plugins/Automod.ts index 1ddac0a8..413c7460 100644 --- a/backend/src/plugins/Automod.ts +++ b/backend/src/plugins/Automod.ts @@ -12,6 +12,7 @@ import { noop, SECONDS, stripObjectToScalars, + tDeepPartial, tNullable, UnknownUser, verboseChannelMention, @@ -297,6 +298,8 @@ const ConfigSchema = t.type({ }); type TConfigSchema = t.TypeOf; +const PartialConfigSchema = tDeepPartial(ConfigSchema); + /** * DEFAULTS */ @@ -499,12 +502,10 @@ export class AutomodPlugin extends ZeppelinPlugin { protected archives: GuildArchives; protected guildLogs: GuildLogs; - protected static preprocessStaticConfig(config) { - if (config.rules && typeof config.rules === "object") { + protected static preprocessStaticConfig(config: t.TypeOf) { + if (config.rules) { // Loop through each rule for (const [name, rule] of Object.entries(config.rules)) { - if (rule == null || typeof rule !== "object") continue; - rule["name"] = name; // If the rule doesn't have an explicitly set "enabled" property, set it to true @@ -513,12 +514,11 @@ export class AutomodPlugin extends ZeppelinPlugin { } // Loop through the rule's triggers - if (rule["triggers"] != null && Array.isArray(rule["triggers"])) { + if (rule["triggers"]) { for (const trigger of rule["triggers"]) { - if (trigger == null || typeof trigger !== "object") continue; // Apply default config to the triggers used in this rule for (const [defaultTriggerName, defaultTrigger] of Object.entries(defaultTriggers)) { - if (trigger[defaultTriggerName] && typeof trigger[defaultTriggerName] === "object") { + if (trigger[defaultTriggerName]) { trigger[defaultTriggerName] = configUtils.mergeConfig({}, defaultTrigger, trigger[defaultTriggerName]); } } @@ -526,7 +526,7 @@ export class AutomodPlugin extends ZeppelinPlugin { } // Enable logging of automod actions by default - if (rule["actions"] && typeof rule["actions"] === "object") { + if (rule["actions"]) { if (rule["actions"]["log"] == null) { rule["actions"]["log"] = true; }