Skip to content

Commit

Permalink
Mod log prune members event
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Dec 3, 2024
1 parent afc7dcb commit 4d87cc6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/src/modules/mod_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';

Expand Down

0 comments on commit 4d87cc6

Please sign in to comment.