
    Yi              	           S r SrSSKrSSKJr  SSKJrJrJr  SSK	J
r
  SSKJrJr  \(       a  SSKJrJr   SS	\S
\
S\\   S\4S jjrS\\\4   S\S\4S jrSS\\\4   S\S
\
S\4S jjrS\S   S\\   4S jr SS\S\\   S\S\4S jjrg)zThis module contains convenience helper functions.

.. versionchanged:: 20.0
   Previously, the contents of this module were available through the (no longer existing)
   module ``telegram.utils.helpers``.
)create_deep_linked_urleffective_message_typeescape_markdownmention_htmlmention_markdown    Nescape)TYPE_CHECKINGOptionalUnion)MarkdownVersion)MessageLimitMessageTypeMessageUpdatetextversionentity_typereturnc                     [        U5      S:X  a  SnO/[        U5      S:X  a  US;   a  SnOUS;   a  SnOSnO[        S	5      e[        R                  " S
[        R                  " U5       S3SU 5      $ )az  Helper function to escape telegram markup symbols.

.. versionchanged:: 20.3
    Custom emoji entity escaping is now supported.

Args:
    text (:obj:`str`): The text.
    version (:obj:`int` | :obj:`str`): Use to specify the version of telegrams Markdown.
        Either ``1`` or ``2``. Defaults to ``1``.
    entity_type (:obj:`str`, optional): For the entity types
        :tg-const:`telegram.MessageEntity.PRE`, :tg-const:`telegram.MessageEntity.CODE` and
        the link part of :tg-const:`telegram.MessageEntity.TEXT_LINK` and
        :tg-const:`telegram.MessageEntity.CUSTOM_EMOJI`, only certain characters need to be
        escaped in :tg-const:`telegram.constants.ParseMode.MARKDOWN_V2`. See the `official API
        documentation <https://core.telegram.org/bots/api#formatting-options>`_ for details.
        Only valid in combination with ``version=2``, will be ignored else.
   z_*`[   )precodez\`)	text_linkcustom_emojiz\)z\_*[]()~`>#+-=|{}.!z'Markdown version must be either 1 or 2!z([z])z\\\1)int
ValueErrorresubr	   )r   r   r   escape_charss       ;/app/.venv/lib/python3.13/site-packages/telegram/helpers.pyr   r   -   ss    ( 7|q	W	/) L99 L1LBCC66Bryy./r2GTBB    user_idnamec                 &    SU  S[        U5       S3$ )z
Helper function to create a user mention as HTML tag.

Args:
    user_id (:obj:`int`): The user's id which you want to mention.
    name (:obj:`str`): The name the mention is showing.

Returns:
    :obj:`str`: The inline mention for the user as HTML.
z<a href="tg://user?id=z">z</a>r   )r%   r&   s     r#   r   r   P   s     $G9Bvd|nDAAr$   c                 J    SU  3nUS:X  a	  SU SU S3$ S[        XS9 SU S3$ )a  
Helper function to create a user mention in Markdown syntax.

Args:
    user_id (:obj:`int`): The user's id which you want to mention.
    name (:obj:`str`): The name the mention is showing.
    version (:obj:`int` | :obj:`str`): Use to specify the version of Telegram's Markdown.
        Either ``1`` or ``2``. Defaults to ``1``.

Returns:
    :obj:`str`: The inline mention for the user as Markdown.
ztg://user?id=r   [z]())r   )r   )r%   r&   r   tg_links       r#   r   r   ^   sG     gY'G!|4&7)1%%t56b	CCr$   entityc                     SSK JnJn  [        X5      (       a  U nOG[        X5      (       a  U R                  (       d  gU R                  nO[        S[        U 5       S35      e[         H  nX4   (       d  M  Us  $    g)a  
Extracts the type of message as a string identifier from a :class:`telegram.Message` or a
:class:`telegram.Update`.

Args:
    entity (:class:`telegram.Update` | :class:`telegram.Message`): The ``update`` or
        ``message`` to extract from.

Returns:
    :obj:`str` | :obj:`None`: One of :class:`telegram.constants.MessageType` if the entity
    contains a message that matches one of those types. :obj:`None` otherwise.

r   r   Nz/The entity is neither Message nor Update (got: r*   )telegramr   r   
isinstanceeffective_message	TypeErrortyper   )r,   r   r   messagemessage_types        r#   r   r   q   sq     )&""	F	#	#''**I$v,WXYZZ#   $ r$   bot_usernamepayloadgroupc                 D   U b  [        U 5      S::  a  [        S5      eSU  3nU(       d  U$ [        U5      [        R                  :  a  [        S[        R                   S35      e[        R
                  " SU5      (       d  [        S5      eU(       a  SOS	nU S
U SU 3$ )a  
Creates a deep-linked URL for this :paramref:`~create_deep_linked_url.bot_username` with the
specified :paramref:`~create_deep_linked_url.payload`. See
https://core.telegram.org/bots/features#deep-linking to learn more.

The :paramref:`~create_deep_linked_url.payload` may consist of the following characters:
``A-Z, a-z, 0-9, _, -``

Note:
    Works well in conjunction with
    ``CommandHandler("start", callback, filters=filters.Regex('payload'))``

Examples:
    * ``create_deep_linked_url(bot.get_me().username, "some-params")``
    * :any:`Deep Linking <examples.deeplinking>`

Args:
    bot_username (:obj:`str`): The username to link to.
    payload (:obj:`str`, optional): Parameters to encode in the created URL.
    group (:obj:`bool`, optional): If :obj:`True` the user is prompted to select a group to
        add the bot to. If :obj:`False`, opens a one-on-one conversation with the bot.
        Defaults to :obj:`False`.

Returns:
    :obj:`str`: An URL to start the bot with specific parameters.

Raises:
    :exc:`ValueError`: If the length of the :paramref:`payload` exceeds         :tg-const:`telegram.constants.MessageLimit.DEEP_LINK_LENGTH` characters,
        contains invalid characters, or if the :paramref:`bot_username` is less than 4
        characters.
   z&You must provide a valid bot_username.zhttps://t.me/z)The deep-linking payload must not exceed z characters.z^[A-Za-z0-9_-]+$zVOnly the following characters are allowed for deep-linked URLs: A-Z, a-z, 0-9, _ and -
startgroupstart?=)lenr   r   DEEP_LINK_LENGTHr    match)r5   r6   r7   base_urlkeys        r#   r   r      s    F s<0A5ABB|n-H
7|l33378U8U7VVbc
 	
 88'11+
 	

  ,WCZqQwi((r$   )r   N)r   )NF)__doc____all__r    htmlr	   typingr
   r   r   telegram._utils.typesr   telegram.constantsr   r   r.   r   r   strr   r   r   r   r   boolr    r$   r#   <module>rL      s  & 
  1 1 1 8( KO C
 C' C:B3- C CFB%S/ B B BDeCHo DS D? D[^ D&5)<#= (3- D EJ7)7) (7)=A7)7)r$   