# 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 PermissionOrHierarchyException(Exception):
#     pass
# 
# class RoleManagementException(Exception):
#     pass


from datetime import datetime, timedelta
from typing import List
from redbot.core import commands
from .abc import MixinMeta
from .exceptions import PermissionOrHierarchyException, RoleManagementException
import discord
        emoji = payload.emoji
        if emoji.is_custom_emoji():
            eid = str(emoji.id)
        else:
            eid = self.strip_variations(str(emoji))

        cfg = self.config.custom("REACTROLE", str(payload.message_id), eid)
        rid = await cfg.roleid()
        if rid is None or not await self.config.role_from_id(rid).self_role():
            return

        guild = self.bot.get_guild(payload.guild_id)
        if guild:
            await self.maybe_update_guilds(guild)
        else:
            return
        member = guild.get_member(payload.user_id)

        if member is None or member.bot:
            return

        if self.verification_level_issue(member):
            return

        role = guild.get_role(rid)
        if role is None or role in member.roles:
            return

        try:
            remove = await self.is_self_assign_eligible(member, role)

# 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 PermissionOrHierarchyException(Exception):
#     pass
# 
# class RoleManagementException(Exception):
#     pass


# Path: rolemanagement/events.py
from datetime import datetime, timedelta
from typing import List
from redbot.core import commands
from .abc import MixinMeta
from .exceptions import PermissionOrHierarchyException, RoleManagementException
import discord

        emoji = payload.emoji
        if emoji.is_custom_emoji():
            eid = str(emoji.id)
        else:
            eid = self.strip_variations(str(emoji))

        cfg = self.config.custom("REACTROLE", str(payload.message_id), eid)
        rid = await cfg.roleid()
        if rid is None or not await self.config.role_from_id(rid).self_role():
            return

        guild = self.bot.get_guild(payload.guild_id)
        if guild:
            await self.maybe_update_guilds(guild)
        else:
            return
        member = guild.get_member(payload.user_id)

        if member is None or member.bot:
            return

        if self.verification_level_issue(member):
            return

        role = guild.get_role(rid)
        if role is None or role in member.roles:
            return

        try:
            remove = await self.is_self_assign_eligible(member, role)

        except (RoleManagementException, PermissionOrHierarchyException):