
    Yi                         S r SSKrSSKJrJrJrJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  SSKJr  SS	KJrJr  \(       a  SS
KJr  \" S5      r " S S\\	\\4   5      rg)z-This module contains the PrefixHandler class.    N)TYPE_CHECKINGAnyOptionalTypeVarUnion)Update)DEFAULT_TRUE)SCTDVType)filters)BaseHandler)CCTHandlerCallback)ApplicationRTc                     ^  \ rS rSrSrSrS\4SSS\\   S\\   S	\	\
\\4   S
\\R                     S\\   4U 4S jjjrS\S\\\\\\   \\\\\\4   4      4   4      4S jrS\S\
SSS\\\\\\   \\   4   4      SS4
S jrSrU =r$ )PrefixHandler$   a  Handler class to handle custom prefix commands.

This is an intermediate handler between :class:`MessageHandler` and :class:`CommandHandler`.
It supports configurable commands with the same options as :class:`CommandHandler`. It will
respond to every combination of :paramref:`prefix` and :paramref:`command`.
It will add a :obj:`list` to the :class:`CallbackContext` named :attr:`CallbackContext.args`,
containing a list of strings, which is the text following the command split on single or
consecutive whitespace characters.

Examples:

    Single prefix and command:

    .. code:: python

        PrefixHandler("!", "test", callback)  # will respond to '!test'.

    Multiple prefixes, single command:

    .. code:: python

        PrefixHandler(["!", "#"], "test", callback)  # will respond to '!test' and '#test'.

    Multiple prefixes and commands:

    .. code:: python

        PrefixHandler(
            ["!", "#"], ["test", "help"], callback
        )  # will respond to '!test', '#test', '!help' and '#help'.


By default, the handler listens to messages as well as edited messages. To change this behavior
use :attr:`~filters.UpdateType.EDITED_MESSAGE <telegram.ext.filters.UpdateType.EDITED_MESSAGE>`

Note:
    * :class:`PrefixHandler` does *not* handle (edited) channel posts.

Warning:
    When setting :paramref:`block` to :obj:`False`, you cannot rely on adding custom
    attributes to :class:`telegram.ext.CallbackContext`. See its docs for more info.

.. versionchanged:: 20.0

    * :class:`PrefixHandler` is no longer a subclass of :class:`CommandHandler`.
    * Removed the attributes ``command`` and ``prefix``. Instead, the new :attr:`commands`
      contains all commands that this handler listens to as a :class:`frozenset`, which
      includes the prefixes.
    * Updating the prefixes and commands this handler listens to is no longer possible.

Args:
    prefix (:obj:`str` | Collection[:obj:`str`]):
        The prefix(es) that will precede :paramref:`command`.
    command (:obj:`str` | Collection[:obj:`str`]):
        The command or list of commands this handler should listen for. Case-insensitive.
    callback (:term:`coroutine function`): The callback function for this handler. Will be
        called when :meth:`check_update` has determined that an update should be processed by
        this handler. Callback signature::

            async def callback(update: Update, context: CallbackContext)

        The return value of the callback is usually ignored except for the special case of
        :class:`telegram.ext.ConversationHandler`.
    filters (:class:`telegram.ext.filters.BaseFilter`, optional): A filter inheriting from
        :class:`telegram.ext.filters.BaseFilter`. Standard filters can be found in
        :mod:`telegram.ext.filters`. Filters can be combined using bitwise
        operators (``&`` for :keyword:`and`, ``|`` for :keyword:`or`, ``~`` for :keyword:`not`)
    block (:obj:`bool`, optional): Determines whether the return value of the callback should
        be awaited before processing the next handler in
        :meth:`telegram.ext.Application.process_update`. Defaults to :obj:`True`.

        .. seealso:: :wiki:`Concurrency`

Attributes:
    commands (frozenset[:obj:`str`]): The commands that this handler will listen for, i.e. the
        combinations of :paramref:`prefix` and :paramref:`command`.
    callback (:term:`coroutine function`): The callback function for this handler.
    filters (:class:`telegram.ext.filters.BaseFilter`): Optional. Only allow updates with these
        Filters.
    block (:obj:`bool`): Determines whether the return value of the callback should be
        awaited before processing the next handler in
        :meth:`telegram.ext.Application.process_update`.

)commandsr   NselfzPrefixHandler[CCT, RT]prefixcommandcallbackr   blockc                   > [         T	U ]  X5S9  [        U[        5      (       a  UR	                  5       1OU Vs1 s H  ofR	                  5       iM     snn[        U[        5      (       a  UR	                  5       1OU Vs1 s H  ofR	                  5       iM     snn[        S [        R                  " Xx5       5       5      U l        Ub  UU l        g [        R                  R                  U l        g s  snf s  snf )N)r   r   c              3   .   #    U  H  u  pX-   v   M     g 7f)N ).0pcs      O/app/.venv/lib/python3.13/site-packages/telegram/ext/_handlers/prefixhandler.py	<genexpr>)PrefixHandler.__init__.<locals>.<genexpr>   s      2
CdaAECs   )super__init__
isinstancestrlower	frozenset	itertoolsproductr   filters_module
UpdateTypeMESSAGESr   )
r   r   r   r   r   r   xprefixesr   	__class__s
            r!   r%   PrefixHandler.__init__}   s     	(8'1&#'>'>FLLN#X^D_X^STWWYX^D_(27C(@(@GMMO$ZaFbZaUVwwyZaFb(1 2
'//C2
 )
 *G 	0>0I0I0R0R 	 E`Fbs   C1?C6updatereturnc                 V   [        U[        5      (       a  UR                  (       a  UR                  nUR                  (       af  UR                  R	                  5       nUS   R                  5       U R                  ;  a  gU R                  R                  U5      nU(       a  USS U4$ gg)zDetermines whether an update should be passed to this handler's :attr:`callback`.

Args:
    update (:class:`telegram.Update` | :obj:`object`): Incoming update.

Returns:
    :obj:`list`: The list of args for the handler.

r   N   F)	r&   r   effective_messagetextsplitr(   r   r   check_update)r   r3   message	text_listfilter_results        r!   r:   PrefixHandler.check_update   s     ff%%&*B*B..G||#LL..0	Q<%%'t}}< $ 9 9& A $QR=-77    contextapplicationz)Application[Any, CCT, Any, Any, Any, Any]check_resultc                     [        U[        5      (       a8  US   Ul        [        US   [        5      (       a  UR	                  US   5        ggg)zAdd text after the command to :attr:`CallbackContext.args` as list, split on single
whitespaces and add output of data filters to :attr:`CallbackContext` as well.
r   r6   N)r&   tupleargsdictr3   )r   r@   r3   rA   rB   s        r!   collect_additional_context(PrefixHandler.collect_additional_context   sG     lE**'?GL,q/400|A/ 1 +r?   )__name__
__module____qualname____firstlineno____doc__	__slots__r	   r
   r'   r   r   r   r   r   r,   
BaseFilterr   boolr%   objectr   rD   listrF   r   r:   rG   __static_attributes____classcell__)r1   s   @r!   r   r   $   s"   Sl (I 8<*
&
C
 S
 "&#r/2	

 .334
 d|
 
*	%eDIxdDcN>R8S/T$TUUV	W200 0 A	0
 uT5cHTN1J+K%KLM0 
0 0r?   r   )rM   r*   typingr   r   r   r   r   telegramr   telegram._utils.defaultvaluer	   telegram._utils.typesr
   r   telegram.extr   r,   "telegram.ext._handlers.basehandlerr   telegram.ext._utils.typesr   r   r   r   r   r   r?   r!   <module>r\      sM   & 4  ? ?  5 - 2 : :(T]T0KR0 T0r?   