public RestRequestEnumerator <T> GetAuditLogsEnumerator <T>(Snowflake guildId, int limit = 100, Snowflake?userId = null, Snowflake?startFromId = null) where T : RestAuditLog
        {
            var enumerator = new RestRequestEnumerator <T>();
            var remaining  = limit;

            do
            {
                var amount = remaining > 100 ? 100 : remaining;
                remaining -= amount;
                enumerator.Enqueue(async(previous, options) =>
                {
                    var startFrom = startFromId;
                    if (previous != null && previous.Count > 0)
                    {
                        startFrom = previous[previous.Count - 1].Id;
                    }

                    var auditLogs = await InternalGetAuditLogsAsync <T>(guildId, amount, userId, startFrom, options).ConfigureAwait(false);
                    if (auditLogs.Count < 100)
                    {
                        enumerator.Cancel();
                    }

                    return(auditLogs);
                });
            }while (remaining > 0);
            return(enumerator);
        }
        internal RestRequestEnumerator <Snowflake> InternalGetBulkMessageDeletionEnumerator(Snowflake channelId, Snowflake[] messageIds)
        {
            var enumerator = new RestRequestEnumerator <Snowflake>();
            var remaining  = messageIds.Length;
            var offset     = 0;

            do
            {
                var amount  = remaining > 100 ? 100 : remaining;
                var segment = new ArraySegment <Snowflake>(messageIds, offset, amount);
                enumerator.Enqueue(async(_, options) =>
                {
                    if (amount == 1)
                    {
                        await DeleteMessageAsync(channelId, segment[0], options).ConfigureAwait(false);
                    }
                    else
                    {
                        await ApiClient.BulkDeleteMessagesAsync(channelId, segment.Select(x => x.RawValue), options).ConfigureAwait(false);
                    }

                    return(new ReadOnlyList <Snowflake>(segment));
                });
                remaining -= amount;
                offset    += amount;
            }while (remaining > 0);
            return(enumerator);
        }
        public RestRequestEnumerator <RestUser> GetReactionEnumerator(Snowflake channelId, Snowflake messageId, IEmoji emoji, int limit, RetrievalDirection?direction = null, Snowflake?startFromId = null)
        {
            if (emoji == null)
            {
                throw new ArgumentNullException(nameof(emoji));
            }

            var enumerator = new RestRequestEnumerator <RestUser>();
            var remaining  = limit;

            do
            {
                var amount = remaining > 100 ? 100 : remaining;
                remaining -= amount;
                enumerator.Enqueue(async(previous, options) =>
                {
                    var startFrom = startFromId;
                    if (previous != null && previous.Count > 0)
                    {
                        switch (direction)
                        {
                        case null:
                        case RetrievalDirection.Before:
                            startFrom = previous[previous.Count - 1].Id;
                            break;

                        case RetrievalDirection.After:
                            startFrom = previous[0].Id;
                            break;

                        case RetrievalDirection.Around:
                            throw new NotSupportedException();
                        }
                    }
                    var users = await InternalGetReactionsAsync(channelId, messageId, emoji, amount, direction, startFrom, options).ConfigureAwait(false);
                    if (users.Count != 100)
                    {
                        enumerator.Cancel();
                    }

                    return(users);
                });
            }while (remaining > 0);
            return(enumerator);
        }
        public RestRequestEnumerator <RestMessage> GetMessagesEnumerator(Snowflake channelId, int limit, RetrievalDirection?direction = null, Snowflake?startFromId = null)
        {
            var enumerator = new RestRequestEnumerator <RestMessage>();
            var remaining  = limit;

            do
            {
                var amount = remaining > 100 ? 100 : remaining;
                remaining -= amount;
                enumerator.Enqueue(async(previous, options) =>
                {
                    var startFrom = startFromId;
                    if (previous != null && previous.Count > 0)
                    {
                        switch (direction)
                        {
                        case null:
                        case RetrievalDirection.Before:
                            startFrom = previous[previous.Count - 1].Id;
                            break;

                        case RetrievalDirection.After:
                            startFrom = previous[0].Id;
                            break;

                        case RetrievalDirection.Around:
                            throw new NotImplementedException();
                        }
                    }
                    var messages = await InternalGetMessagesAsync(channelId, amount, direction, startFrom, options).ConfigureAwait(false);
                    if (messages.Count < 100)
                    {
                        enumerator.Cancel();
                    }

                    return(messages);
                });
            }while (remaining > 0);
            return(enumerator);
        }
Exemple #5
0
        public RestRequestEnumerator <RestMember> GetMembersEnumerator(Snowflake guildId, int limit, Snowflake?startFromId = null)
        {
            var enumerator = new RestRequestEnumerator <RestMember>();
            var remaining  = limit;

            do
            {
                var amount = remaining > 1000 ? 1000 : remaining;
                remaining -= amount;
                enumerator.Enqueue(async(previous, options) =>
                {
                    var members = await InternalGetMembersAsync(guildId, amount, previous?.Count > 0 ? previous.Max(x => x.Id) : startFromId, options).ConfigureAwait(false);
                    if (members.Count < 1000)
                    {
                        enumerator.Cancel();
                    }

                    return(members);
                });
            }while (remaining > 0);
            return(enumerator);
        }
 internal RestRequestEnumerable(RestRequestEnumerator <T> enumerator)
 {
     _enumerator = enumerator;
 }