o
    Zzj±¥  ã                   @   sž  d Z ddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZ ddl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 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% 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/m0Z0m1Z1 er˜ddl2m3Z3m4Z4m5Z5 e6e7e1eee/e7f e7f Z8ee9dd�Z:eG dd„ de
e/ ƒƒZ;eG dd„ dƒƒZ<G dd„ deee/e7f ƒZ=dS )z-This module contains the ConversationHandler.é    N)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚFinalÚGenericÚNoReturnÚcast)ÚUpdate)ÚDEFAULT_TRUEÚDefaultValue)Ú
get_logger)Úbuild_repr_with_selected_attrs)ÚDVType)Úwarn)ÚApplicationHandlerStop)ÚExtBot)ÚBaseHandler)ÚCallbackQueryHandler)ÚChosenInlineResultHandler)ÚInlineQueryHandler)ÚStringCommandHandler)ÚStringRegexHandler)ÚTypeHandler)ÚTrackingDict)ÚCCTÚConversationDictÚConversationKey)ÚApplicationÚJobÚJobQueueÚConversationHandler)Ú
class_namec                   @   s6   e Zd ZU dZdZeed< eed< ded< eed< dS )	Ú_ConversationTimeoutContextz‘Used as a datastore for conversation timeouts. Passed in the
    :paramref:`JobQueue.run_once.data` parameter. See :meth:`_trigger_timeout`.
    )ÚapplicationÚcallback_contextÚconversation_keyÚupdater%   r&   ú.Application[Any, CCT, Any, Any, Any, JobQueue]r#   r$   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Ú__annotations__r	   r   © r.   r.   úe/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telegram/ext/_handlers/conversationhandler.pyr"   3   s   
 r"   c                   @   sD   e Zd ZU dZdZejed< eed< de	fdd„Z
defdd	„Zd
S )ÚPendingStatea  Thin wrapper around :class:`asyncio.Task` to handle block=False handlers. Note that this is
    a public class of this module, since :meth:`Application.update_persistence` needs to access it.
    It's still hidden from users, since this module itself is private.
    ©Ú	old_stateÚtaskr3   r2   Úreturnc                 C   s
   | j  ¡ S ©N)r3   Údone©Úselfr.   r.   r/   r6   M   s   
zPendingState.donec                 C   sl   | j  ¡ s	tdƒ‚| j  ¡ }|rt d| j¡ | jS | j  ¡ }|du r-| jdu r-tj}|S |du r4| jS |S )a�  Returns the new state of the :class:`ConversationHandler` if available. If there was an
        exception during the task execution, then return the old state. If both the new and old
        state are :obj:`None`, return `CH.END`. If only the new state is :obj:`None`, return the
        old state.

        Raises:
            :exc:`RuntimeError`: If the current task has not yet finished.
        zNew state is not yet availablez<Task function raised exception. Falling back to old state %sN)	r3   r6   ÚRuntimeErrorÚ	exceptionÚ_LOGGERr2   Úresultr    ÚEND)r8   ÚexcÚresr.   r.   r/   ÚresolveP   s    
	
þ
üzPendingState.resolveN)r(   r)   r*   r+   r,   ÚasyncioÚTaskr-   ÚobjectÚboolr6   r@   r.   r.   r.   r/   r0   A   s   
 
r0   c                   @   s  e Zd ZU dZdZdZee ed< 	 dZ	ee ed< 	 dZ
ee ed< 	 d	d
d
d	ddd	def	dddeeeeef  deeeeeeef  f deeeeef  dededededeejB dB dedB dedeeef dB dee fdd„Zdefdd„Zedeeeeef  fdd „ƒZejd!edefd"d „ƒZedeeeeeeef  f fd#d$„ƒZejd!edefd%d$„ƒZedeeeeef  fd&d'„ƒZejd!edefd(d'„ƒZedefd)d*„ƒZ e jd!edefd+d*„ƒZ edefd,d-„ƒZ!e!jd!edefd.d-„ƒZ!edefd/d0„ƒZ"e"jd!edefd1d0„ƒZ"edefd2d3„ƒZ#e#jd!edefd4d3„ƒZ#edeejB dB fd5d6„ƒZ$e$jd!edefd7d6„ƒZ$ededB fd8d9„ƒZ%e%jd!edefd:d9„ƒZ%edefd;d<„ƒZ&e&jd!edefd=d<„ƒZ&edeeef dB fd>d?„ƒZ'e'jd!edefd@d?„ƒZ'dAdBdeee(e)ef f fdCdD„Z*dEede)fdFdG„Z+dHe,j-dAdIdEedJedKe)ddfdLdM„Z.dHedAdIdEedJedKe)ddfdNdO„Z/dEede0e dB fdPdQ„Z1dEedAdRdSe0e dJededB f
dTdU„Z2	d\dHedVe)dWedB ddfdXdY„Z3dJeddfdZd[„Z4dS )]r    aè#  
    A handler to hold a conversation with a single or multiple users through Telegram updates by
    managing three collections of other handlers.

    Warning:
        :class:`ConversationHandler` heavily relies on incoming updates being processed one by one.
        When using this handler, :attr:`telegram.ext.ApplicationBuilder.concurrent_updates` should
        be set to :obj:`False`.

    Note:
        :class:`ConversationHandler` will only accept updates that are (subclass-)instances of
        :class:`telegram.Update`. This is, because depending on the :attr:`per_user` and
        :attr:`per_chat`, :class:`ConversationHandler` relies on
        :attr:`telegram.Update.effective_user` and/or :attr:`telegram.Update.effective_chat` in
        order to determine which conversation an update should belong to. For
        :attr:`per_message=True <per_message>`, :class:`ConversationHandler` uses
        :attr:`update.callback_query.message.message_id <telegram.Message.message_id>` when
        :attr:`per_chat=True <per_chat>` and
        :attr:`update.callback_query.inline_message_id <.CallbackQuery.inline_message_id>` when
        :attr:`per_chat=False <per_chat>`. For a more detailed explanation, please see our `FAQ`_.

        Finally, :class:`ConversationHandler`, does *not* handle (edited) channel posts.

    .. _`FAQ`: https://github.com/python-telegram-bot/python-telegram-bot/wiki        /Frequently-Asked-Questions#what-do-the-per_-settings-in-conversation handler-do

    The first collection, a :obj:`list` named :attr:`entry_points`, is used to initiate the
    conversation, for example with a :class:`telegram.ext.CommandHandler` or
    :class:`telegram.ext.MessageHandler`.

    The second collection, a :obj:`dict` named :attr:`states`, contains the different conversation
    steps and one or more associated handlers that should be used if the user sends a message when
    the conversation with them is currently in that state. Here you can also define a state for
    :attr:`TIMEOUT` to define the behavior when :attr:`conversation_timeout` is exceeded, and a
    state for :attr:`WAITING` to define behavior when a new update is received while the previous
    :attr:`block=False <block>` handler is not finished.

    The third collection, a :obj:`list` named :attr:`fallbacks`, is used if the user is currently
    in a conversation but the state has either no associated handler or the handler that is
    associated to the state is inappropriate for the update, for example if the update contains a
    command, but a regular text message is expected. You could use this for a ``/cancel`` command
    or to let the user know their message was not recognized.

    To change the state of conversation, the callback function of a handler must return the new
    state after responding to the user. If it does not return anything (returning :obj:`None` by
    default), the state will not change. If an entry point callback function returns :obj:`None`,
    the conversation ends immediately after the execution of this callback function.
    To end the conversation, the callback function must return :attr:`END` or ``-1``. To
    handle the conversation timeout, use handler :attr:`TIMEOUT` or ``-2``.
    Finally, :class:`telegram.ext.ApplicationHandlerStop` can be used in conversations as described
    in its documentation.

    Note:
        In each of the described collections of handlers, a handler may in turn be a
        :class:`ConversationHandler`. In that case, the child :class:`ConversationHandler` should
        have the attribute :attr:`map_to_parent` which allows returning to the parent conversation
        at specified states within the child conversation.

        Note that the keys in :attr:`map_to_parent` must not appear as keys in :attr:`states`
        attribute or else the latter will be ignored. You may map :attr:`END` to one of the parents
        states to continue the parent conversation after the child conversation has ended or even
        map a state to :attr:`END` to end the *parent* conversation from within the child
        conversation. For an example on nested :class:`ConversationHandler` s, see
        :any:`examples.nestedconversationbot`.

    Examples:
        * :any:`Conversation Bot <examples.conversationbot>`
        * :any:`Conversation Bot 2 <examples.conversationbot2>`
        * :any:`Nested Conversation Bot <examples.nestedconversationbot>`
        * :any:`Persistent Conversation Bot <examples.persistentconversationbot>`

    Args:
        entry_points (list[:class:`telegram.ext.BaseHandler`]): A list of :obj:`BaseHandler`
            objects that
            can trigger the start of the conversation. The first handler whose :meth:`check_update`
            method returns :obj:`True` will be used. If all return :obj:`False`, the update is not
            handled.
        states (dict[:obj:`object`, list[:class:`telegram.ext.BaseHandler`]]): A :obj:`dict` that
            defines the different states of conversation a user can be in and one or more
            associated :obj:`BaseHandler` objects that should be used in that state. The first
            handler whose :meth:`check_update` method returns :obj:`True` will be used.
        fallbacks (list[:class:`telegram.ext.BaseHandler`]): A list of handlers that might be used
            if the user is in a conversation, but every handler for their current state returned
            :obj:`False` on :meth:`check_update`. The first handler which :meth:`check_update`
            method returns :obj:`True` will be used. If all return :obj:`False`, the update is not
            handled.
        allow_reentry (:obj:`bool`, optional): If set to :obj:`True`, a user that is currently in a
            conversation can restart the conversation by triggering one of the entry points.
            Default is :obj:`False`.
        per_chat (:obj:`bool`, optional): If the conversation key should contain the Chat's ID.
            Default is :obj:`True`.
        per_user (:obj:`bool`, optional): If the conversation key should contain the User's ID.
            Default is :obj:`True`.
        per_message (:obj:`bool`, optional): If the conversation key should contain the Message's
            ID. Default is :obj:`False`.
        conversation_timeout (:obj:`float` | :obj:`datetime.timedelta`, optional): When this
            handler is inactive more than this timeout (in seconds), it will be automatically
            ended. If this value is ``0`` or :obj:`None` (default), there will be no timeout. The
            last received update and the corresponding :class:`context <.CallbackContext>` will be
            handled by *ALL* the handler's whose :meth:`check_update` method returns :obj:`True`
            that are in the state :attr:`ConversationHandler.TIMEOUT`.

            Caution:
                * This feature relies on the :attr:`telegram.ext.Application.job_queue` being set
                  and hence requires that the dependencies that :class:`telegram.ext.JobQueue`
                  relies on are installed.
                * Using :paramref:`conversation_timeout` with nested conversations is currently
                  not supported. You can still try to use it, but it will likely behave
                  differently from what you expect.

        name (:obj:`str`, optional): The name for this conversation handler. Required for
            persistence.
        persistent (:obj:`bool`, optional): If the conversation's dict for this handler should be
            saved. :paramref:`name` is required and persistence has to be set in
            :attr:`Application <.Application.persistence>`.

            .. versionchanged:: 20.0
                Was previously named as ``persistence``.
        map_to_parent (dict[:obj:`object`, :obj:`object`], optional): A :obj:`dict` that can be
            used to instruct a child conversation handler to transition into a mapped state on
            its parent conversation handler in place of a specified nested state.
        block (:obj:`bool`, optional): Pass :obj:`False` or :obj:`True` to set a default value for
            the :attr:`BaseHandler.block` setting of all handlers (in :attr:`entry_points`,
            :attr:`states` and :attr:`fallbacks`). The resolution order for checking if a handler
            should be run non-blocking is:

            1. :attr:`telegram.ext.BaseHandler.block` (if set)
            2. the value passed to this parameter (if any)
            3. :attr:`telegram.ext.Defaults.block` (if defaults are used)

            .. seealso:: :wiki:`Concurrency`

            .. versionchanged:: 20.0
                No longer overrides the handlers settings. Resolution order was changed.

    Raises:
        :exc:`ValueError`: If :paramref:`persistent` is used but :paramref:`name` was not set, or
            when :attr:`per_message`, :attr:`per_chat`, :attr:`per_user` are all :obj:`False`.

    Attributes:
        block (:obj:`bool`): Determines whether the callback will run in a blocking way. Always
            :obj:`True` since conversation handlers handle any non-blocking callbacks internally.

    )Ú_allow_reentryÚ_blockÚ_child_conversationsÚ_conversation_timeoutÚ_conversationsÚ_entry_pointsÚ
_fallbacksÚ_map_to_parentÚ_nameÚ	_per_chatÚ_per_messageÚ	_per_userÚ_persistentÚ_statesÚ_timeout_jobs_lockÚtimeout_jobséÿÿÿÿr=   éþÿÿÿÚTIMEOUTéýÿÿÿÚWAITINGFTNr8   zConversationHandler[CCT]Úentry_pointsÚstatesÚ	fallbacksÚallow_reentryÚper_chatÚper_userÚper_messageÚconversation_timeoutÚnameÚ
persistentÚmap_to_parentÚblockc                 C   s<  ddl m}m}m}m} d| _|| _|| _|| _|| _	|| _
|| _|| _|| _|| _|	| _|| _i | _t ¡ | _i | _tƒ | _|
rH| jsHtdƒ‚|
| _t| j| j| jfƒsYtdƒ‚| jre| jsetddd� g }|  |¡ |  |¡ | !¡ D ]}|  |¡ qu| j "d	d
„ |D ƒ¡ d}|D ]�}t#|t$t%B ƒr¢td|j&j'› d�dd� nht#|t(ƒrºt)|j*t+ƒsºtd|j*j'› d�dd� nPt#||ƒrÆtddd� nD| jråt#||t,B t-B |B |B ƒråtd|j&j'› d|› �dd� n%| jr÷t#|t.ƒs÷td|› �dd� n| j�s
t#|t.ƒ�r
td|› �dd� | j/�rt#|| j&ƒ�rtddd� qŒd S )Nr   )ÚPollAnswerHandlerÚPollHandlerÚPreCheckoutQueryHandlerÚShippingQueryHandlerTz:Conversations can't be persistent when handler is unnamed.z='per_user', 'per_chat' and 'per_message' can't all be 'False'znIf 'per_message=True' is used, 'per_chat=True' should also be used, since message IDs are not globally unique.é   ©Ú
stacklevelc                 s   s   � | ]
}t |tƒr|V  qd S r5   )Ú
isinstancer    )Ú.0Úhandlerr.   r.   r/   Ú	<genexpr>c  s   € 
ÿ
ÿz/ConversationHandler.__init__.<locals>.<genexpr>zÌ Read this FAQ entry to learn more about the per_* settings: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-Asked-Questions#what-do-the-per_-settings-in-conversationhandler-do.zJThe `ConversationHandler` only handles updates of type `telegram.Update`. z handles updates of type `str`.zkThe `ConversationHandler` only handles updates of type `telegram.Update`. The TypeHandler is set to handle Ú.z�PollHandler will never trigger in a conversation since it has no information about the chat or the user who voted in it. Do you mean the `PollAnswerHandler`?zUpdates handled by zb only have information about the user, so this handler won't ever be triggered if `per_chat=True`.z–If 'per_message=True', all entry points, state handlers, and fallbacks must be 'CallbackQueryHandler', since no other handlers have a message context.zUIf 'per_message=False', 'CallbackQueryHandler' will not be tracked for every message.z«Using `conversation_timeout` with nested conversations is currently not supported. You can still try to use it, but it will likely behave differently from what you expect.)0Útelegram.extrf   rg   rh   ri   re   rF   rJ   rR   rK   rE   rP   rN   rO   rH   rM   rL   rT   rA   ÚLockrS   rI   ÚsetrG   rb   Ú
ValueErrorrQ   Úanyr_   r^   r`   r   ÚextendÚvaluesr&   rm   r   r   Ú	__class__r(   r   Ú
issubclassÚtyper	   r   r   r   ra   )r8   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   Úall_handlersÚstate_handlersÚper_faq_linkro   r.   r.   r/   Ú__init__  sÄ   	

ý

ÿÿÿýÿý
üÿþýüþÿ
þüþüÿýü€ËzConversationHandler.__init__r4   c                 C   sT   d}t t| j ¡ ƒd|… ƒ}t|ƒ}t| jƒ|kr"|dd… d }t| | j|d�S )a—  Give a string representation of the ConversationHandler in the form
        ``ConversationHandler[name=..., states={...}]``.

        If there are more than 3 states, only the first 3 states are listed.

        As this class doesn't implement :meth:`object.__str__`, the default implementation
        will be used, which is equivalent to :meth:`__repr__`.

        Returns:
            :obj:`str`
        é   NrU   z, ...})rb   r[   )ÚdictÚlistr[   ÚitemsÚstrÚlenr   rb   )r8   Útruncation_thresholdr[   Ústates_stringr.   r.   r/   Ú__repr__¬  s   ýzConversationHandler.__repr__c                 C   ó   | j S )zŽlist[:class:`telegram.ext.BaseHandler`]: A list of :obj:`BaseHandler` objects that can
        trigger the start of the conversation.
        )rJ   r7   r.   r.   r/   rZ   Ä  s   z ConversationHandler.entry_pointsÚ_c                 C   ó   t dƒ‚)NzDYou can not assign a new value to entry_points after initialization.©ÚAttributeError©r8   rŠ   r.   r.   r/   rZ   Ë  ó   ÿc                 C   r‰   )a   dict[:obj:`object`, list[:class:`telegram.ext.BaseHandler`]]: A :obj:`dict` that
        defines the different states of conversation a user can be in and one or more
        associated :obj:`BaseHandler` objects that should be used in that state.
        )rR   r7   r.   r.   r/   r[   Ñ  ó   zConversationHandler.statesc                 C   r‹   )Nz>You can not assign a new value to states after initialization.rŒ   rŽ   r.   r.   r/   r[   Ù  ó   c                 C   r‰   )zâlist[:class:`telegram.ext.BaseHandler`]: A list of handlers that might be used if
        the user is in a conversation, but every handler for their current state returned
        :obj:`False` on :meth:`check_update`.
        )rK   r7   r.   r.   r/   r\   Ý  r�   zConversationHandler.fallbacksc                 C   r‹   )NzAYou can not assign a new value to fallbacks after initialization.rŒ   rŽ   r.   r.   r/   r\   å  r‘   c                 C   r‰   )zQ:obj:`bool`: Determines if a user can restart a conversation with an entry point.)rE   r7   r.   r.   r/   r]   é  ó   z!ConversationHandler.allow_reentryc                 C   r‹   )NzEYou can not assign a new value to allow_reentry after initialization.rŒ   rŽ   r.   r.   r/   r]   î  r�   c                 C   r‰   )zB:obj:`bool`: If the conversation key should contain the User's ID.)rP   r7   r.   r.   r/   r_   ô  r’   zConversationHandler.per_userc                 C   r‹   )Nz@You can not assign a new value to per_user after initialization.rŒ   rŽ   r.   r.   r/   r_   ù  r‘   c                 C   r‰   )zB:obj:`bool`: If the conversation key should contain the Chat's ID.)rN   r7   r.   r.   r/   r^   ý  r’   zConversationHandler.per_chatc                 C   r‹   )Nz@You can not assign a new value to per_chat after initialization.rŒ   rŽ   r.   r.   r/   r^     r‘   c                 C   r‰   )zE:obj:`bool`: If the conversation key should contain the message's ID.)rO   r7   r.   r.   r/   r`     r’   zConversationHandler.per_messagec                 C   r‹   )NzCYou can not assign a new value to per_message after initialization.rŒ   rŽ   r.   r.   r/   r`     r‘   c                 C   r‰   )z¯:obj:`float` | :obj:`datetime.timedelta`: Optional. When this
        handler is inactive more than this timeout (in seconds), it will be automatically
        ended.
        )rH   r7   r.   r.   r/   ra     s   z(ConversationHandler.conversation_timeoutc                 C   r‹   )NzLYou can not assign a new value to conversation_timeout after initialization.rŒ   rŽ   r.   r.   r/   ra     r�   c                 C   r‰   )zE:obj:`str`: Optional. The name for this :class:`ConversationHandler`.)rM   r7   r.   r.   r/   rb     r’   zConversationHandler.namec                 C   r‹   )Nz<You can not assign a new value to name after initialization.rŒ   rŽ   r.   r.   r/   rb   $  r‘   c                 C   r‰   )zÕ:obj:`bool`: Optional. If the conversations dict for this handler should be
        saved. :attr:`name` is required and persistence has to be set in
        :attr:`Application <.Application.persistence>`.
        )rQ   r7   r.   r.   r/   rc   (  r�   zConversationHandler.persistentc                 C   r‹   )NzBYou can not assign a new value to persistent after initialization.rŒ   rŽ   r.   r.   r/   rc   0  r‘   c                 C   r‰   )a
  dict[:obj:`object`, :obj:`object`]: Optional. A :obj:`dict` that can be
        used to instruct a nested :class:`ConversationHandler` to transition into a mapped state on
        its parent :class:`ConversationHandler` in place of a specified nested state.
        )rL   r7   r.   r.   r/   rd   4  r�   z!ConversationHandler.map_to_parentc                 C   r‹   )NzEYou can not assign a new value to map_to_parent after initialization.rŒ   rŽ   r.   r.   r/   rd   <  r�   r#   r   c                 Ã   s¼   �| j r
| jr
|jstdƒ‚| j}tdtƒ ƒ| _| j |¡ |j | j¡I dH }| j 	|¡ | 
¡ D ]\}}|| jkrC| j| j|d� q2| j| ji}| jD ]}| |j|d�I dH ¡ qM|S )aý  Initializes the persistence for this handler and its child conversations.
        While this method is marked as protected, we expect it to be called by the
        Application/parent conversations. It's just protected to hide it from users.

        Args:
            application (:class:`telegram.ext.Application`): The application.

        Returns:
            A dict {conversation.name -> TrackingDict}, which contains all dict of this
            conversation and possible child conversations.

        zRThis handler is not persistent, has no name or the application has no persistence!z%TrackingDict[ConversationKey, object]N)Ú	new_stateÚkey)r#   )rc   rb   Úpersistencer9   rI   r   r   r&   Úget_conversationsÚupdate_no_trackrƒ   r=   Ú_update_staterG   Ú_initialize_persistence)r8   r#   Úcurrent_conversationsÚstored_datar”   ÚstateÚoutro   r.   r.   r/   r™   B  s2   €ÿþ
€

ÿÿz+ConversationHandler._initialize_persistencer&   c                 C   s¢   |j }|j}g }| jr|du rtdƒ‚| |j¡ | jr*|du r$tdƒ‚| |j¡ | jrM|jdu r6tdƒ‚|jj	rE| |jj	¡ t|ƒS | |jj
j¡ t|ƒS )z7Builds the conversation key associated with the update.Nz2Can't build key for update without effective chat!z2Can't build key for update without effective user!z1Can't build key for update without CallbackQuery!)Úeffective_chatÚeffective_userr^   r9   ÚappendÚidr_   r`   Úcallback_queryÚinline_message_idÚmessageÚ
message_idÚtuple)r8   r&   ÚchatÚuserr”   r.   r.   r/   Ú_get_keyv  s&   
þzConversationHandler._get_keyr“   r'   Úcontextr%   c              
   Ã   sZ   �z|I d H }W n t y" } ztjd|d� W Y d }~d S d }~ww | j|||||d�S )NzTNon-blocking handler callback raised exception. Not scheduling conversation timeout.©Úexc_info)r“   r#   r&   rª   r%   )Ú	Exceptionr;   ÚdebugÚ_schedule_job)r8   r“   r#   r&   rª   r%   Úeffective_new_stater>   r.   r.   r/   Ú_schedule_job_delayed‘  s$   €ý€úûz)ConversationHandler._schedule_job_delayedc              
   C   st   || j krdS z|j}|j| j| jt||||ƒd�| j|< W dS  ty9 } ztj	d|d� W Y d}~dS d}~ww )zRSchedules a job which executes :meth:`_trigger_timeout` upon conversation timeout.N)ÚdatazFailed to schedule timeout.r«   )
r=   Ú	job_queueÚrun_onceÚ_trigger_timeoutra   r"   rT   r­   r;   r:   )r8   r“   r#   r&   rª   r%   Új_queuer>   r.   r.   r/   r¯   ª  s   
	ý€ÿz!ConversationHandler._schedule_jobc                 C   s  t |tƒsdS |js|jrdS | jr|jsdS | jr|jsdS | jr'|j	s'dS |j	r3| jr3|j	j
s3dS |  |¡}| j |¡}d}t |tƒr˜t d¡ | ¡ rs| ¡ }|jdu rf|j ¡ rf| j |d¡ d}n2|  ||¡ | j |¡}n%| j | jg ¡}|D ]}| |¡}|dur•|dur•| j|||f  S q}dS t dt|ƒt|ƒ¡ d}|du s¬| jrÉ| jD ]}	|	 |¡}|durÂ|durÂ|	} nq¯|du rÉdS |du�r	|du �r	| j |g ¡D ]}
|
 |¡}|durí|durí|
} nqÚ| jD ]}| |¡}|du�r|du�r|} nqñdS ||||fS )a(  
        Determines whether an update should be handled by this conversation handler, and if so in
        which state the conversation currently is.

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

        Returns:
            :obj:`bool`

        Nz&Waiting for asyncio Task to finish ...Fz'Selecting conversation %s with state %s)rm   r	   Úchannel_postÚedited_channel_postr^   rž   r_   rŸ   r`   r¢   r¤   r©   rI   Úgetr0   r;   r®   r6   r@   r2   r3   r:   Úpopr˜   r[   rY   Úcheck_updater„   r]   rZ   r\   )r8   r&   r”   rœ   Úcheckr?   ÚhandlersÚhandler_ro   Úentry_pointÚ	candidateÚfallbackr.   r.   r/   r»   Â  sr   




€

€
€

€z ConversationHandler.check_updatez)Application[Any, CCT, Any, Any, Any, Any]Úcheck_resultc              
   Ã   s`  �|\}}}}d}	| j 4 I dH š | j |d¡}
|
dur |
 ¡  W d  ƒI dH  n1 I dH s0w   Y  |jtur>|j}n!| jturG| j}nt|jt	ƒrY|jj
durY|jj
j}nt |j¡}z#|rn| ||||¡I dH }n|j| ||||¡|d|j› d�d�}W n ty™ } z|j}d}	W Y d}~nd}~ww | j 4 I dH šJ | jrá|jdu r±tddd	� n0|jjjs½td
dd	� n$t|tjƒrØ|j|  |||||¡|d|j› d�d� n	|  |||||¡ W d  ƒI dH  n1 I dH sñw   Y  t| jtƒ�r|| jv �r|  | j||¡ |	�rt| j |¡ƒ‚| j |¡S || j k�r)|  |||¡ |	�r.t‚dS )aL  Send the update to the callback for the current state and BaseHandler

        Args:
            check_result: The result from :meth:`check_update`. For this handler it's a tuple of
                the conversation state, key, handler, and the handler's check result.
            update (:class:`telegram.Update`): Incoming telegram update.
            application (:class:`telegram.ext.Application`): Application that originated the
                update.
            context (:class:`telegram.ext.CallbackContext`): The context as provided by
                the application.

        FNzConversationHandler:z:handle_update:non_blocking_cb)Ú	coroutiner&   rb   TzHIgnoring `conversation_timeout` because the Application has no JobQueue.é   rk   zQIgnoring `conversation_timeout` because the Applications JobQueue is not running.z:handle_update:timeout_job)r&   rb   )!rS   rT   rº   Úschedule_removalre   r
   rF   rm   Úbotr   Údefaultsr   Ú	get_valueÚhandle_updateÚcreate_taskÚ	update_idr   rœ   ra   r³   r   Ú	schedulerÚrunningrA   rB   r±   r¯   rd   r�   r˜   r=   r¹   rY   )r8   r&   r#   rÂ   rª   Úcurrent_stater%   ro   Úhandler_check_resultÚraise_dp_handler_stopÚtimeout_jobre   r“   r:   r.   r.   r/   rÉ     s†   €€(û

ÿÿû€€þ
þ
ý
ÿû€(èz!ConversationHandler.handle_updater”   ro   c                 C   s¸   || j kr|| jv r| j|= d S d S t|tjƒr't| j |¡|d�| j|< d S |d urZ|| jvrSt|d ur;t	|j
jƒnd› d|› d| jd urKd| j nd› d�dd	� || j|< d S d S )
Nr1   r   z returned state z, which is unknown to the ConversationHandlerú Ú rq   rj   rk   )r=   rI   rm   rA   rB   r0   r¹   r[   r   ÚreprÚcallbackr(   rb   )r8   r“   r”   ro   r.   r.   r/   r˜   �  s(   

þÿ
ÿþüøz!ConversationHandler._update_statec           	   	   Ã   s(  �t d|jƒ}t d|jƒ}t d|j¡ |j}| j4 I dH š' | j 	|j¡}||ur6	 W d  ƒI dH  dS | j|j= W d  ƒI dH  n1 I dH sKw   Y  | j
 	| jg ¡}|D ]/}| |j¡}|dur‰|dur‰z| |j|j||¡I dH  W qZ tyˆ   tddd� Y qZw qZ|  | j|j¡ dS )	zßThis is run whenever a conversation has timed out. Also makes sure that all handlers
        which are in the :attr:`TIMEOUT` state and whose :meth:`BaseHandler.check_update` returns
        :obj:`True` is handled.
        r   r"   z7Conversation timeout was triggered for conversation %s!NFzWApplicationHandlerStop in TIMEOUT state of ConversationHandler has no effect. Ignoring.rj   rk   )r   Újobr²   r;   r®   r%   r$   rS   rT   r¹   r[   rW   r»   r&   rÉ   r#   r   r   r˜   r=   )	r8   rª   rÖ   Úctxtr$   Ú	found_jobr½   ro   r¼   r.   r.   r/   rµ   ˜  s<   €ÿü(ûÿ
ýÿ€z$ConversationHandler._trigger_timeoutr5   )5r(   r)   r*   r+   r,   r=   r   Úintr-   rW   rY   r
   r‚   r   r	   r   rC   r�   rD   ÚfloatÚdtmÚ	timedeltar„   r   r   rˆ   ÚpropertyrZ   Úsetterr   r[   r\   r]   r_   r^   r`   ra   rb   rc   rd   r   r   r™   r©   rA   rB   r±   r¯   Ú_CheckUpdateTyper»   rÉ   r˜   rµ   r.   r.   r.   r/   r    n   s*  
  	óÿþýüûúùø	÷
öõô
ó &þ	ÿ
þ4þýüûú
ùþýüûú
ù[þýüû
úeÿÿÿÿ
þ)>r+   rA   ÚdatetimerÛ   Údataclassesr   Útypingr   r   r   r   r   r   Útelegramr	   Útelegram._utils.defaultvaluer
   r   Útelegram._utils.loggingr   Útelegram._utils.reprr   Útelegram._utils.typesr   Útelegram._utils.warningsr   Útelegram.ext._applicationr   Útelegram.ext._extbotr   Ú"telegram.ext._handlers.basehandlerr   Ú+telegram.ext._handlers.callbackqueryhandlerr   Ú0telegram.ext._handlers.choseninlineresulthandlerr   Ú)telegram.ext._handlers.inlinequeryhandlerr   Ú+telegram.ext._handlers.stringcommandhandlerr   Ú)telegram.ext._handlers.stringregexhandlerr   Ú"telegram.ext._handlers.typehandlerr   Ú telegram.ext._utils.trackingdictr   Útelegram.ext._utils.typesr   r   r   rr   r   r   r   r¦   rC   rß   r(   r;   r"   r0   r    r.   r.   r.   r/   Ú<module>   s>    ,