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);
        }
Beispiel #2
0
        public async Task <List <InviteModel> > GetStoredInvitesAsync(InvitesListFilter filter)
        {
            var skip  = (filter.Page == 0 ? 0 : filter.Page - 1) * PaginationInfo.DefaultPageSize;
            var query = (await GetInvitesQueryAsync(filter)).Skip(skip).Take(PaginationInfo.DefaultPageSize);
            var guild = Discord.GetGuild(filter.GuildID);

            var invites = await query.ToListAsync();

            var result = new List <InviteModel>();

            foreach (var invite in invites)
            {
                var isVanity = invite.Code == guild.VanityURLCode;

                if (invite.Creator == null)
                {
                    result.Add(new InviteModel(invite, null, isVanity, invite.UsedUsers.Count));
                    continue;
                }

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

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

            return(result);
        }
Beispiel #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));
        }
Beispiel #4
0
        public async Task <PaginationInfo> GetPaginationInfoAsync(InvitesListFilter filter)
        {
            var query = await GetInvitesQueryAsync(filter);

            var count = await query.CountAsync();

            var skip = (filter.Page == 0 ? 0 : filter.Page - 1) * PaginationInfo.DefaultPageSize;

            return(new PaginationInfo(skip, filter.Page, count));
        }
Beispiel #5
0
        public async Task <IActionResult> IndexAsync(InvitesListFilter filter = null)
        {
            if (filter == null || filter.GuildID == 0)
            {
                filter = InvitesListFilter.CreateDefault(DiscordClient);
            }

            var invitesFromGuild = await InviteTrackerService.GetStoredInvitesAsync(filter);

            return(View(new InvitesListViewModel(DiscordClient.Guilds.ToList(), invitesFromGuild, filter)));
        }