# Path: rolemanagement/abc.py
# class MixinMeta(ABC):
#     """
#     Metaclass for well behaved type hint detection with composite class.
#     """
# 
#     # https://github.com/python/mypy/issues/1996
# 
#     qualified_name: str
# 
#     def __init__(self, *_args):
#         self.config: Config
#         self.bot: Red
# 
#     @abstractmethod
#     def strip_variations(self, s: str) -> str:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def wait_for_ready(self) -> None:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def is_self_assign_eligible(
#         self, who: discord.Member, role: discord.Role
#     ) -> List[discord.Role]:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def update_roles_atomically(
#         self,
#         *,
#         who: discord.Member,
#         give: Optional[List[discord.Role]] = None,
#         remove: Optional[List[discord.Role]] = None,
#     ):
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def all_are_valid_roles(self, ctx, *roles: discord.Role) -> bool:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def maybe_update_guilds(self, *guilds: discord.Guild) -> None:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     def get_top_role(self, member: discord.Member) -> discord.Role:
#         raise NotImplementedError()
# 
# Path: rolemanagement/exceptions.py
# class ConflictingRoleException(RoleManagementException):
#     def __init__(self, *, conflicts=None):
#         self.conflicts = conflicts or []
#         super().__init__()
# 
# class MissingRequirementsException(RoleManagementException):
#     def __init__(self, *, miss_any=None, miss_all=None):
#         self.miss_all = miss_all or []
#         self.miss_any = miss_any or []
#         super().__init__()
# 
# class PermissionOrHierarchyException(Exception):
#     pass
# 
# class RoleManagementException(Exception):
#     pass


import re
import discord
from typing import List
from .abc import MixinMeta
from .exceptions import (
    ConflictingRoleException,
    MissingRequirementsException,
    PermissionOrHierarchyException,
    RoleManagementException,
)
        user_roles = sorted(who.roles)  # resort needed, see GH-discord.py#4087
        roles = [r for r in user_roles if r not in remove]
        roles.extend([r for r in give if r not in roles])
        if sorted(roles) == user_roles:
            return
        if (
            any(r >= self.get_top_role(me) for r in hierarchy_testing)
            or not me.guild_permissions.manage_roles
        ):
            raise PermissionOrHierarchyException("Can't do that.")
        await who.edit(roles=roles)

    async def all_are_valid_roles(
        self, ctx, *roles: discord.Role, detailed: bool = False
    ) -> bool:
        """
        Quick hierarchy check on a role set in syntax returned
        """
        author = ctx.author
        guild = ctx.guild

        # Author allowed

        if not guild.owner == author:
            auth_top = self.get_top_role(author)
            if not (
                all(auth_top > role for role in roles)
                or await ctx.bot.is_owner(ctx.author)
            ):
                if detailed:

# Path: rolemanagement/abc.py
# class MixinMeta(ABC):
#     """
#     Metaclass for well behaved type hint detection with composite class.
#     """
# 
#     # https://github.com/python/mypy/issues/1996
# 
#     qualified_name: str
# 
#     def __init__(self, *_args):
#         self.config: Config
#         self.bot: Red
# 
#     @abstractmethod
#     def strip_variations(self, s: str) -> str:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def wait_for_ready(self) -> None:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def is_self_assign_eligible(
#         self, who: discord.Member, role: discord.Role
#     ) -> List[discord.Role]:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def update_roles_atomically(
#         self,
#         *,
#         who: discord.Member,
#         give: Optional[List[discord.Role]] = None,
#         remove: Optional[List[discord.Role]] = None,
#     ):
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def all_are_valid_roles(self, ctx, *roles: discord.Role) -> bool:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     async def maybe_update_guilds(self, *guilds: discord.Guild) -> None:
#         raise NotImplementedError()
# 
#     @abstractmethod
#     def get_top_role(self, member: discord.Member) -> discord.Role:
#         raise NotImplementedError()
# 
# Path: rolemanagement/exceptions.py
# class ConflictingRoleException(RoleManagementException):
#     def __init__(self, *, conflicts=None):
#         self.conflicts = conflicts or []
#         super().__init__()
# 
# class MissingRequirementsException(RoleManagementException):
#     def __init__(self, *, miss_any=None, miss_all=None):
#         self.miss_all = miss_all or []
#         self.miss_any = miss_any or []
#         super().__init__()
# 
# class PermissionOrHierarchyException(Exception):
#     pass
# 
# class RoleManagementException(Exception):
#     pass


# Path: rolemanagement/utils.py
import re
import discord
from typing import List
from .abc import MixinMeta
from .exceptions import (
    ConflictingRoleException,
    MissingRequirementsException,
    PermissionOrHierarchyException,
    RoleManagementException,
)

        user_roles = sorted(who.roles)  # resort needed, see GH-discord.py#4087
        roles = [r for r in user_roles if r not in remove]
        roles.extend([r for r in give if r not in roles])
        if sorted(roles) == user_roles:
            return
        if (
            any(r >= self.get_top_role(me) for r in hierarchy_testing)
            or not me.guild_permissions.manage_roles
        ):
            raise PermissionOrHierarchyException("Can't do that.")
        await who.edit(roles=roles)

    async def all_are_valid_roles(
        self, ctx, *roles: discord.Role, detailed: bool = False
    ) -> bool:
        """
        Quick hierarchy check on a role set in syntax returned
        """
        author = ctx.author
        guild = ctx.guild

        # Author allowed

        if not guild.owner == author:
            auth_top = self.get_top_role(author)
            if not (
                all(auth_top > role for role in roles)
                or await ctx.bot.is_owner(ctx.author)
            ):
                if detailed:

                    raise RoleManagementException(