// Audit logs public static IAsyncEnumerable <IReadOnlyCollection <RestAuditLogEntry> > GetAuditLogsAsync(IGuild guild, BaseDiscordClient client, ulong?from, int?limit, RequestOptions options) { return(new PagedAsyncEnumerable <RestAuditLogEntry>( DiscordConfig.MaxAuditLogEntriesPerBatch, async(info, ct) => { var args = new GetAuditLogsParams { Limit = info.PageSize }; if (info.Position != null) { args.BeforeEntryId = info.Position.Value; } var model = await client.ApiClient.GetAuditLogsAsync(guild.Id, args, options); return model.Entries.Select((x) => RestAuditLogEntry.Create(client, model, x)).ToImmutableArray(); }, nextPage: (info, lastPage) => { if (lastPage.Count != DiscordConfig.MaxAuditLogEntriesPerBatch) { return false; } info.Position = lastPage.Min(x => x.Id); return true; }, start: from, count: limit )); }
/// <summary> /// Converts an existing <see cref="RestAuditLogEntry"/> to an abstracted <see cref="IRestAuditLogEntry"/> value. /// </summary> /// <param name="restAuditLogEntry">The existing <see cref="RestAuditLogEntry"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restAuditLogEntry"/>.</exception> /// <returns>An <see cref="IRestAuditLogEntry"/> that abstracts <paramref name="restAuditLogEntry"/>.</returns> public static IRestAuditLogEntry Abstract(this RestAuditLogEntry restAuditLogEntry) => new RestAuditLogEntryAbstraction(restAuditLogEntry);
/// <summary> /// Constructs a new <see cref="RestAuditLogEntryAbstraction"/> around an existing <see cref="Rest.RestAuditLogEntry"/>. /// </summary> /// <param name="restAuditLogEntry">The value to use for <see cref="Rest.RestAuditLogEntry"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restAuditLogEntry"/>.</exception> public RestAuditLogEntryAbstraction(RestAuditLogEntry restAuditLogEntry) { RestAuditLogEntry = restAuditLogEntry ?? throw new ArgumentNullException(nameof(restAuditLogEntry)); }