U
    g
                      @   s   d Z ddlmZmZmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ erdd
lmZ G dd deZdS )z?This module contains an object that represents a Telegram Game.    )TYPE_CHECKINGDictListOptionalSequenceTuple)	Animation)	PhotoSize)MessageEntity)TelegramObject)parse_sequence_arg)TextEncoding)JSONDict)Botc                
       s   e Zd ZdZdZdddeeee ee eee	  ee
 ee d fddZedee ed ed  d	 fd
dZe	edddZdeee  ee	ef dddZ  ZS )Gamea
  
    This object represents a game. Use `BotFather <https://t.me/BotFather>`_ to create and edit
    games, their short names will act as unique identifiers.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`title`, :attr:`description` and :attr:`photo` are equal.

    Args:
        title (:obj:`str`): Title of the game.
        description (:obj:`str`): Description of the game.
        photo (Sequence[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
            message in chats.

            .. versionchanged:: 20.0
                |sequenceclassargs|

        text (:obj:`str`, optional): Brief description of the game or high scores included in the
            game message. Can be automatically edited to include current high scores for the game
            when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
            using :meth:`telegram.Bot.edit_message_text`.
            0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
        text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that
            appear in text, such as usernames, URLs, bot commands, etc.

            .. versionchanged:: 20.0
                |sequenceclassargs|

        animation (:class:`telegram.Animation`, optional): Animation that will be displayed in the
            game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.

    Attributes:
        title (:obj:`str`): Title of the game.
        description (:obj:`str`): Description of the game.
        photo (Tuple[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
            message in chats.

            .. versionchanged:: 20.0
                |tupleclassattrs|

        text (:obj:`str`): Optional. Brief description of the game or high scores included in the
            game message. Can be automatically edited to include current high scores for the game
            when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
            using :meth:`telegram.Bot.edit_message_text`.
            0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
        text_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special entities that
            appear in text, such as usernames, URLs, bot commands, etc.
            This tuple is empty if the message does not contain text entities.

            .. versionchanged:: 20.0
                |tupleclassattrs|

        animation (:class:`telegram.Animation`): Optional. Animation that will be displayed in the
            game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.

    )	animationdescriptionphototexttext_entitiestitleN
api_kwargs)r   r   r   r   r   r   r   c                   sX   t  j|d || _|| _t|| _|| _t|| _|| _| j| j| jf| _	| 
  d S )Nr   )super__init__r   r   r   r   r   r   r   Z	_id_attrsZ_freeze)selfr   r   r   r   r   r   r   	__class__ 8/tmp/pip-unpacked-wheel-swnnwir2/telegram/_games/game.pyr   d   s    

zGame.__init__r   )databotreturnc                    sd   |  |}|sdS t|d||d< t|d||d< t|d||d< t j||dS )z,See :meth:`telegram.TelegramObject.de_json`.Nr   r   r   )r    r!   )Z_parse_datar	   Zde_listgetr
   r   de_jsonr   )clsr    r!   r   r   r   r$   }   s    
zGame.de_json)entityr"   c                 C   sF   | j std| j tj}||jd |j|j d  }|tjS )a  Returns the text from a given :class:`telegram.MessageEntity`.

        Note:
            This method is present because Telegram calculates the offset and length in
            UTF-16 codepoint pairs, which some versions of Python don't handle automatically.
            (That is, you can't just slice ``Message.text`` with the offset and length.)

        Args:
            entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must
                be an entity that belongs to this message.

        Returns:
            :obj:`str`: The text of the given entity.

        Raises:
            RuntimeError: If this game has no text.

        zThis Game has no 'text'.   )r   RuntimeErrorencoder   Z	UTF_16_LEoffsetlengthdecode)r   r&   Zentity_textr   r   r   parse_text_entity   s
    zGame.parse_text_entity)typesr"   c                    s$   dkrt j fdd jD S )a]  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this message filtered by their
        :attr:`~telegram.MessageEntity.type` attribute as the key, and the text that each entity
        belongs to as the value of the :obj:`dict`.

        Note:
            This method should always be used instead of the :attr:`text_entities` attribute, since
            it calculates the correct substring from the message text based on UTF-16 codepoints.
            See :attr:`parse_text_entity` for more info.

        Args:
            types (List[:obj:`str`], optional): List of :class:`telegram.MessageEntity` types as
                strings. If the :attr:`~telegram.MessageEntity.type` attribute of an entity is
                contained in this list, it will be returned. Defaults to
                :attr:`telegram.MessageEntity.ALL_TYPES`.

        Returns:
            Dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to
            the text that belongs to them, calculated based on UTF-16 codepoints.

        Nc                    s"   i | ]}|j kr| |qS r   )typer-   ).0r&   r   r.   r   r   
<dictcomp>   s   
 z,Game.parse_text_entities.<locals>.<dictcomp>)r
   Z	ALL_TYPESr   r1   r   r1   r   parse_text_entities   s
    zGame.parse_text_entities)NNN)N)N)__name__
__module____qualname____doc__	__slots__strr   r	   r   r
   r   r   r   classmethodr$   r-   r   r   r3   __classcell__r   r   r   r   r   "   s(   8   	
&r   N)r7   typingr   r   r   r   r   r   Ztelegram._files.animationr   Ztelegram._files.photosizer	   Ztelegram._messageentityr
   Ztelegram._telegramobjectr   Ztelegram._utils.argumentparsingr   Ztelegram._utils.stringsr   Ztelegram._utils.typesr   Ztelegramr   r   r   r   r   r   <module>   s    