From 4d87cc68d199c6eaa71d7f11c1581ac02c65e61b Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Tue, 3 Dec 2024 23:38:45 +0100 Subject: [PATCH] Mod log prune members event --- lib/src/modules/mod_log.dart | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/src/modules/mod_log.dart b/lib/src/modules/mod_log.dart index 8929023..087a453 100644 --- a/lib/src/modules/mod_log.dart +++ b/lib/src/modules/mod_log.dart @@ -63,16 +63,16 @@ class ModLogsModule implements RequiresInitialization { AuditLogEvent.memberKick => 'Kick', AuditLogEvent.memberBanAdd => 'Ban', AuditLogEvent.memberUpdate => 'Timeout Added', + AuditLogEvent.memberPrune => 'Members Pruned', _ => throw UnimplementedError(), }; final messageBuffer = StringBuffer('$eventTypeName | ${DateTime.now().format(TimestampStyle.longDateTime)}') ..writeln('User: ${targetUser.username} (${targetUser.mention})'); - final auditLogChange = auditLogEntry.changes?.first; - if (isMemberTimeoutEntry(auditLogEntry, auditLogChange)) { - final timeoutUntil = DateTime.parse(auditLogChange!.newValue as String); - messageBuffer.writeln("Until: ${timeoutUntil.format(TimestampStyle.relativeTime)}"); + final additionalMessageData = getAdditionalMessageData(auditLogEntry); + if (additionalMessageData != null) { + messageBuffer.writeln(additionalMessageData); } if (auditLogEntry.reason != null) { @@ -87,6 +87,23 @@ class ModLogsModule implements RequiresInitialization { ); } + String? getAdditionalMessageData(AuditLogEntry auditLogEntry) { + final auditLogChange = auditLogEntry.changes?.first; + if (isMemberTimeoutEntry(auditLogEntry, auditLogChange)) { + final timeoutUntil = DateTime.parse(auditLogChange!.newValue as String); + + return "Until: ${timeoutUntil.format(TimestampStyle.relativeTime)}"; + } + + if (auditLogEntry.actionType == AuditLogEvent.memberPrune) { + final membersRemoved = auditLogEntry.options?.membersRemoved ?? '???'; + + return "Pruned count: $membersRemoved"; + } + + return null; + } + bool isMemberTimeoutEntry(AuditLogEntry auditLogEntry, AuditLogChange? auditLogChange) => auditLogEntry.actionType == AuditLogEvent.memberUpdate && auditLogChange?.key == 'communication_disabled_until';