U
    g                     @   s   d Z ddl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mZmZ erdddlmZ G dd	 d	eeeef Zd
S )z4This module contains the StringCommandHandler class.    )TYPE_CHECKINGAnyListOptional)DEFAULT_TRUE)DVType)BaseHandler)CCTRTHandlerCallback)Applicationc                       sx   e Zd ZdZdZefdeeeee	f e
e d fddZeeee  ddd	Zeed
eee  ddddZ  ZS )StringCommandHandlera  Handler class to handle string commands. Commands are string updates that start with
    ``/``. The handler will add a :obj:`list` to the
    :class:`CallbackContext` named :attr:`CallbackContext.args`. It will contain a list of strings,
    which is the text following the command split on single whitespace characters.

    Note:
        This handler is not used to handle Telegram :class:`telegram.Update`, but strings manually
        put in the queue. For example to send messages with the bot using command line or API.

    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.

    Args:
        command (:obj:`str`): The command this handler should listen for.
        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: str, context: CallbackContext)

            The return value of the callback is usually ignored except for the special case of
            :class:`telegram.ext.ConversationHandler`.
        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:
        command (:obj:`str`): The command this handler should listen for.
        callback (:term:`coroutine function`): The callback function for this handler.
        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`.

    )commandzStringCommandHandler[CCT, RT]selfr   callbackblockc                    s   t  j||d || _d S )N)r   )super__init__r   r   	__class__ O/tmp/pip-unpacked-wheel-swnnwir2/telegram/ext/_handlers/stringcommandhandler.pyr   I   s    zStringCommandHandler.__init__)updatereturnc                 C   sD   t |tr@|dr@|dd d}|d | jkr@|dd S dS )a	  Determines whether an update should be passed to this handler's :attr:`callback`.

        Args:
            update (:obj:`object`): The incoming update.

        Returns:
            List[:obj:`str`]: List containing the text command split on whitespace.

        /   N r   )
isinstancestr
startswithsplitr   )r   r   argsr   r   r   check_updateR   s
    
z!StringCommandHandler.check_updatez)Application[Any, CCT, Any, Any, Any, Any]N)contextr   applicationcheck_resultr   c                 C   s
   ||_ dS )zqAdd text after the command to :attr:`CallbackContext.args` as list, split on single
        whitespaces.
        N)r"   )r   r$   r   r%   r&   r   r   r   collect_additional_contextb   s    
z/StringCommandHandler.collect_additional_context)__name__
__module____qualname____doc__	__slots__r   r   r   r	   r
   r   boolr   objectr   r   r#   r'   __classcell__r   r   r   r   r       s    &	
r   N)r+   typingr   r   r   r   Ztelegram._utils.defaultvaluer   Ztelegram._utils.typesr   Z"telegram.ext._handlers.basehandlerr   Ztelegram.ext._utils.typesr	   r
   r   Ztelegram.extr   r   r   r   r   r   r   <module>   s   