diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index b5f70a7c..dbee0835 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -429,7 +429,7 @@ namespace Discord /// /// /// - /// The returned collection is an asynchronous enumerable object; one must call + /// The returned collection is an asynchronous enumerable object; one must call /// to access the individual messages as a /// collection. /// @@ -449,7 +449,7 @@ namespace Discord /// /// /// - /// The returned collection is an asynchronous enumerable object; one must call + /// The returned collection is an asynchronous enumerable object; one must call /// to access the individual messages as a /// collection. /// @@ -471,7 +471,7 @@ namespace Discord /// /// /// - /// The returned collection is an asynchronous enumerable object; one must call + /// The returned collection is an asynchronous enumerable object; one must call /// to access the individual messages as a /// collection. /// @@ -1003,13 +1003,14 @@ namespace Discord /// The audit log entry ID to get entries before. /// The type of actions to filter. /// The user ID to filter entries for. + /// The audit log entry ID to get entries after. /// /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of the requested audit log entries. /// Task> GetAuditLogsAsync(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, - ActionType? actionType = null); + ActionType? actionType = null, ulong? afterId = null); /// /// Gets a webhook found within this guild. diff --git a/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs b/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs index f136fa7a..a697db31 100644 --- a/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs +++ b/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs @@ -4,6 +4,7 @@ namespace Discord.API.Rest { public Optional Limit { get; set; } public Optional BeforeEntryId { get; set; } + public Optional AfterEntryId { get; set; } public Optional UserId { get; set; } public Optional ActionType { get; set; } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 8936aba3..cd7d18a4 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -2331,6 +2331,11 @@ namespace Discord.API queryArgs.Append("&action_type=") .Append(args.ActionType.Value); } + if (args.AfterEntryId.IsSpecified) + { + queryArgs.Append("&after=") + .Append(args.AfterEntryId); + } // Still use string interpolation for the query w/o params, as this is necessary for CreateBucketId endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}{queryArgs.ToString()}"; diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 323584c8..32357f1c 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -611,7 +611,7 @@ namespace Discord.Rest #region Audit logs public static IAsyncEnumerable> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client, - ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null) + ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null, ulong? afterId = null) { return new PagedAsyncEnumerable( DiscordConfig.MaxAuditLogEntriesPerBatch, @@ -627,6 +627,8 @@ namespace Discord.Rest args.UserId = userId.Value; if (actionType.HasValue) args.ActionType = (int)actionType.Value; + if (afterId.HasValue) + args.AfterEntryId = afterId.Value; var model = await client.ApiClient.GetAuditLogsAsync(guild.Id, args, options); return model.Entries.Select((x) => RestAuditLogEntry.Create(client, model, x)).ToImmutableArray(); }, @@ -1081,7 +1083,7 @@ namespace Discord.Rest throw new ArgumentException("Name of the rule must not be empty", paramName: nameof(args.Name)); Preconditions.AtLeast(1, args.Actions.GetValueOrDefault(Array.Empty()).Length, nameof(args.Actions), "Auto moderation rule must have at least 1 action"); - + if (args.RegexPatterns.IsSpecified) { if (args.TriggerType.Value is not AutoModTriggerType.Keyword) @@ -1122,10 +1124,10 @@ namespace Discord.Rest throw new ArgumentException(message: $"Allow list entry length must be less than or equal to {AutoModRuleProperties.MaxAllowListEntryLength}.", paramName: nameof(args.AllowList)); } - + if (args.TriggerType.Value is not AutoModTriggerType.KeywordPreset && args.Presets.IsSpecified) throw new ArgumentException(message: $"Keyword presets scan only be used with 'KeywordPreset' trigger type.", paramName: nameof(args.Presets)); - + if (args.MentionLimit.IsSpecified) { if (args.TriggerType.Value is AutoModTriggerType.MentionSpam) diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index 058e6acb..e35f1bc9 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -914,12 +914,13 @@ namespace Discord.Rest /// The audit log entry ID to get entries before. /// The type of actions to filter. /// The user ID to filter entries for. + /// The audit log entry ID to get entries after. /// /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of the requested audit log entries. /// - public IAsyncEnumerable> 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); + public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null, ulong? afterId = null) + => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType, afterId: afterId); #endregion #region Webhooks @@ -1508,10 +1509,10 @@ namespace Discord.Rest } async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options, - ulong? beforeId, ulong? userId, ActionType? actionType) + ulong? beforeId, ulong? userId, ActionType? actionType, ulong? afterId) { if (cacheMode == CacheMode.AllowDownload) - return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); + return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType, afterId: afterId).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); else return ImmutableArray.Create(); } diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index 6d21fec8..9f5cf4d1 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -1397,12 +1397,13 @@ namespace Discord.WebSocket /// The audit log entry ID to filter entries before. /// The type of actions to filter. /// The user ID to filter entries for. + /// The audit log entry ID to filter entries after. /// /// A task that represents the asynchronous get operation. The task result contains a read-only collection /// of the requested audit log entries. /// - public IAsyncEnumerable> 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); + public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null, ulong? afterId = null) + => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType, afterId: afterId); #endregion #region Webhooks @@ -2093,10 +2094,10 @@ namespace Discord.WebSocket /// async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options, - ulong? beforeId, ulong? userId, ActionType? actionType) + ulong? beforeId, ulong? userId, ActionType? actionType, ulong? afterId) { if (cacheMode == CacheMode.AllowDownload) - return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); + return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType, afterId: afterId).FlattenAsync().ConfigureAwait(false)).ToImmutableArray(); else return ImmutableArray.Create(); }