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 )); }
internal static RestUserGuild Create(BaseDiscordClient discord, Model model) { RestUserGuild entity = new RestUserGuild(discord, model.Id); entity.Update(model); return(entity); }
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()); }
/// <summary> /// Converts an existing <see cref="RestUserGuild"/> to an abstracted <see cref="IRestUserGuild"/> value. /// </summary> /// <param name="restUserGuild">The existing <see cref="RestUserGuild"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restUserGuild"/>.</exception> /// <returns>An <see cref="IRestUserGuild"/> that abstracts <paramref name="restUserGuild"/>.</returns> public static IRestUserGuild Abstract(this RestUserGuild restUserGuild) => new RestUserGuildAbstraction(restUserGuild);
/// <inheritdoc cref="RestUserGuild.ToString" /> public override string ToString() => RestUserGuild.ToString();
/// <inheritdoc /> public Task LeaveAsync(RequestOptions options = null) => RestUserGuild.LeaveAsync(options);
/// <inheritdoc /> public Task DeleteAsync(RequestOptions options = null) => RestUserGuild.DeleteAsync(options);
/// <summary> /// Constructs a new <see cref="RestUserGuildAbstraction"/> around an existing <see cref="Rest.RestUserGuild"/>. /// </summary> /// <param name="restUserGuild">The value to use for <see cref="Rest.RestUserGuild"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="restUserGuild"/>.</exception> public RestUserGuildAbstraction(RestUserGuild restUserGuild) { RestUserGuild = restUserGuild ?? throw new ArgumentNullException(nameof(restUserGuild)); }