Exemplo n.º 1
0
 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
                ));
 }
Exemplo n.º 2
0
        internal static RestUserGuild Create(BaseDiscordClient discord, Model model)
        {
            RestUserGuild entity = new RestUserGuild(discord, model.Id);

            entity.Update(model);
            return(entity);
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
 /// <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);
Exemplo n.º 5
0
 /// <inheritdoc cref="RestUserGuild.ToString" />
 public override string ToString()
 => RestUserGuild.ToString();
Exemplo n.º 6
0
 /// <inheritdoc />
 public Task LeaveAsync(RequestOptions options = null)
 => RestUserGuild.LeaveAsync(options);
Exemplo n.º 7
0
 /// <inheritdoc />
 public Task DeleteAsync(RequestOptions options = null)
 => RestUserGuild.DeleteAsync(options);
Exemplo n.º 8
0
 /// <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));
 }