text: from typing import Union
  
  from discord import Reaction, Member, User, Message
  from discord.ext.commands import Cog, AutoShardedBot
  
  from DiscordBot.game.game import Game, get_game_by_message_id
  from DiscordBot.game.state import ExecuteSelectedMove, SelectFigureState
  
  
  class EmoteCog(Cog):
      def __init__(self, bot: AutoShardedBot):
          self.bot = bot
  
      @Cog.listener()
      async def on_reaction_add(self, reaction: Reaction, member: Union[Member, User]):
          if isinstance(member, User) or member.id == self.bot.user.id:
              return
  
          message: Message = reaction.message
          game: Game = get_game_by_message_id(message.id)
          if game is None:
              return
  
          if member.id != game.m1.id and member.id != game.m2.id:
              await message.remove_reaction(reaction, member)
              return
  
          if game.wait:
              await message.remove_reaction(reaction, member)
              return
  
          if reaction.emoji == "🤝":
              if reaction.count == 3:
                  await game.remis()
              return
  
          if game.get_current_member().id != member.id:
              await message.remove_reaction(reaction, member)
              return
  
          if reaction.emoji == "❌":
              await game.give_up()
              return
  
          if reaction.emoji == "↩️":
              game.state = SelectFigureState(game)
              await game.on_state(True)
              return
  
          if str(reaction.emoji) not in map(str, game.state.possible_emotes()):
              await message.remove_reaction(reaction, member)
              return
  
          game.state.on_react(reaction)
          await game.on_state()
  
          if isinstance(game.state, ExecuteSelectedMove):
              if game.state.gameover:
                  await game.state.end_game()
  