public static IPagedEnumerable <IMessage> EnumerateMessages(this IMessageChannel channel,
                                                                    int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null,
                                                                    IRestRequestOptions options             = null)
        {
            var client = channel.GetRestClient();

            return(client.EnumerateMessages(channel.Id, limit, direction, startFromId, options));
        }
예제 #2
0
 public RestGuildsRequestEnumerator(RestDiscordClient client,
                                    int limit, RetrievalDirection direction, Snowflake?startFromId,
                                    RestRequestOptions options)
     : base(client, 100, limit, options)
 {
     _direction   = direction;
     _startFromId = startFromId;
 }
예제 #3
0
 public FetchGuildsPagedEnumerator(
     IRestClient client,
     int limit, RetrievalDirection direction, Snowflake?startFromId,
     IRestRequestOptions options)
     : base(client, limit, options)
 {
     _direction   = direction;
     _startFromId = startFromId;
 }
        public static IPagedEnumerable <IUser> EnumerateUsers(this IGuildEvent @event,
                                                              int limit, RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null,
                                                              bool?withMember             = null,
                                                              IRestRequestOptions options = null)
        {
            var client = @event.GetRestClient();

            return(client.EnumerateGuildEventUsers(@event.GuildId, @event.Id, limit, direction, startFromId, withMember, options));
        }
예제 #5
0
        public static Task <IReadOnlyList <IUser> > FetchEventUsersAsync(this IGuild guild,
                                                                         Snowflake eventId, int limit = Discord.Limits.Rest.FetchGuildEventUsersPageSize,
                                                                         RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null,
                                                                         bool?withMember             = null,
                                                                         IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            var client = guild.GetRestClient();

            return(client.FetchGuildEventUsersAsync(guild.Id, eventId, limit, direction, startFromId, withMember, options, cancellationToken));
        }
 public FetchMessagesPagedEnumerator(
     IRestClient client,
     Snowflake guildId, int limit, RetrievalDirection direction, Snowflake?startFromId,
     IRestRequestOptions options,
     CancellationToken cancellationToken)
     : base(client, limit, options, cancellationToken)
 {
     _guildId     = guildId;
     _direction   = direction;
     _startFromId = startFromId;
 }
예제 #7
0
        public static IPagedEnumerable <IPartialGuild> EnumerateGuilds(this IRestClient client,
                                                                       int limit, RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null,
                                                                       IRestRequestOptions options             = null)
        {
            Guard.IsGreaterThanOrEqualTo(limit, 0);

            return(PagedEnumerable.Create((state, cancellationToken) =>
            {
                var(client, limit, direction, startFromId, options) = state;
                return new FetchGuildsPagedEnumerator(client, limit, direction, startFromId, options, cancellationToken);
            }, (client, limit, direction, startFromId, options)));
        }
예제 #8
0
 public ValueTask <AdminCommandResult> PruneMessages([MustBe(Operator.GreaterThan, 0)]
                                                     [MustBe(Operator.LessThan, 10000)] int limit,
                                                     RetrievalDirection direction,
                                                     ulong messageId)
 {
     if (direction == RetrievalDirection.Around)
     {
         return(CommandSuccess()); // silent failure
     }
     return(direction == RetrievalDirection.Before
         ? PruneMessagesAsync(limit, message => message.Id < messageId)
         : PruneMessagesAsync(limit, message => message.Id > messageId));
 }
 public FetchGuildEventUsersPagedEnumerator(
     IRestClient client,
     Snowflake guildId, Snowflake eventId, int limit, RetrievalDirection direction, Snowflake?startFromId,
     bool?withMember,
     IRestRequestOptions options,
     CancellationToken cancellationToken)
     : base(client, limit, options, cancellationToken)
 {
     _guildId     = guildId;
     _eventId     = eventId;
     _direction   = direction;
     _startFromId = startFromId;
     _withMember  = withMember;
 }
        internal static async Task <IReadOnlyList <IMessage> > InternalFetchMessagesAsync(this IRestClient client,
                                                                                          Snowflake channelId, int limit, RetrievalDirection direction, Snowflake?startFromId,
                                                                                          IRestRequestOptions options, CancellationToken cancellationToken)
        {
            var models = await client.ApiClient.FetchMessagesAsync(channelId, limit, direction, startFromId, options, cancellationToken).ConfigureAwait(false);

            return(models.ToReadOnlyList(client, (x, client) => TransientMessage.Create(client, x)));
        }
예제 #11
0
 public Task <IReadOnlyList <RestMessage> > GetMessagesAsync(Snowflake channelId, int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetMessagesAsync(channelId, limit, direction, startFromId, options);
예제 #12
0
 public RestRequestEnumerable <RestMessage> GetMessagesEnumerable(Snowflake channelId, int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetMessagesEnumerable(channelId, limit, direction, startFromId, options);
예제 #13
0
 public Task <IReadOnlyList <RestPartialGuild> > GetGuildsAsync(int limit  = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetGuildsAsync(limit, direction, startFromId, options);
예제 #14
0
 public RestRequestEnumerable <RestPartialGuild> GetGuildsEnumerable(int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null) => ((IRestDiscordClient)RestClient).GetGuildsEnumerable(limit, direction, startFromId, options);
예제 #15
0
 public RestRequestEnumerable <RestMessage> GetMessagesEnumerable(int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
 => Client.GetMessagesEnumerable(Id, limit, direction, startFromId, options);
예제 #16
0
        internal async Task <IReadOnlyList <RestMessage> > InternalGetMessagesAsync(Snowflake channelId, int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
        {
            var models = await ApiClient.GetChannelMessagesAsync(channelId, limit, direction, startFromId, options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => RestMessage.Create(@this, x)));
        }
예제 #17
0
 /// <summary>
 ///     Enumerates the guilds of the user tied to this bearer token.
 /// </summary>
 /// <param name="client"> The bearer client. </param>
 /// <param name="limit"> The amount of guilds to enumerate. </param>
 /// <param name="retrievalDirection"> The direction to enumerate the guilds in. </param>
 /// <param name="startFromId"> The ID of the guild to start enumerating from. </param>
 /// <param name="options"> The optional request options. </param>
 /// <returns>
 ///     A paged enumerable yielding the requested guilds.
 /// </returns>
 public static IPagedEnumerable <IPartialGuild> EnumerateGuilds(this IBearerClient client,
                                                                int limit, RetrievalDirection retrievalDirection = RetrievalDirection.After, Snowflake?startFromId = null,
                                                                IRestRequestOptions options = null)
 {
     return(client.RestClient.EnumerateGuilds(limit, retrievalDirection, startFromId, options));
 }
예제 #18
0
 public RestRequestEnumerable <RestMessage> GetMessagesEnumerable(Snowflake channelId, int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
 => new RestRequestEnumerable <RestMessage>(new RestMessagesRequestEnumerator(this, channelId, limit, direction, startFromId, options));
        public static Task <IReadOnlyList <IMessage> > FetchMessagesAsync(this IRestClient client,
                                                                          Snowflake channelId, int limit = Discord.Limits.Rest.FetchMessagesPageSize, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null,
                                                                          IRestRequestOptions options    = null, CancellationToken cancellationToken = default)
        {
            if (limit == 0)
            {
                return(Task.FromResult(ReadOnlyList <IMessage> .Empty));
            }

            if (limit <= Discord.Limits.Rest.FetchMessagesPageSize)
            {
                return(client.InternalFetchMessagesAsync(channelId, limit, direction, startFromId, options, cancellationToken));
            }

            var enumerable = client.EnumerateMessages(channelId, limit, direction, startFromId, options);

            return(enumerable.FlattenAsync(cancellationToken));
        }
        public static IPagedEnumerable <IMessage> EnumerateMessages(this IRestClient client,
                                                                    Snowflake channelId, int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null,
                                                                    IRestRequestOptions options = null)
        {
            Guard.IsGreaterThanOrEqualTo(limit, 0);

            return(PagedEnumerable.Create((state, cancellationToken) =>
            {
                var(client, channelId, limit, direction, startFromId, options) = state;
                return new FetchMessagesPagedEnumerator(client, channelId, limit, direction, startFromId, options, cancellationToken);
            }, (client, channelId, limit, direction, startFromId, options)));
        }
        public static Task <GuildScheduledEventUserJsonModel[]> FetchGuildScheduledEventUsersAsync(this IRestApiClient client,
                                                                                                   Snowflake guildId, Snowflake eventId, int limit = Discord.Limits.Rest.FetchGuildEventUsersPageSize,
                                                                                                   RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null,
                                                                                                   bool?withMember             = null,
                                                                                                   IRestRequestOptions options = null, CancellationToken cancellationToken = default)
        {
            Guard.IsBetweenOrEqualTo(limit, 0, Discord.Limits.Rest.FetchGuildEventUsersPageSize);

            var queryParameters = new Dictionary <string, object>
            {
                ["limit"] = limit
            };

            if (startFromId != null)
            {
                switch (direction)
                {
                case RetrievalDirection.Before:
                {
                    queryParameters["before"] = startFromId;
                    break;
                }

                case RetrievalDirection.After:
                {
                    queryParameters["after"] = startFromId;
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException(nameof(direction), "Invalid guild event user fetch direction.");
                }
                }
            }

            if (withMember != null)
            {
                queryParameters["with_member"] = withMember.Value;
            }

            var route = Format(Route.GuildEvents.GetEventUsers, queryParameters, guildId, eventId);

            return(client.ExecuteAsync <GuildScheduledEventUserJsonModel[]>(route, null, options, cancellationToken));
        }
예제 #22
0
        public Task <IReadOnlyList <RestMessage> > GetMessagesAsync(Snowflake channelId, int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
        {
            if (limit == 0)
            {
                return(Task.FromResult <IReadOnlyList <RestMessage> >(ReadOnlyList <RestMessage> .Empty));
            }

            if (limit <= 100)
            {
                return(InternalGetMessagesAsync(channelId, limit, direction, startFromId, options));
            }

            var enumerable = GetMessagesEnumerable(channelId, limit, direction, startFromId, options);

            return(enumerable.FlattenAsync());
        }
        public static Task <MessageJsonModel[]> FetchMessagesAsync(this IRestApiClient client, Snowflake channelId, int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, IRestRequestOptions options = null)
        {
            if (limit < 1 || limit > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            var queryParameters = new Dictionary <string, object>(startFromId != null ? 2 : 1)
            {
                ["limit"] = limit
            };

            switch (direction)
            {
            case RetrievalDirection.Around:
            {
                queryParameters["around"] = startFromId ?? throw new ArgumentNullException(nameof(startFromId), "The ID to fetch messages around must not be null.");
                break;
            }

            case RetrievalDirection.Before:
            {
                if (startFromId != null)
                {
                    queryParameters["before"] = startFromId;
                }

                break;
            }

            case RetrievalDirection.After:
            {
                queryParameters["after"] = startFromId ?? throw new ArgumentNullException(nameof(startFromId), "The ID to fetch messages after must not be null.");
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(direction), "Invalid message fetch direction.");
            }
            }

            var route = Format(Route.Channel.GetMessages, queryParameters, channelId);

            return(client.ExecuteAsync <MessageJsonModel[]>(route, null, options));
        }
예제 #24
0
        public static Task <IReadOnlyList <IMessage> > FetchMessagesAsync(this IMessageChannel channel, int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, IRestRequestOptions options = null)
        {
            var client = channel.GetRestClient();

            return(client.FetchMessagesAsync(channel.Id, limit, direction, startFromId, options));
        }
예제 #25
0
        public static Task <GuildJsonModel[]> FetchGuildsAsync(this IRestApiClient client,
                                                               int limit = Discord.Limits.Rest.FetchGuildsPageSize, RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null,
                                                               IRestRequestOptions options = null, CancellationToken cancellationToken           = default)
        {
            Guard.IsBetweenOrEqualTo(limit, 0, Discord.Limits.Rest.FetchGuildsPageSize);

            var queryParameters = new Dictionary <string, object>(startFromId != null ? 2 : 1)
            {
                ["limit"] = limit
            };

            switch (direction)
            {
            case RetrievalDirection.Before:
            {
                if (startFromId != null)
                {
                    queryParameters["before"] = startFromId;
                }

                break;
            }

            case RetrievalDirection.After:
            {
                if (startFromId != null)
                {
                    queryParameters["after"] = startFromId;
                }

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(direction), "Invalid guild fetch direction.");
            }
            }

            var route = Format(Route.User.GetGuilds, queryParameters);

            return(client.ExecuteAsync <GuildJsonModel[]>(route, null, options, cancellationToken));
        }
예제 #26
0
 public RestRequestEnumerable <RestPartialGuild> GetGuildsEnumerable(int limit, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
 => new RestRequestEnumerable <RestPartialGuild>(new RestGuildsRequestEnumerator(this, limit, direction, startFromId, options));
예제 #27
0
 /// <summary>
 ///     Fetches the guilds of the user tied to this bearer token.
 /// </summary>
 /// <param name="client"> The bearer client. </param>
 /// <param name="limit"> The amount of guilds to fetch. </param>
 /// <param name="retrievalDirection"> The direction to fetch the guilds in. </param>
 /// <param name="startFromId"> The ID of the guild to start fetching from. </param>
 /// <param name="options"> The optional request options. </param>
 /// <param name="cancellationToken"> The cancellation token to observe. </param>
 /// <returns>
 ///     A <see cref="Task{TResult}"/> representing the asynchronous request
 ///     that wraps the returned <see cref="IReadOnlyList{T}"/> of <see cref="IPartialGuild"/>.
 /// </returns>
 public static Task <IReadOnlyList <IPartialGuild> > FetchGuildsAsync(this IBearerClient client,
                                                                      int limit = Discord.Limits.Rest.FetchGuildsPageSize, RetrievalDirection retrievalDirection = RetrievalDirection.Before, Snowflake?startFromId = null,
                                                                      IRestRequestOptions options = null, CancellationToken cancellationToken = default)
 {
     return(client.RestClient.FetchGuildsAsync(limit, retrievalDirection, startFromId, options, cancellationToken));
 }
예제 #28
0
        public Task <IReadOnlyList <RestPartialGuild> > GetGuildsAsync(int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
        {
            if (limit == 0)
            {
                return(Task.FromResult(ReadOnlyList <RestPartialGuild> .Empty));
            }

            if (limit <= 100)
            {
                return(InternalGetGuildsAsync(limit, direction, startFromId, options));
            }

            var enumerable = GetGuildsEnumerable(limit, direction, startFromId, options);

            return(enumerable.FlattenAsync());
        }
예제 #29
0
 public Task <IReadOnlyList <RestMessage> > GetMessagesAsync(int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
 => Client.GetMessagesAsync(Id, limit, direction, startFromId, options);
예제 #30
0
        internal async Task <IReadOnlyList <RestPartialGuild> > InternalGetGuildsAsync(int limit = 100, RetrievalDirection direction = RetrievalDirection.Before, Snowflake?startFromId = null, RestRequestOptions options = null)
        {
            var models = await ApiClient.GetCurrentUserGuildsAsync(limit, direction, startFromId, options).ConfigureAwait(false);

            return(models.ToReadOnlyList(this, (x, @this) => new RestPartialGuild(@this, x)));
        }