Implementation
Future<List<AuditLogEntry>> list({Snowflake? userId, AuditLogEvent? type, Snowflake? before, Snowflake? after, int? limit}) async {
final route = HttpRoute()
..guilds(id: guildId.toString())
..auditLogs();
final request = BasicRequest(route, queryParameters: {
if (userId != null) 'user_id': userId.toString(),
if (type != null) 'action_type': type.value.toString(),
if (before != null) 'before': before.toString(),
if (after != null) 'after': after.toString(),
if (limit != null) 'limit': limit.toString(),
});
final response = await client.httpHandler.executeSafe(request);
final responseBody = response.jsonBody as Map<String, Object?>;
final entries = parseMany(responseBody['audit_log_entries'] as List<Object?>, parse);
final applicationCommands = parseMany(responseBody['application_commands'] as List<Object?>, (Map<String, Object?> raw) {
final guildId = maybeParse(raw['guild_id'], Snowflake.parse);
if (guildId == null) {
return client.commands.parse(raw);
}
return client.guilds[guildId].commands.parse(raw);
});
applicationCommands.forEach(client.updateCacheWith);
final autoModerationRules = parseMany(responseBody['auto_moderation_rules'] as List<Object?>, client.guilds[guildId].autoModerationRules.parse);
autoModerationRules.forEach(client.updateCacheWith);
final scheduledEvents = parseMany(responseBody['guild_scheduled_events'] as List<Object?>, client.guilds[guildId].scheduledEvents.parse);
scheduledEvents.forEach(client.updateCacheWith);
final threads = parseMany(responseBody['threads'] as List<Object?>, client.channels.parse);
threads.forEach(client.updateCacheWith);
final users = parseMany(responseBody['users'] as List<Object?>, client.users.parse);
users.forEach(client.updateCacheWith);
final webhooks = parseMany(responseBody['webhooks'] as List<Object?>, client.webhooks.parse);
webhooks.forEach(client.updateCacheWith);
entries.forEach(client.updateCacheWith);
return entries;
}