예제 #1
0
 public static GuildRoleEntity Clone(this GuildRoleEntity entity)
 => new GuildRoleEntity()
 {
     RoleId   = entity.RoleId,
     GuildId  = entity.GuildId,
     Name     = entity.Name,
     Position = entity.Position
 };
예제 #2
0
        public static void ShouldNotHaveChanged(this GuildRoleEntity entity)
        {
            entity.ShouldNotBeNull();
            entity.RoleId.ShouldBeOneOf(GuildRoles.Entities.Select(x => x.RoleId).ToArray());

            var originalEntity = GuildRoles.Entities.First(x => x.RoleId == entity.RoleId);

            entity.GuildId.ShouldBe(originalEntity.GuildId);
            entity.Name.ShouldBe(originalEntity.Name);
            entity.Position.ShouldBe(originalEntity.Position);
        }
예제 #3
0
        private async Task <bool> CanUserMaintainTagOwnedByRoleAsync(IGuildUser currentUser, GuildRoleEntity ownerRole)
        {
            Debug.Assert(!(ownerRole is null));

            var rankRoles = await GetRankRolesAsync(currentUser.GuildId);

            // If the owner role is no longer ranked, everything outranks it.
            if (!rankRoles.Any(x => x.Id == ownerRole.RoleId))
            {
                return(true);
            }

            var currentUserRankRoles = rankRoles.Where(r => currentUser.RoleIds.Contains(r.Id));

            var currentUserMaxRank = currentUserRankRoles.Any()
                ? currentUserRankRoles.Select(x => x.Position).Max()
                : int.MinValue;

            // Only allow maintenance if the user has sufficient rank.
            return(currentUserMaxRank >= ownerRole.Position);
        }
예제 #4
0
 internal void ApplyTo(GuildRoleEntity entity)
 {
     entity.Name     = Name;
     entity.Position = Position;
 }
예제 #5
0
 internal static GuildRoleMutationData FromEntity(GuildRoleEntity entity)
 => new GuildRoleMutationData()
 {
     Name     = entity.Name,
     Position = entity.Position
 };