
    Th2                         d Z ddlZddl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 erdd	l
mZ  G d
 de      Zy)zHThis module contains an object that represents a Telegram MessageEntity.    N)TYPE_CHECKINGDictFinalListOptionalSequence)	constants)TelegramObject)User)enum)JSONDict)Botc                       e Zd ZU dZdZ	 	 	 	 d*dddedededee   d	ee   d
ee   dee   dee	   f fdZ
e	 d+dee	   ded   ded    f fd       Zededed    ded    fd       Z eej$                        Zeee      ed<   	 ej$                  j.                  Zee   ed<   	 ej$                  j0                  Zee   ed<   	 ej$                  j2                  Zee   ed<   	 ej$                  j4                  Zee   ed<   	 ej$                  j6                  Zee   ed<   	 ej$                  j8                  Zee   ed<   	 ej$                  j:                  Zee   ed<   	 ej$                  j<                  Zee   ed<   	 ej$                  j>                  Zee   ed<   	 ej$                  j@                  Z ee   ed <   	 ej$                  jB                  Z!ee   ed!<   	 ej$                  jD                  Z"ee   ed"<   	 ej$                  jF                  Z#ee   ed#<   	 ej$                  jH                  Z$ee   ed$<   	 ej$                  jJ                  Z%ee   ed%<   	 ej$                  jL                  Z&ee   ed&<   	 ej$                  jN                  Z'ee   ed'<   	 ej$                  jP                  Z(ee   ed(<   	 ej$                  jR                  Z)ee   ed)<    xZ*S ),MessageEntitya  
    This object represents one special entity in a text message. For example, hashtags,
    usernames, URLs, etc.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`type`, :attr:`offset` and :attr:`length` are equal.

    Args:
        type (:obj:`str`): Type of the entity. Can be :attr:`MENTION` (@username),
            :attr:`HASHTAG` (#hashtag), :attr:`CASHTAG` ($USD), :attr:`BOT_COMMAND`
            (/start@jobs_bot), :attr:`URL` (https://telegram.org),
            :attr:`EMAIL` (do-not-reply@telegram.org), :attr:`PHONE_NUMBER` (+1-212-555-0123),
            :attr:`BOLD` (**bold text**), :attr:`ITALIC` (*italic text*), :attr:`UNDERLINE`
            (underlined text), :attr:`STRIKETHROUGH`, :attr:`SPOILER` (spoiler message),
            :attr:`BLOCKQUOTE` (block quotation), :attr:`CODE` (monowidth string), :attr:`PRE`
            (monowidth block), :attr:`TEXT_LINK` (for clickable text URLs), :attr:`TEXT_MENTION`
            (for users without usernames), :attr:`CUSTOM_EMOJI` (for inline custom emoji stickers).

            .. versionadded:: 20.0
                Added inline custom emoji

            .. versionadded:: 20.8
                Added block quotation
        offset (:obj:`int`): Offset in UTF-16 code units to the start of the entity.
        length (:obj:`int`): Length of the entity in UTF-16 code units.
        url (:obj:`str`, optional): For :attr:`TEXT_LINK` only, url that will be opened after
            user taps on the text.
        user (:class:`telegram.User`, optional): For :attr:`TEXT_MENTION` only, the mentioned
             user.
        language (:obj:`str`, optional): For :attr:`PRE` only, the programming language of
            the entity text.
        custom_emoji_id (:obj:`str`, optional): For :attr:`CUSTOM_EMOJI` only, unique identifier
            of the custom emoji. Use :meth:`telegram.Bot.get_custom_emoji_stickers` to get full
            information about the sticker.

            .. versionadded:: 20.0
    Attributes:
        type (:obj:`str`): Type of the entity. Can be :attr:`MENTION` (@username),
            :attr:`HASHTAG` (#hashtag), :attr:`CASHTAG` ($USD), :attr:`BOT_COMMAND`
            (/start@jobs_bot), :attr:`URL` (https://telegram.org),
            :attr:`EMAIL` (do-not-reply@telegram.org), :attr:`PHONE_NUMBER` (+1-212-555-0123),
            :attr:`BOLD` (**bold text**), :attr:`ITALIC` (*italic text*), :attr:`UNDERLINE`
            (underlined text), :attr:`STRIKETHROUGH`, :attr:`SPOILER` (spoiler message),
            :attr:`BLOCKQUOTE` (block quotation), :attr:`CODE` (monowidth string), :attr:`PRE`
            (monowidth block), :attr:`TEXT_LINK` (for clickable text URLs), :attr:`TEXT_MENTION`
            (for users without usernames), :attr:`CUSTOM_EMOJI` (for inline custom emoji stickers).

            .. versionadded:: 20.0
                Added inline custom emoji

            .. versionadded:: 20.8
                Added block quotation
        offset (:obj:`int`): Offset in UTF-16 code units to the start of the entity.
        length (:obj:`int`): Length of the entity in UTF-16 code units.
        url (:obj:`str`): Optional. For :attr:`TEXT_LINK` only, url that will be opened after
            user taps on the text.
        user (:class:`telegram.User`): Optional. For :attr:`TEXT_MENTION` only, the mentioned
             user.
        language (:obj:`str`): Optional. For :attr:`PRE` only, the programming language of
            the entity text.
        custom_emoji_id (:obj:`str`): Optional. For :attr:`CUSTOM_EMOJI` only, unique identifier
            of the custom emoji. Use :meth:`telegram.Bot.get_custom_emoji_stickers` to get full
            information about the sticker.

            .. versionadded:: 20.0

    )custom_emoji_idlanguagelengthoffsettypeurluserN
api_kwargsr   r   r   r   r   r   r   r   c                >   t         	|   |       t        j                  t        j
                  ||      | _        || _        || _        || _	        || _
        || _        || _        | j                  | j                  | j                  f| _        | j                          y )Nr   )super__init__r   
get_memberr	   MessageEntityTyper   r   r   r   r   r   r   	_id_attrs_freeze)
selfr   r   r   r   r   r   r   r   	__class__s
            W/opt/server/standalone/crm/venv/lib/python3.12/site-packages/telegram/_messageentity.pyr   zMessageEntity.__init__j   s}     	J/)D)DdDQ	!!"%$(	'/.=))T[[$++>    databotr   returnc                     | j                  |      }|syt        j                  |j                  d      |      |d<   t        | 	  ||      S )z,See :meth:`telegram.TelegramObject.de_json`.Nr   )r%   r&   )_parse_datar   de_jsongetr   )clsr%   r&   r"   s      r#   r*   zMessageEntity.de_json   sI    
 t$||DHHV$4c:VwDc22r$   textentitiesc                 
   t        t        j                  d |D               }d}i }t        |      D ]>  \  }}|dkD  r||dz
     nd}| || }|t	        |j                  d            dz  z  }|||<   @ g }	|D ]}  }
||
j                     }||
j                  |
j                  z      |z
  }t        j                  |
      }|j                         5  ||_        ||_        ddd       |	j                  |        |	S # 1 sw Y   xY w)u  Utility functionality for converting the offset and length of entities from
        Unicode (:obj:`str`) to UTF-16 (``utf-16-le`` encoded :obj:`bytes`).

        Tip:
            Only the offsets and lengths calulated in UTF-16 is acceptable by the Telegram Bot API.
            If they are calculated using the Unicode string (:obj:`str` object), errors may occur
            when the text contains characters that are not in the Basic Multilingual Plane (BMP).
            For more information, see `Unicode <https://en.wikipedia.org/wiki/Unicode>`_ and
            `Plane (Unicode) <https://en.wikipedia.org/wiki/Plane_(Unicode)>`_.

        .. versionadded:: 21.4

        Examples:
            Below is a snippet of code that demonstrates how to use this function to convert
            entities from Unicode to UTF-16 space. The ``unicode_entities`` are calculated in
            Unicode and the `utf_16_entities` are calculated in UTF-16.

            .. code-block:: python

                text = "𠌕 bold 𝄢 italic underlined: 𝛙𝌢𑁍"
                unicode_entities = [
                    MessageEntity(offset=2, length=4, type=MessageEntity.BOLD),
                    MessageEntity(offset=9, length=6, type=MessageEntity.ITALIC),
                    MessageEntity(offset=28, length=3, type=MessageEntity.UNDERLINE),
                ]
                utf_16_entities = MessageEntity.adjust_message_entities_to_utf_16(
                    text, unicode_entities
                )
                await bot.send_message(
                    chat_id=123,
                    text=text,
                    entities=utf_16_entities,
                )
                # utf_16_entities[0]: offset=3, length=4
                # utf_16_entities[1]: offset=11, length=6
                # utf_16_entities[2]: offset=30, length=6

        Args:
            text (:obj:`str`): The text that the entities belong to
            entities (Sequence[:class:`telegram.MessageEntity`]): Sequence of entities
                with offset and length calculated in Unicode

        Returns:
            Sequence[:class:`telegram.MessageEntity`]: Sequence of entities
            with offset and length calculated in UTF-16 encoding
        c              3   f   K   | ])  }|j                   |j                   |j                  z   f + y wN)r   r   ).0xs     r#   	<genexpr>zBMessageEntity.adjust_message_entities_to_utf_16.<locals>.<genexpr>   s'     ,_QRahh1888K-L,_s   /1r      z	utf-16-le   N)sorted	itertoolschain	enumeratelenencoder   r   copy	_unfrozenappend)r-   r.   	positionsaccumulated_lengthposition_translationipositionlast_position
text_sliceoutentitytranslated_positionstranslated_length
new_entitys                 r#   !adjust_message_entities_to_utf_16z/MessageEntity.adjust_message_entities_to_utf_16   s/   f 9??,_V^,_`a	 02$Y/ 	@KAx01AIa!e,1MmH5J#j&7&7&D"E"JJ-? *		@  		#F#7#F $V]]V]]%BCFZZ  6*J%%' 6$8
!$5
!6 JJz"		# 
	6 6s   C99D		ALL_TYPES
BLOCKQUOTEBOLDBOT_COMMANDCASHTAGCODECUSTOM_EMOJIEMAILEXPANDABLE_BLOCKQUOTEHASHTAGITALICMENTIONPHONE_NUMBERPRESPOILERSTRIKETHROUGH	TEXT_LINKTEXT_MENTION	UNDERLINEURL)NNNNr1   )+__name__
__module____qualname____doc__	__slots__strintr   r   r   r   classmethodr*   staticmethodr   rL   listr	   r   rM   r   r   __annotations__rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   __classcell__)r"   s   @r#   r   r   #   sf   BH [I "#"&)- *.  	
 c] tn 3- "# X&6 >B3H%3,4UO3	/	"3 3 HH%o6H	/	"H HT #'y'B'B"CIuT#YCI&88CCJc
C !2277D%*7<'99EEKsEC#55==GU3Z=? 2277D%*7<(::GGL%*G "3399E5:9=(1(C(C(Y(Y5:Y $55==GU3Z=?"44;;FE#J;>#55==GU3Z=?(::GGL%*GD1155Cs5;#55==GU3Z= !* ; ; I IM5:IE%77AAIuSzAA(::GGL%*GD%77AAIuSzAA1155Cs5;r$   r   )rd   r=   r8   typingr   r   r   r   r   r   telegramr	   telegram._telegramobjectr
   telegram._userr   telegram._utilsr   telegram._utils.typesr   r   r    r$   r#   <module>rt      s:   & O   G G  3    *n<N n<r$   