From 775a459deefa1d1590d890649cab8c4b8e011261 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 24 Jan 2024 23:00:19 +0200 Subject: [PATCH] Option to disable automatic logging of infractions --- @types/Settings.ts | 3 ++- src/client/components/observers/AuditLog.ts | 16 ++++++++---- .../components/settings/logging/Moderation.ts | 26 ++++++++++++++----- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/@types/Settings.ts b/@types/Settings.ts index 91d26b2..f4a2aef 100644 --- a/@types/Settings.ts +++ b/@types/Settings.ts @@ -33,7 +33,8 @@ export type ModerationSettings = { channel: Snowflake | null, infractions: InfractionType[], anonymous: boolean, - enabled: boolean + enabled: boolean, + autolog: boolean, } export type DMInfractionSettings = { diff --git a/src/client/components/observers/AuditLog.ts b/src/client/components/observers/AuditLog.ts index a4d86e9..02be2b6 100644 --- a/src/client/components/observers/AuditLog.ts +++ b/src/client/components/observers/AuditLog.ts @@ -26,7 +26,7 @@ class AuditLogObserver extends Observer async guildBanAdd ({ user, guildWrapper: guild }: ExtendedGuildBan) { const settings = await guild.settings(); - if (!settings.moderation.channel || !settings.moderation.infractions.includes('BAN')) + if (!settings.moderation.channel || !settings.moderation.infractions.includes('BAN') || !settings.moderation.autolog) return; // This is checked by the infraction handling, but it may save resources if checked earlier. const audit = await this._fetchFirstEntry(guild, user, 'MemberBanAdd'); if (!audit) @@ -46,7 +46,7 @@ class AuditLogObserver extends Observer async guildBanRemove ({ user, guildWrapper: wrapper }: ExtendedGuildBan) { const settings = await wrapper.settings(); - if (!settings.moderation.channel || !settings.moderation.infractions.includes('UNBAN')) + if (!settings.moderation.channel || !settings.moderation.infractions.includes('UNBAN') || !settings.moderation.autolog) return; // This is checked by the infraction handling, but it may save resources if checked earlier. const audit = await this._fetchFirstEntry(wrapper, user, 'MemberBanRemove'); if (!audit) @@ -67,7 +67,7 @@ class AuditLogObserver extends Observer { const { guildWrapper: wrapper } = member; const settings = await wrapper.settings(); - if (!settings.moderation.channel || !settings.moderation.infractions.includes('KICK')) + if (!settings.moderation.channel || !settings.moderation.infractions.includes('KICK') || !settings.moderation.autolog) return; // This is checked by the infraction handling, but it may save resources if checked earlier. const audit = await this._fetchFirstEntry(wrapper, member.user, 'MemberKick'); if (!audit) @@ -101,7 +101,10 @@ class AuditLogObserver extends Observer { const { guild: wrapper } = newMember; const settings = await wrapper.settings(); - if (!settings.moderation.channel) + if (!settings.moderation.channel + || !settings.moderation.infractions.includes('MUTE') + || !settings.moderation.infractions.includes('UNMUTE') + || !settings.moderation.autolog) return; // console.log(oldMember.communicationDisabledUntilTimestamp, newMember.communicationDisabledUntilTimestamp); @@ -152,7 +155,10 @@ class AuditLogObserver extends Observer { const { guild: wrapper } = newMember; const settings = await wrapper.settings(); - if (!settings.moderation.channel) + if (!settings.moderation.channel + || !settings.moderation.infractions.includes('MUTE') + || !settings.moderation.infractions.includes('UNMUTE') + || !settings.moderation.autolog) return; const mutedRole = settings.mute.role; diff --git a/src/client/components/settings/logging/Moderation.ts b/src/client/components/settings/logging/Moderation.ts index 180ab03..cc52d10 100644 --- a/src/client/components/settings/logging/Moderation.ts +++ b/src/client/components/settings/logging/Moderation.ts @@ -42,7 +42,8 @@ class ModerationLog extends Setting channel: null, infractions: Infractions, anonymous: false, - enabled: false + enabled: false, + autoLog: true, }, definitions: { channel: 'GUILD_TEXT', @@ -53,7 +54,15 @@ class ModerationLog extends Setting commandOptions: [ { name: 'enabled', - description: 'Enable/disable member logs', + description: 'Enable/disable infraction logging', + type: CommandOptionType.BOOLEAN, + flag: true, + valueOptional: true, + defaultValue: true + }, + { + name: 'autolog', + description: 'Enable/disable automatic logging of non-bot actions', type: CommandOptionType.BOOLEAN, flag: true, valueOptional: true, @@ -89,10 +98,17 @@ class ModerationLog extends Setting async execute (invoker: InvokerWrapper, opts: CommandParams, setting: ModerationSettings) { - const { channel, infractions, anonymous, enabled } = opts, + const { channel, infractions, anonymous, enabled, autolog } = opts, langParams: FormatParams = {}; let index = 'SETTING_SUCCESS_ALT'; + if (enabled) + setting.enabled = enabled.asBool; + if (anonymous) + setting.anonymous = anonymous.asBool; + if (autolog) + setting.autolog = autolog.asBool; + if (channel) { const ch = channel.asChannel; @@ -102,10 +118,6 @@ class ModerationLog extends Setting return { error: true, index: 'ERR_BOT_MISSING_PERMISSIONS', params: { missing: missing?.join(', ') || 'Any' } }; setting.channel = channel.asChannel.id; } - if (enabled) - setting.enabled = enabled.asBool; - if (anonymous) - setting.anonymous = anonymous.asBool; if (infractions) {