Example #1
0
        private async Task <AuditLogQueryFilter> CreateQueryFilterAsync(LogsFilter filter, SocketGuild guild)
        {
            var users = await UserSearchService.FindUsersAsync(guild, filter.UserQuery);

            var userIds = users != null ? (await UserSearchService.ConvertUsersToIDsAsync(users)).Select(o => o.Value).Where(o => o != null).Select(o => (long)o) : null;

            var botAccounts = filter.IgnoreBots ? await guild.GetBotsAsync() : new List <SocketGuildUser>();

            var botAccountIds = (await UserSearchService.ConvertUsersToIDsAsync(botAccounts)).Select(o => o.Value).Where(o => o != null).Select(o => (long)o);

            if (filter.Page < 0)
            {
                filter.Page = 0;
            }

            var types = filter.GetSelectedTypes();

            return(new AuditLogQueryFilter()
            {
                From = filter.From,
                GuildId = filter.GuildId.ToString(),
                Skip = (filter.Page == 0 ? 0 : filter.Page - 1) * PaginationInfo.DefaultPageSize,
                SortDesc = filter.SortDesc,
                Take = PaginationInfo.DefaultPageSize,
                To = filter.To,
                Types = types.ToArray(),
                UserIds = userIds?.ToList(),
                IgnoredIds = botAccountIds.ToList()
            });
        }