(binbrk)feature: Support filtering audit log entries on user, action type, and before entry id (#1377)
* Support filtering audit log entries on user, type, and before id Adds support for filtering audit log entires with GetAuditLogsAsync. Adds the ability to specify a userId and ActionType to filter. Exposes the beforeId filter which was already implemented, yet unused (even when requesting > 100 entries)? Was thinking that this could expose overloads of GetAuditLogAsync that accepts a IUser and IAuditLogEntry, but dealing with all the combinations of these types may be excessive. * use only stringbuilder for args instead of string interpolation
This commit is contained in:
committed by
Christopher F
parent
c54867feba
commit
68eb71c175
@@ -380,7 +380,7 @@ namespace Discord.Rest
|
||||
|
||||
// Audit logs
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong? from, int? limit, RequestOptions options)
|
||||
ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestAuditLogEntry>(
|
||||
DiscordConfig.MaxAuditLogEntriesPerBatch,
|
||||
@@ -392,6 +392,10 @@ namespace Discord.Rest
|
||||
};
|
||||
if (info.Position != null)
|
||||
args.BeforeEntryId = info.Position.Value;
|
||||
if (userId.HasValue)
|
||||
args.UserId = userId.Value;
|
||||
if (actionType.HasValue)
|
||||
args.ActionType = (int)actionType.Value;
|
||||
var model = await client.ApiClient.GetAuditLogsAsync(guild.Id, args, options);
|
||||
return model.Entries.Select((x) => RestAuditLogEntry.Create(client, model, x)).ToImmutableArray();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user