Ejemplo n.º 1
0
        public async Task <IActionResult> GetUserInformationAsync(string userIdString)
        {
            if (!ulong.TryParse(userIdString, out var userId))
            {
                return(Ok(null));
            }

            var userInformation = await UserService.GetUserInformationAsync(UserGuild.Id, userId);

            if (userInformation is null)
            {
                return(Ok(null));
            }

            var userRank = await MessageRepository.GetGuildUserParticipationStatistics(UserGuild.Id, userId);

            var messages7 = await MessageRepository.GetGuildUserMessageCountByDate(UserGuild.Id, userId, TimeSpan.FromDays(7));

            var messages30 = await MessageRepository.GetGuildUserMessageCountByDate(UserGuild.Id, userId, TimeSpan.FromDays(30));

            var roles = userInformation.RoleIds
                        .Select(x => UserGuild.GetRole(x))
                        .OrderByDescending(x => x.IsHoisted)
                        .ThenByDescending(x => x.Position)
                        .ToArray();

            var mapped = new
            {
                Id                                                                = userInformation.Id.ToString(),
                Username                                                          = userInformation.Username,
                Nickname                                                          = userInformation.Nickname,
                Discriminator                                                     = userInformation.Discriminator,
                AvatarUrl                                                         = userInformation.AvatarId != null?userInformation.GetAvatarUrl(ImageFormat.Auto, 256) : userInformation.GetDefaultAvatarUrl(),
                                                            Status                = userInformation.Status.ToString(),
                                                            CreatedAt             = userInformation.CreatedAt,
                                                            JoinedAt              = userInformation.JoinedAt,
                                                            FirstSeen             = userInformation.FirstSeen,
                                                            LastSeen              = userInformation.LastSeen,
                                                            Rank                  = userRank.Rank,
                                                            Last7DaysMessages     = messages7.Sum(x => x.Value),
                                                            Last30DaysMessages    = messages30.Sum(x => x.Value),
                                                            AverageMessagesPerDay = userRank.AveragePerDay,
                                                            Percentile            = userRank.Percentile,
                                                            Roles                 = roles
                                                                                    .Where(x => !x.IsEveryone)
                                                                                    .Select(x => new
                {
                    Id    = x.Id,
                    Name  = x.Name,
                    Color = x.Color.ToString(),
                }),
                                                            IsBanned      = userInformation.IsBanned,
                                                            BanReason     = userInformation.BanReason,
                                                            IsGuildMember = userInformation.GuildId != default
            };

            return(Ok(mapped));
        }
    }
Ejemplo n.º 2
0
        public async Task <IActionResult> RoleDesignations()
        {
            var designatedRoles = await RoleService.GetDesignatedRolesAsync(ModixAuth.CurrentGuildId.Value);

            var mapped = designatedRoles.Select(d => new DesignatedRoleApiData
            {
                Id              = d.Id,
                RoleId          = d.Role.Id,
                RoleDesignation = d.Type,
                Name            = UserGuild?.GetRole(d.Role.Id)?.Name ?? d.Role.Id.ToString()
            });

            return(Ok(mapped));
        }