public static IAsyncEnumerable <IReadOnlyCollection <RestUserGuild> > GetGuildSummariesAsync(BaseDiscordClient client, ulong?fromGuildId, int?limit, RequestOptions options) { return(new PagedAsyncEnumerable <RestUserGuild>( DiscordConfig.MaxGuildsPerBatch, async(info, ct) => { var args = new GetGuildSummariesParams { Limit = info.PageSize }; if (info.Position != null) { args.AfterGuildId = info.Position.Value; } var models = await client.ApiClient.GetMyGuildsAsync(args, options).ConfigureAwait(false); return models .Select(x => RestUserGuild.Create(client, x)) .ToImmutableArray(); }, nextPage: (info, lastPage) => { if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch) { return false; } info.Position = lastPage.Max(x => x.Id); return true; }, start: fromGuildId, count: limit )); }
public static async Task <IReadOnlyCollection <RestUserGuild> > GetGuildSummariesAsync(BaseDiscordClient client) { var models = await client.ApiClient.GetMyGuildsAsync().ConfigureAwait(false); return(models.Select(x => RestUserGuild.Create(client, x)).ToImmutableArray()); }