L i dZdZddlZddlmZddlmZmZmZddl m Z ddl m Z m Z erddlmZmZ dd ed e d eed efd Zdeeefded efdZddeeefded e d efdZdedd eefdZ ddedeeded efdZy)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_urleffective_message_typeescape_markdown mention_htmlmention_markdownNescape) TYPE_CHECKINGOptionalUnion)MarkdownVersion) MessageLimit MessageTypeMessageUpdatetextversion entity_typereturnct|dk(rd}n*t|dk(r|dvrd}n|dvrd}nd}n td tjd tj|d d |S) aHelper 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 `_ for details. Only valid in combination with ``version=2``, will be ignored else. z_*`[)precodez\`) text_link custom_emojiz\)z\_*[]()~`>#+-=|{}.!z'Markdown version must be either 1 or 2!z([z])z\\\1)int ValueErrorresubr )rrr escape_charss V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/helpers.pyrr-ss( 7|q W  / ) L 9 9 L1LBCC 66Bryy./r2GT BBuser_idnamec&d|dt|dS)a 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. zzr)r%r&s r#rrPs$G9Bvd|nD AAr$cPd|}|dk(r d|d|dSdt||d|dS)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&rtg_links r#rr^sIgY'G!|4&7)1%% tW56b  CCr$entitycddlm}m}t||r|}n>t||r|jsy|j}nt dt |dtD] }||s |cSy)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. rrNz/The entity is neither Message nor Update (got: r*)telegramrr isinstanceeffective_message TypeErrortyper)r,rrmessage message_types r#rrqsu &'" FF #''**I$v,WXYZZ# <    r$ bot_usernamepayloadgroupc|t|dkr tdd|}|s|St|tjkDrtdtjdt j d|s td|rdnd }|d |d |S) ab 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 ` 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 - startgroupstart?=)lenrrDEEP_LINK_LENGTHr match)r5r6r7base_urlkeys r#rrsFs<0A5ABB|n-H  7|l3337 8U8U7VVb c   88' 1 +   ,WCZqQwi ((r$)rN)r)NF)__doc____all__r htmlr typingr r r telegram._utils.typesr telegram.constantsrrr.rrstrrrrrrboolrr$r#rLs&  1118(KO C  C' C:B3- C CF B%S/ B B BDeCHoDSD?D[^D&!5)<#=!(3-!JEJ7)7) ( 7)=A7)7)r$