U
    g'                     @   s   d Z ddlZddlmZmZmZ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mZ erdd	lmZ e	d
ZG dd deeeef ZdS )z2This module contains the InlineQueryHandler class.    N)	TYPE_CHECKINGAnyListMatchOptionalPatternTypeVarUnioncast)Update)DEFAULT_TRUE)DVType)BaseHandler)CCTHandlerCallback)ApplicationRTc                       s   e Zd ZdZdZdedfdeeee	f e
eeee f  ee e
ee  d fddZee
eeee f  dd	d
Zeede
eeee f  ddddZ  ZS )InlineQueryHandlera

  
    BaseHandler class to handle Telegram updates that contain a
    :attr:`telegram.Update.inline_query`.
    Optionally based on a regex. Read the documentation of the :mod:`re` module for more
    information.

    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.
        * :attr:`telegram.InlineQuery.chat_type` will not be set for inline queries from secret
          chats and may not be set for inline queries coming from third-party clients. These
          updates won't be handled, if :attr:`chat_types` is passed.

    Examples:
        :any:`Inline Bot <examples.inlinebot>`


    Args:
        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`.
        pattern (:obj:`str` | :func:`re.Pattern <re.compile>`, optional): Regex pattern.
            If not :obj:`None`, :func:`re.match` is used on :attr:`telegram.InlineQuery.query`
            to determine if an update should be handled by this handler.
        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`
        chat_types (List[:obj:`str`], optional): List of allowed chat types. If passed, will only
            handle inline queries with the appropriate :attr:`telegram.InlineQuery.chat_type`.

            .. versionadded:: 13.5
    Attributes:
        callback (:term:`coroutine function`): The callback function for this handler.
        pattern (:obj:`str` | :func:`re.Pattern <re.compile>`): Optional. Regex pattern to test
            :attr:`telegram.InlineQuery.query` against.
        chat_types (List[:obj:`str`]): Optional. List of allowed chat types.

            .. versionadded:: 13.5
        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`.

    )
chat_typespatternNzInlineQueryHandler[CCT, RT]selfcallbackr   blockr   c                    s4   t  j||d t|tr$t|}|| _|| _d S )N)r   )super__init__
isinstancestrrecompiler   r   r   	__class__ M/tmp/pip-unpacked-wheel-swnnwir2/telegram/ext/_handlers/inlinequeryhandler.pyr   Y   s
    

zInlineQueryHandler.__init__)updatereturnc                 C   sb   t |tr^|jr^| jdk	r,|jj| jkr,dS | jrT|jjrTt| j|jj }rT|S | js^dS dS )z
        Determines whether an update should be passed to this handler's :attr:`callback`.

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

        Returns:
            :obj:`bool` | :obj:`re.match`

        NFT)	r   r   Zinline_queryr   Z	chat_typer   queryr   match)r   r$   r'   r"   r"   r#   check_updateh   s    
zInlineQueryHandler.check_updatez)Application[Any, CCT, Any, Any, Any, Any])contextr$   applicationcheck_resultr%   c                 C   s   | j rtt|}|g|_dS )zAdd the result of ``re.match(pattern, update.inline_query.query)`` to
        :attr:`CallbackContext.matches` as list with one element.
        N)r   r
   r   matches)r   r)   r$   r*   r+   r"   r"   r#   collect_additional_context   s    

z-InlineQueryHandler.collect_additional_context)__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r	   r   r   r   boolr   r   objectr   r(   r-   __classcell__r"   r"   r    r#   r   #   s&   3
 r   )r1   r   typingr   r   r   r   r   r   r   r	   r
   Ztelegramr   Ztelegram._utils.defaultvaluer   Ztelegram._utils.typesr   Z"telegram.ext._handlers.basehandlerr   Ztelegram.ext._utils.typesr   r   Ztelegram.extr   r   r   r"   r"   r"   r#   <module>   s   ,