Esempio n. 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()
            });
        }
        public async Task <List <InviteModel> > GetStoredInvitesAsync(InvitesListFilter filter)
        {
            var guild          = Discord.GetGuild(filter.GuildID);
            var usersFromQuery = await UserSearchService.FindUsersAsync(guild, filter.UserQuery);

            var userIds = (await UserSearchService.ConvertUsersToIDsAsync(usersFromQuery))
                          .Select(o => o.Value).Where(o => o != null).Select(o => o.Value).ToList();

            var invites = await GrillBotRepository.InviteRepository.GetInvitesQuery(filter.GuildID, filter.CreatedFrom, filter.CreatedTo, userIds, filter.Desc).ToListAsync();

            var result = new List <InviteModel>();

            foreach (var invite in invites)
            {
                if (invite.Creator == null)
                {
                    result.Add(new InviteModel(invite, null, invite.UsedUsers.Count));
                    continue;
                }

                var creator = await guild.GetUserFromGuildAsync(invite.Creator.UserIDSnowflake);

                result.Add(new InviteModel(invite, creator, invite.UsedUsers.Count));
            }

            return(result);
        }
Esempio n. 3
0
        private async Task <IQueryable <Invite> > GetInvitesQueryAsync(InvitesListFilter filter)
        {
            var guild          = Discord.GetGuild(filter.GuildID);
            var usersFromQuery = await UserSearchService.FindUsersAsync(guild, filter.UserQuery);

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

            return(GrillBotRepository.InviteRepository.GetInvitesQuery(filter.GuildID, filter.CreatedFrom, filter.CreatedTo, userIds, filter.Desc));
        }