(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
@@ -801,12 +801,15 @@ namespace Discord.WebSocket
|
||||
/// </summary>
|
||||
/// <param name="limit">The number of audit log entries to fetch.</param>
|
||||
/// <param name="options">The options to be used when sending the request.</param>
|
||||
/// <param name="beforeId">The audit log entry ID to filter entries before.</param>
|
||||
/// <param name="actionType">The type of actions to filter.</param>
|
||||
/// <param name="userId">The user ID to filter entries for.</param>
|
||||
/// <returns>
|
||||
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
|
||||
/// of the requested audit log entries.
|
||||
/// </returns>
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null)
|
||||
=> GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestAuditLogEntry>> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null)
|
||||
=> GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType);
|
||||
|
||||
//Webhooks
|
||||
/// <summary>
|
||||
@@ -1160,10 +1163,11 @@ namespace Discord.WebSocket
|
||||
=> Task.FromResult<IGuildUser>(Owner);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options)
|
||||
async Task<IReadOnlyCollection<IAuditLogEntry>> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options,
|
||||
ulong? beforeId, ulong? userId, ActionType? actionType)
|
||||
{
|
||||
if (cacheMode == CacheMode.AllowDownload)
|
||||
return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
|
||||
return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
|
||||
else
|
||||
return ImmutableArray.Create<IAuditLogEntry>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user