
    ՟f                        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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/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 er
ddl7m8Z8m9Z9m:Z: ee;e6e$ee4e;f   e;f   Z< ee=d      Z>e G d de
e4                Z?e G d d             Z@ G d de$ee4e;f         ZAy)z-This module contains the ConversationHandler.    N)	dataclass)TYPE_CHECKINGAnyDictFinalGenericListNoReturnOptionalSetTupleUnion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                   >    e Zd ZU dZdZeed<   eed<   ded<   eed<   y)	_ConversationTimeoutContextzUsed 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!        e/var/www/cvtools/html/venv/lib/python3.12/site-packages/telegram/ext/_handlers/conversationhandler.pyr*   r*   ?   s&     RI%%NAAr7   r*   c                   V    e Zd ZU dZdZej                  ed<   eed<   de	fdZ
defdZy)	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taskr=   r<   returnc                 6    | j                   j                         S N)r=   doneselfs    r8   rA   zPendingState.doneY   s    yy~~r7   c                 p   | j                   j                         st        d      | j                   j                         }|r,t        j                  d| j
                         | j
                  S | j                   j                         }|| j
                  t        j                  }|S || 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 %s)	r=   rA   RuntimeError	exception_LOGGERr<   resultr'   END)rC   excress      r8   resolvezPendingState.resolve\   s     yy~~?@@ii!!#N >>!ii ;4>>1%))C
 
	 [>>!
r7   N)r0   r1   r2   r3   r4   asyncioTaskr5   objectboolrA   rL   r6   r7   r8   r:   r:   M   s6    
 &I
,, d   r7   r:   c                      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eej.                  f      dee   dedeeeef      dee   fdZdefdZedeeeeef      fd       Zej<                  dedefd       Zedeeeeeeef      f   fd        Z e j<                  dedefd!       Z edeeeeef      fd"       Z!e!j<                  dedefd#       Z!edefd$       Z"e"j<                  dedefd%       Z"edefd&       Z#e#j<                  dedefd'       Z#edefd(       Z$e$j<                  dedefd)       Z$edefd*       Z%e%j<                  dedefd+       Z%edeeeej.                  f      fd,       Z&e&j<                  dedefd-       Z&edee   fd.       Z'e'j<                  dedefd/       Z'edefd0       Z(e(j<                  dedefd1       Z(edeeeef      fd2       Z)e)j<                  dedefd3       Z)d4d5deee*e+ef   f   fd6Z,d7ede+fd8Z-d9e.j^                  d4d:d7ed;ed<e+ddfd=Z0d9ed4d:d7ed;ed<e+ddfd>Z1d7edee2e      fd?Z3d7ed4d@dAe2e   d;edee   f
dBZ4	 dGd9edCe+dDee   ddfdEZ5d;eddfdFZ6y)Hr'   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_jobsrI   TIMEOUTWAITINGFTNrC   zConversationHandler[CCT]entry_pointsstates	fallbacksallow_reentryper_chatper_userper_messageconversation_timeoutname
persistentmap_to_parentblockc           	         ddl m}m}m}m} d| _        || _        || _        || _        || _	        || _
        || _        || _        || _        || _        |	| _        || _        i | _        t%        j&                         | _        i | _        t-               | _        |
r| j0                  st3        d      |
| _        t7        | j8                  | j:                  | j<                  f      st3        d      | j<                  r| j:                  st?        dd       g }|jA                  |       |jA                  |       |jC                         D ]  }|jA                  |        | j.                  jE                  d	 |D               d
}|D ]  }tG        |tH        tJ        f      r't?        d|jL                  jN                   dd       ntG        |tP              r@tS        |jT                  tV              s&t?        d|jT                  jN                   dd       ntG        ||      rt?        dd       n| j:                  rAtG        ||tX        tZ        ||f      r(t?        d|jL                  jN                   d| d       nY| j<                  r!tG        |t\              st?        d| d       n,| j<                  s tG        |t\              rt?        d| d       | j^                  s_tG        || jL                        swt?        dd        y )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              3   B   K   | ]  }t        |t              s|  y wr@   )
isinstancer'   ).0handlers     r8   	<genexpr>z/ConversationHandler.__init__.<locals>.<genexpr>q  s      )
:gGZ3[G)
s   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 .zPollHandler 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`.zIf '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.zUsing `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.extrt   ru   rv   rw   rr   rS   rW   r_   rX   rR   r]   r[   r\   rU   rZ   rY   ra   rM   Lockr`   rV   setrT   ro   
ValueErrorr^   anyrl   rk   rm   r   extendvaluesr.   r|   r   r   	__class__r0   r   
issubclasstyper   r   r   r   rn   )rC   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rt   ru   rv   rw   all_handlersstate_handlersper_faq_linkr~   s                        r8   __init__zConversationHandler.__init__*  s    	
 	
 $(
$)EQMSBK$1''"-  	" %)
>K >@"),,.02>Ae!diiYZZ!+DMM4==$2B2BCD\]]DMM= @BL)I&$mmo 	0N/	0 	!!(( )
#/)
 	
_ 	 $ <	G'$8:L#MN`((1122QS 
 G[1*W\\SY:Z99@9N9N8OqR 
 G[1+  !	 ,*1/)	 )'*;*;*D*D)E F\#n&  !	 !!*W>R*S..:^=  !	 %%*W>R*S11=@  ((Z-P8  !	o<	r7   r>   c                     d}t        t        | j                  j                               d|       }t	        |      }t        | j                        |kD  r|dd dz   }t        | | j                  |      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`
           Nrb   z, ...})ro   rh   )dictlistrh   itemsstrlenr   ro   )rC   truncation_thresholdrh   states_strings       r8   __repr__zConversationHandler.__repr__  su      !d4;;,,./0E1EFGFt{{22)#2.9M- 
 	
r7   c                     | j                   S )zList[:class:`telegram.ext.BaseHandler`]: A list of :obj:`BaseHandler` objects that can
        trigger the start of the conversation.
        )rW   rB   s    r8   rg   z ConversationHandler.entry_points  s    
 !!!r7   _c                     t        d      )NzDYou can not assign a new value to entry_points after initialization.AttributeErrorrC   r   s     r8   rg   z ConversationHandler.entry_points  s    R
 	
r7   c                     | j                   S )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.
        )r_   rB   s    r8   rh   zConversationHandler.states  s     ||r7   c                     t        d      )Nz>You can not assign a new value to states after initialization.r   r   s     r8   rh   zConversationHandler.states  s    ]^^r7   c                     | j                   S )zList[: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`.
        )rX   rB   s    r8   ri   zConversationHandler.fallbacks  s     r7   c                     t        d      )NzAYou can not assign a new value to fallbacks after initialization.r   r   s     r8   ri   zConversationHandler.fallbacks  s    `aar7   c                     | j                   S )zQ:obj:`bool`: Determines if a user can restart a conversation with an entry point.)rR   rB   s    r8   rj   z!ConversationHandler.allow_reentry  s     """r7   c                     t        d      )NzEYou can not assign a new value to allow_reentry after initialization.r   r   s     r8   rj   z!ConversationHandler.allow_reentry      S
 	
r7   c                     | j                   S )zB:obj:`bool`: If the conversation key should contain the User's ID.)r]   rB   s    r8   rl   zConversationHandler.per_user       ~~r7   c                     t        d      )Nz@You can not assign a new value to per_user after initialization.r   r   s     r8   rl   zConversationHandler.per_user	      _``r7   c                     | j                   S )zB:obj:`bool`: If the conversation key should contain the Chat's ID.)r[   rB   s    r8   rk   zConversationHandler.per_chat  r   r7   c                     t        d      )Nz@You can not assign a new value to per_chat after initialization.r   r   s     r8   rk   zConversationHandler.per_chat  r   r7   c                     | j                   S )zE:obj:`bool`: If the conversation key should contain the message's ID.)r\   rB   s    r8   rm   zConversationHandler.per_message  s        r7   c                     t        d      )NzCYou can not assign a new value to per_message after initialization.r   r   s     r8   rm   zConversationHandler.per_message  s    bccr7   c                     | j                   S )z:obj:`float` | :obj:`datetime.timedelta`: Optional. When this
        handler is inactive more than this timeout (in seconds), it will be automatically
        ended.
        )rU   rB   s    r8   rn   z(ConversationHandler.conversation_timeout  s     )))r7   c                     t        d      )NzLYou can not assign a new value to conversation_timeout after initialization.r   r   s     r8   rn   z(ConversationHandler.conversation_timeout)  s    Z
 	
r7   c                     | j                   S )zE:obj:`str`: Optional. The name for this :class:`ConversationHandler`.)rZ   rB   s    r8   ro   zConversationHandler.name/  s     zzr7   c                     t        d      )Nz<You can not assign a new value to name after initialization.r   r   s     r8   ro   zConversationHandler.name4  s    [\\r7   c                     | j                   S )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>`.
        )r^   rB   s    r8   rp   zConversationHandler.persistent8  s     r7   c                     t        d      )NzBYou can not assign a new value to persistent after initialization.r   r   s     r8   rp   zConversationHandler.persistent@  s    abbr7   c                     | j                   S )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.
        )rY   rB   s    r8   rq   z!ConversationHandler.map_to_parentD  s     """r7   c                     t        d      )NzEYou can not assign a new value to map_to_parent after initialization.r   r   s     r8   rq   z!ConversationHandler.map_to_parentL  r   r7   r+   r$   c                   K   | j                   r| j                  r|j                  st        d      | j                  }t        t        t        t        f   t                     | _        | j                  j                  |       |j                  j                  | j                         d{   }| j                  j                  |       |j                         D ]2  \  }}|| j                  k(  s| j                  | j                  |       4 | j                  | j                  i}| j                  D ]+  }|j                  |j!                  |       d{          - |S 7 7 w)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!N)	new_statekey)r+   )rp   ro   persistencerE   rV   r   r    r#   rO   r.   get_conversationsupdate_no_trackr   rI   _update_staterT   _initialize_persistence)rC   r+   current_conversationsstored_datar   stateoutr~   s           r8   r   z+ConversationHandler._initialize_persistenceR  sN     DII+2I2I 
 !% 3 3"&01N

 	""#89 (33EEdiiPP++K8 &++- 	@JC ""TXX3"?	@ yy$--.00 	GJJ55 + 6  	 
) Qs,   B)E(+E$,AE(1A&E(E&
E(&E(r.   c                 L   |j                   }|j                  }g }| j                  r(|t        d      |j	                  |j
                         | j                  r(|t        d      |j	                  |j
                         | j                  r|j                  t        d      |j                  j                  r0|j	                  |j                  j                         t        |      S |j	                  |j                  j                  j                         t        |      S )z7Builds the conversation key associated with the update.z2Can'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_userrk   rE   appendidrl   rm   callback_queryinline_message_idmessage
message_idtuple)rC   r.   chatuserr   s        r8   _get_keyzConversationHandler._get_key  s    $$$$%'==|"#WXXJJtww==|"#WXXJJtww$$,"#VWW$$66

600BBC Sz 

60088CCDSzr7   r   r/   contextr-   c                    K   	 | d {   }| j                  |||||      S 7 # t         $ r!}t        j                  d|       Y d }~y d }~ww xY ww)NzTNon-blocking handler callback raised exception. Not scheduling conversation timeout.exc_info)r   r+   r.   r   r-   )	ExceptionrG   debug_schedule_job)rC   r   r+   r.   r   r-   effective_new_staterJ   s           r8   _schedule_job_delayedz)ConversationHandler._schedule_job_delayed  sn     	(1/ !!)#- " 
 	
 #2 	MM  
 	s6   A& $& A& 	AAAAAc           
         || j                   k(  ry	 |j                  }|j                  | j                  | j                  t        ||||            | j                  |<   y# t        $ r!}t        j                  d|       Y d}~yd}~ww xY w)zRSchedules a job which executes :meth:`_trigger_timeout` upon conversation timeout.N)datazFailed to schedule timeout.r   )
rI   	job_queuerun_once_trigger_timeoutrn   r*   ra   r   rG   rF   )rC   r   r+   r.   r   r-   j_queuerJ   s           r8   r   z!ConversationHandler._schedule_job  s      		K!++G292B2B%%))01A6;X_` 3C 3D./
  	K;cJJ	Ks   AA   	B
)BB
c                    t        |t              sy|j                  s|j                  ry| j                  r|j
                  sy| j                  r|j                  sy| j                  r|j                  sy|j                  r#| j                  r|j                  j                  sy| j                  |      }| j                  j                  |      }d}t        |t              r t        j!                  d       |j#                         r|j%                         }|j&                  9|j(                  j+                         r| j                  j-                  |d       d}n| j/                  ||       | j                  j                  |      }nX| j0                  j                  | j2                  g       }|D ],  }|j5                  |      }||dus| j2                  |||fc S  yt        j!                  dt7        |      t7        |             d}|| j8                  r0| j:                  D ]  }	|	j5                  |      }||dus|	} n |y|m|k| j0                  j                  |g       D ]  }
|
j5                  |      }||dus|
} n/ | j<                  D ]  }|j5                  |      }||dus|} n y||||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)r|   r   channel_postedited_channel_postrk   r   rl   r   rm   r   r   r   rV   getr:   rG   r   rA   rL   r<   r=   rF   popr   rh   rf   check_updater   rj   rg   ri   )rC   r.   r   r   checkrK   handlershandler_r~   entry_point	candidatefallbacks               r8   r   z ConversationHandler.check_update  s    &&)&"<"<==!6!6==!6!6F$9$9  T]]6;P;P;X;XmmF###'',"& e\*MMBC zz|mmo??*uzz/C/C/E''++C6 E&&sC0 //33C8E  ;;??4<<< ( BH$11&9E(U%-?#||S(EAAB ?S3u:V)- =D..#00  #008$e);)G	  = ![[__UB7  	!..v6$e);'G	  !%  H$11&9E(U%-?"*	   c7E))r7   z)Application[Any, CCT, Any, Any, Any, Any]check_resultc           
        K   |\  }}}}d}	| j                   4 d{    | j                  j                  |d      }
|
|
j                          ddd      d{    |j                  t
        ur|j                  }n| j                  t
        ur| j                  }npt        |j                  t              r7|j                  j                  !|j                  j                  j                  }nt        j                  |j                        }	 |r|j                  ||||       d{   }n4|j                  |j                  ||||      |d|j                   d      }| j                   4 d{    | j$                  r|j&                  t)        dd	       n|j&                  j*                  j,                  st)        d
d	       net        |t.        j0                        r6|j                  | j3                  |||||      |d|j                   d       n| j5                  |||||       ddd      d{    t        | j6                  t8              rl|| j6                  v r^| j;                  | j<                  ||       |	r$t!        | j6                  j?                  |            | j6                  j?                  |      S || j@                  k7  r| j;                  |||       |	rt         y7 7 # 1 d{  7  sw Y   xY w7 # t         $ r}|j"                  }d}	Y d}~d}~ww xY w7 7 # 1 d{  7  sw Y   xY ww)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.   ro   TzHIgnoring `conversation_timeout` because the Application has no JobQueue.   ry   zQIgnoring `conversation_timeout` because the Applications JobQueue is not running.z:handle_update:timeout_job)r.   ro   )!r`   ra   r   schedule_removalrr   r   rS   r|   botr   defaultsr   	get_valuehandle_updatecreate_task	update_idr   r   rn   r   r   	schedulerrunningrM   rN   r   r   rq   r   r   rI   r   rf   )rC   r.   r+   r   r   current_stater-   r~   handler_check_resultraise_dp_handler_stoptimeout_jobrr   r   rF   s                 r8   r   z!ConversationHandler.handle_update-  s#    & JVF'2F %** 	/ 	/++//0@$GK&,,.	/ 	/ ==,MME[[,KKE0[__5M5M5YOO,,22E **7==9E	)*1*?*?K)=w+ %	 (33%33-A7 "/0@0@/AA_` 4 	 ** 	b 	b((((0b#$ %..88@@'#$
  	7<<8  ++22%{FGEU  &3F4D4D3EE_` ,  &&y+vwP`a1	b 	b4 d(($/IASAS4Stxx)97C$,T-?-?-C-CI-NOO%%)))44DLL(y*:GD  )(Y	/ 	/ 	/ 	/ 	/,% & 	)!I$(!	)	b 	b 	b 	b 	bs   MK0M/K6MK3B2ML 'L(9L !M1L42M5B:L9/M:L7;B6M3M6L	<K?=L	ML 	L1L,&M,L11M7M9M?M MMr   r~   c                    || j                   k(  r|| j                  v r| j                  |= y y t        |t        j                        r4t        | j                  j                  |      |      | j                  |<   y |p|| j                  vrRt        |t        |j                  j                        nd d| d| j                  d| j                  z   nd dd	       || j                  |<   y y )
Nr;   r   z returned state z, which is unknown to the ConversationHandler  r   rx   ry   )rI   rV   r|   rM   rN   r:   r   rh   r   reprcallbackr0   ro   )rC   r   r   r~   s       r8   r   z!ConversationHandler._update_state  s      d)))'', * 	7<<0'3--11#6Y(D$ "+:A:MtG,,556S`a b&&/[ 1*=AYY=R#		/XZ)[[\^  !	 (1D$ #r7   c                 t  K   t        d|j                        }t        t        |j                        }t        j                  d|j                         |j                  }| j                  4 d{    | j                  j                  |j                        }||ur	 ddd      d{    y| j                  |j                  = ddd      d{    | j                  j                  | j                  g       }|D ]V  }|j                  |j                        }|!|dus&	 |j                  |j                  |j                   ||       d{    X | j'                  | j(                  |j                         y7 7 7 # 1 d{  7  sw Y   xY w7 I# t"        $ r t%        dd       Y w xY ww)zThis 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%   z7Conversation timeout was triggered for conversation %s!NFzWApplicationHandlerStop in TIMEOUT state of ConversationHandler has no effect. Ignoring.rx   ry   )r   jobr*   r   rG   r   r-   r,   r`   ra   r   rh   rd   r   r.   r   r+   r   r   r   rI   )	rC   r   r  ctxtr,   	found_jobr   r~   r   s	            r8   r   z$ConversationHandler._trigger_timeout  s    
 5'++&/:EtG\G\	
  00** 	9 	9))--d.C.CDI#		9 	9 	9
 !!$"7"78	9 	9 ;;??4<<4 	G((5E U%%7	!//T%5%5u>N  		 	488T%:%:;/	9 	9 	9 	9 	9 	9 . G#$s   A-F8/E>0F83+FF8)F*F8/FF8FAF8F8%+FFF*F8F8F8FFFF8FF52F84F55F8r@   )7r0   r1   r2   r3   r4   rI   r   intr5   rd   rf   r   r	   r   r   r!   rO   r   rP   r   r   floatdatetime	timedeltar   r   r   r   propertyrg   setterr
   rh   ri   rj   rl   rk   rm   rn   ro   rp   rq   r    r#   r   r   rM   rN   r   r   _CheckUpdateTyper   r   r   r   r6   r7   r8   r'   r'   z   s=   ObI& CsPGU3Z GU3Z? $!KO" 8<*P(P;vsF':;<P VT+fc6.A"BCCDP FC$789	P
 P P P P 'uUH4F4F-F'GHP smP P  VV^ 45P d|Pd
# 
0 "d;vsF/B#CD " " 
f 
 
 

 VT+fc66I*J%KKL   ]]_ _8 _ _ 4FC,? @A   b6 bh b b #t # # 
v 
( 
 

 $   __a& aX a a $   __a& aX a a !T ! ! dV d d d *	%x1112	3* *   
f 
 
 !

 hsm   
[[]f ] ] ]  D     cF cx c c #xVV^(<= # # 
v 
( 
 

2(2	c< 788	92hv / 6
<<
 F
 	

 
 *
 

2KK FK 	K
 K *K 
K0Y*6 Y*h7G7L.M Y*vbb Ab 's+	b
 b 
&	bJ Y]11&51@H@U1	1.%<c %<d %<r7   )Br3   rM   r  dataclassesr   typingr   r   r   r   r   r	   r
   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#   r   r$   r%   r&   rO   r
  r0   rG   r*   r:   r'   r6   r7   r8   <module>r     s   & 4   !     C . ? ( ) < ' : L V H L H : 9 L L77+fc6>Q2RTZZ[ 
X*?
@ 
'#, 
 
 ) ) )XS<+fc6&9: S<r7   