o
    4˜Žjy…  ã                   @  s  d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 d dl
mZm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 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*m+Z+ d dl,m-Z-m.Z. erŽd dl/m0Z0 G dd„ dƒZ1G dd„ dƒZ2G dd„ deƒZ3G dd„ dƒZ4edd�G d d!„ d!ƒƒZ5eG d"d#„ d#ƒƒZ6d;d)d*„Z7G d+d,„ d,ƒZ8G d-d.„ d.ƒZ9G d/d0„ d0ƒZ:G d1d2„ d2ƒZ;G d3d4„ d4ƒZ<eG d5d6„ d6ƒƒZ=G d7d8„ d8ƒZ>G d9d:„ d:ƒZ?e?ƒ Z@dS )<é    )ÚannotationsN)Údefaultdict)ÚMapping)Ú	dataclassÚreplace)ÚEnumÚauto)ÚTYPE_CHECKINGÚAnyÚClassVarÚoverload)ÚSelf)Úloggers)Ú
Dispatcher)ÚCallableObjectÚCallbackType)Úextract_flags_from_object)ÚRouter)ÚSceneException)ÚStateFilter)Ú
FSMContext)ÚState©ÚMemoryStorageRecord)ÚTelegramObjectÚUpdate)ÚClassAttrsResolverÚget_sorted_mro_attrs_resolver)ÚNextMiddlewareTypec                   @  sh   e Zd Zd#d$d	d
„Zd%dd„Zd&dd„Zd&dd„Zd'dd„Zd(dd„Zd(dd„Z	d%dd„Z
d)d d!„Zd"S )*ÚHistoryManagerÚscenes_historyé
   Ústater   ÚdestinyÚstrÚsizeÚintc                 C  s*   || _ || _t|jt|j|d�d�| _d S )N)r#   )ÚstorageÚkey)Ú_sizeÚ_stater   r'   r   r(   Ú_history_state)Úselfr"   r#   r%   © r-   úN/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/aiogram/fsm/scene.pyÚ__init__!   s   þzHistoryManager.__init__ú
str | NoneÚdataúdict[str, Any]ÚreturnÚNonec                 Ã  st   �| j  ¡ I d H }| dg ¡}| ||dœ¡ t|ƒ| jkr&|| j d … }tj d||¡ | j j	|d�I d H  d S )NÚhistory©r"   r1   z Push state=%s data=%s to history©r5   )
r+   Úget_dataÚ
setdefaultÚappendÚlenr)   r   ÚsceneÚdebugÚupdate_data)r,   r"   r1   Úhistory_datar5   r-   r-   r.   Úpush)   s   €zHistoryManager.pushúMemoryStorageRecord | Nonec                 Ã  s†   �| j  ¡ I d H }| dg ¡}|sd S | ¡ }|d }|d }|s+| j  i ¡I d H  n
| j j|d�I d H  tj d||¡ t	||d�S )Nr5   r"   r1   r7   z!Pop state=%s data=%s from historyr6   )
r+   r8   r9   ÚpopÚset_datar>   r   r<   r=   r   )r,   r?   r5   Úrecordr"   r1   r-   r-   r.   rB   3   s   €zHistoryManager.popc                 Ã  s8   �| j  ¡ I d H }| dg ¡}|sd S tdi |d ¤ŽS )Nr5   éÿÿÿÿr-   )r+   r8   r9   r   ©r,   r?   r5   r-   r-   r.   ÚgetB   s   €zHistoryManager.getúlist[MemoryStorageRecord]c                 Ã  s,   �| j  ¡ I d H }| dg ¡}dd„ |D ƒS )Nr5   c                 S  s   g | ]	}t d i |¤Ž‘qS )r-   r   )Ú.0Úitemr-   r-   r.   Ú
<listcomp>L   s    z&HistoryManager.all.<locals>.<listcomp>)r+   r8   r9   rF   r-   r-   r.   ÚallI   s   €zHistoryManager.allc                 Ã  s$   �t j d¡ | j i ¡I d H  d S )NzClear history)r   r<   r=   r+   rC   ©r,   r-   r-   r.   ÚclearN   s   €zHistoryManager.clearc                 Ã  s8   �| j  ¡ I d H }| j  ¡ I d H }|  ||¡I d H  d S ©N)r*   Ú	get_stater8   r@   ©r,   r"   r1   r-   r-   r.   ÚsnapshotR   s   €zHistoryManager.snapshotc                 Ã  s*   �| j  |¡I d H  | j  |¡I d H  d S rO   )r*   Ú	set_staterC   rQ   r-   r-   r.   Ú
_set_stateW   s   €zHistoryManager._set_statec                 Ã  sZ   �|   ¡ I d H }|s|  d i ¡I d H  d S tj d|j|j¡ |  |j|j¡I d H  |jS )NzRollback to state=%s data=%s)rB   rT   r   r<   r=   r"   r1   )r,   Úprevious_stater-   r-   r.   Úrollback[   s   €ýzHistoryManager.rollbackN)r    r!   )r"   r   r#   r$   r%   r&   )r"   r0   r1   r2   r3   r4   )r3   rA   )r3   rH   ©r3   r4   )r3   r0   )Ú__name__Ú
__module__Ú__qualname__r/   r@   rB   rG   rL   rN   rR   rT   rV   r-   r-   r-   r.   r       s    







r   c                   @  sb   e Zd Z		d!d"dd„Zd#dd„Zd$dd„Zd%dd„Zd&dd„Zd'dd„Zd&dd„Z	d&dd „Z
dS )(ÚObserverDecoratorNÚnamer$   Úfiltersútuple[CallbackType, ...]ÚactionúSceneAction | NoneÚafterúAfter | Noner3   r4   c                 C  ó   || _ || _|| _|| _d S rO   )r\   r]   r_   ra   )r,   r\   r]   r_   ra   r-   r-   r.   r/   k   ó   
zObserverDecorator.__init__Útargetútype[Scene] | CallbackTypec                 C  s:   t |dd ƒ}|sg }||_| t| j|| j| jd�¡ d S )NÚ__aiogram_handler__)r\   Úhandlerr]   ra   )Úgetattrrg   r:   ÚHandlerContainerr\   r]   ra   )r,   re   Úhandlersr-   r-   r.   Ú_wrap_filterw   s   üÿzObserverDecorator._wrap_filterr   c                 C  sL   | j d us	J dƒ‚t|dd ƒ}|d u rttƒ}||_t|ƒ|| j  | j< d S )NzScene action is not specifiedÚ__aiogram_action__)r_   ri   r   Údictrm   r   r\   )r,   re   r_   r-   r-   r.   Ú_wrap_action†   s   zObserverDecorator._wrap_actionc                 C  s<   t  |¡r| jd u r|  |¡ |S |  |¡ |S d}t|ƒ‚)Nz"Only function or method is allowed)ÚinspectÚ
isfunctionr_   rl   ro   Ú	TypeError)r,   re   Úmsgr-   r-   r.   Ú__call__�   s   



üþzObserverDecorator.__call__ÚActionContainerc                 C  ó   t | j| jtjƒS rO   )ru   r\   r]   ÚSceneActionÚleaverM   r-   r-   r.   rx   š   ó   zObserverDecorator.leaveútype[Scene]c                 C  s   t | j| jtj|ƒS rO   )ru   r\   r]   rw   Úenter)r,   re   r-   r-   r.   r{   �   s   zObserverDecorator.enterc                 C  rv   rO   )ru   r\   r]   rw   ÚexitrM   r-   r-   r.   r|       ry   zObserverDecorator.exitc                 C  rv   rO   )ru   r\   r]   rw   ÚbackrM   r-   r-   r.   r}   £   ry   zObserverDecorator.back)NN)
r\   r$   r]   r^   r_   r`   ra   rb   r3   r4   )re   rf   r3   r4   )re   r   r3   r4   )re   r   r3   r   )r3   ru   )re   rz   r3   ru   )rX   rY   rZ   r/   rl   ro   rt   rx   r{   r|   r}   r-   r-   r-   r.   r[   j   s    û


	


r[   c                   @  s$   e Zd Zeƒ Zeƒ Zeƒ Zeƒ ZdS )rw   N)rX   rY   rZ   r   r{   rx   r|   r}   r-   r-   r-   r.   rw   §   s
    
rw   c                   @  s$   e Zd Z	dddd„Zddd„ZdS )ru   Nr\   r$   r]   r^   r_   rw   re   ú type[Scene] | State | str | Noner3   r4   c                 C  rc   rO   )r\   r]   r_   re   )r,   r\   r]   r_   re   r-   r-   r.   r/   ¯   rd   zActionContainer.__init__ÚwizardÚSceneWizardc                 Ã  sŒ   �| j tjkr| jd ur| | j¡I d H  d S | j tjkr&| ¡ I d H  d S | j tjkr5| ¡ I d H  d S | j tjkrD| ¡ I d H  d S d S rO   )r_   rw   r{   re   Úgotorx   r|   r}   ©r,   r   r-   r-   r.   Úexecute»   s   €ÿzActionContainer.executerO   )
r\   r$   r]   r^   r_   rw   re   r~   r3   r4   ©r   r€   r3   r4   )rX   rY   rZ   r/   rƒ   r-   r-   r-   r.   ru   ®   s    ûru   T)Úslotsc                   @  s2   e Zd ZU ded< ded< ded< dZded	< dS )
rj   r$   r\   r   rh   r^   r]   Nrb   ra   )rX   rY   rZ   Ú__annotations__ra   r-   r-   r-   r.   rj   Æ   s
   
 rj   c                   @  sb   e Zd ZU ded< 	 ded< 	 ded< 	 dZded	< 	 dZded
< 	 dZded< 	 eZded< dS )ÚSceneConfigr0   r"   zlist[HandlerContainer]rk   z,dict[SceneAction, dict[str, CallableObject]]ÚactionsNzbool | NoneÚreset_data_on_enterÚreset_history_on_enterÚcallback_query_without_stater   Úattrs_resolver)	rX   rY   rZ   r†   r‰   rŠ   r‹   r   rŒ   r-   r-   r-   r.   r‡   Î   s   
 r‡   Úargsr
   Úkwargsr3   r4   c                  Ï  s   �d S rO   r-   )r�   rŽ   r-   r-   r.   Ú_empty_handlerç   s   €r�   c                   @  s8   e Zd Z	ddd
d„Zddd„Zddd„Zddd„ZdS )ÚSceneHandlerWrapperNr<   rz   rh   r   ra   rb   r3   r4   c                 C  s   || _ t|ƒ| _|| _d S rO   )r<   r   rh   ra   )r,   r<   rh   ra   r-   r-   r.   r/   ì   s   

zSceneHandlerWrapper.__init__Úeventr   rŽ   r
   c              
   Ë  sØ   �z
|d }|d }W n t y' } z|jd }d|›d�}t|ƒd ‚d }~ww |d }i |j¥|¥|_| jt| jj|||j||d�d�}	| jj	|	|fi |¤ŽI d H }
| j
rjtd	d
| j
j| j
jƒ}| |	j¡I d H  |
S )Nr"   Úscenesr   zScene context key z@ is not available. Ensure FSM is enabled and pipeline is intact.Úevent_update©Úscene_configÚmanagerr"   Úupdate_typer‘   r1   ©r   ra   r-   )ÚKeyErrorr�   r   r1   r<   r€   Ú__scene_config__Ú
event_typerh   Úcallra   ru   r_   rƒ   r   )r,   r‘   rŽ   r"   r’   ÚerrorÚmissing_keyrs   r“   r<   ÚresultÚaction_containerr-   r-   r.   rt   ö   sB   €

ÿ
€úúÿüzSceneHandlerWrapper.__call__r   c                 C  s   | S rO   r-   rM   r-   r-   r.   Ú	__await__  s   zSceneHandlerWrapper.__await__r$   c                 C  s8   d| j › d| jj› �}| jr|d| j› �7 }|d7 }|S )NzSceneHandlerWrapper(z, z, after=ú))r<   rh   Úcallbackra   )r,   rŸ   r-   r-   r.   Ú__str__!  s
   zSceneHandlerWrapper.__str__rO   )r<   rz   rh   r   ra   rb   r3   r4   )r‘   r   rŽ   r
   r3   r
   )r3   r   )r3   r$   )rX   rY   rZ   r/   rt   r¡   r¤   r-   r-   r-   r.   r�   ë   s    ü


(r�   c                      sd   e Zd ZU dZded< 	 ddd	„Zd‡ fdd„Zeddd„ƒZedddd„ƒZ	ed dd„ƒZ
‡  ZS )!ÚScenea¿  
    Represents a scene in a conversation flow.

    A scene is a specific state in a conversation where certain actions can take place.

    Each scene has a set of filters that determine when it should be triggered,
    and a set of handlers that define the actions to be executed when the scene is active.

    .. note::
        This class is not meant to be used directly. Instead, it should be subclassed
        to define custom scenes.
    zClassVar[SceneConfig]rš   r   r€   r3   r4   c                 C  s   || _ | | j _d S rO   )r   r<   r‚   r-   r-   r.   r/   :  s   zScene.__init__rŽ   r
   c              	     sf  |  dd ¡}|  dd ¡}|  dd ¡}|  dd ¡}|  dd ¡}tƒ jdi |¤Ž g }ttƒ}| jD ]-}	t|	tƒs8q0t|	dd ƒ}
|
sAq0|d u rH|
j	}|d u rO|
j
}|d u rV|
j}|d u r]|
j}q0|d u rdt}|| ƒD ]:\}}t|dd ƒ }ry| |¡ t|tƒrŒ| t|jt|j|jd�¡ t|d	ƒr¢|j ¡ D ]\}}||  |¡ q–qht||t|ƒ||||d
�| _d S )Nr"   r‰   rŠ   r‹   rŒ   rš   rg   ©ra   rm   )r"   rk   rˆ   r‰   rŠ   r‹   rŒ   r-   )rB   ÚsuperÚ__init_subclass__r   rn   Ú	__bases__Ú
issubclassr¥   ri   r‰   rŠ   r‹   rŒ   r   ÚextendÚ
isinstancer[   r:   rj   r\   r�   r]   ra   Úhasattrrm   ÚitemsÚupdater‡   rš   )ÚclsrŽ   Ú
state_namer‰   rŠ   r‹   rŒ   rk   rˆ   ÚbaseÚparent_scene_configÚ_nameÚvalueÚscene_handlersr_   Úaction_handlers©Ú	__class__r-   r.   r¨   A  sd   

€

üÿ
€ùzScene.__init_subclass__Úrouterr   c                 C  sŽ   | j }tƒ }|jD ]#}|j|j jt| |j|jd�g|j	¢R dt
|jƒiŽ | |j¡ q	|D ]}|jr9|dkr9q/|j|  t|jƒ¡ q/dS )z^
        Adds the scene to the given router.

        :param router:
        :return:
        r¦   ÚflagsÚcallback_queryN)rš   Úsetrk   Ú	observersr\   Úregisterr�   rh   ra   r]   r   Úaddr‹   Úfilterr   r"   )r°   rº   r•   Úused_observersrh   Úobserver_namer-   r-   r.   Úadd_to_router{  s(   
ýÿúù	ýzScene.add_to_routerNr\   r0   c                 C  s>   |du rd| j › d| j› d| jj›�}t|d�}|  |¡ |S )zM
        Returns the scene as a router.

        :return: new router
        NzScene 'Ú.z' for state ©r\   )rY   rZ   rš   r"   r   rÄ   )r°   r\   rº   r-   r-   r.   Ú	as_router—  s   ÿÿ

zScene.as_routerÚhandler_kwargsr   c                   s   d‡ ‡fd	d
„}|S )zÎ
        Create an entry point handler for the scene, can be used to simplify the handler
        that starts the scene.

        >>> router.message.register(MyScene.as_handler(), Command("start"))
        r‘   r   r’   ÚScenesManagerÚmiddleware_kwargsr
   r3   r4   c                 ›  s&   �|j ˆ fi i ˆ¥|¥¤ŽI d H  d S rO   )r{   )r‘   r’   rÊ   ©r°   rÈ   r-   r.   Úenter_to_scene_handler°  s   €$z0Scene.as_handler.<locals>.enter_to_scene_handlerN)r‘   r   r’   rÉ   rÊ   r
   r3   r4   r-   )r°   rÈ   rÌ   r-   rË   r.   Ú
as_handler§  s   	zScene.as_handlerr„   ©rŽ   r
   r3   r4   ©rº   r   r3   r4   rO   )r\   r0   r3   r   )rÈ   r
   r3   r   )rX   rY   rZ   Ú__doc__r†   r/   r¨   ÚclassmethodrÄ   rÇ   rÍ   Ú__classcell__r-   r-   r¸   r.   r¥   )  s   
 
:r¥   c                   @  s¶   e Zd ZdZd;dd„Zd<dd„Zd=d>dd„Zd<dd„Zd<dd„Zd<dd „Z	d?d#d$„Z
d@d'd(„ZdAd*d+„ZdBd,d-„ZedCd0d1„ƒZedDd3d1„ƒZdEdFd5d1„Z	4dEdGd7d8„ZdHd9d:„Zd4S )Ir€   as  
    A class that represents a wizard for managing scenes in a Telegram bot.

    Instance of this class is passed to each scene as a parameter.
    So, you can use it to transition between scenes, get and set data, etc.

    .. note::

        This class is not meant to be used directly. Instead, it should be used
        as a parameter in the scene constructor.

    r•   r‡   r–   rÉ   r"   r   r—   r$   r‘   r   r1   r2   c                 C  s.   || _ || _|| _|| _|| _|| _d| _dS )a¿  
        A class that represents a wizard for managing scenes in a Telegram bot.

        :param scene_config: The configuration of the scene.
        :param manager: The scene manager.
        :param state: The FSMContext object for storing the state of the scene.
        :param update_type: The type of the update event.
        :param event: The TelegramObject represents the event.
        :param data: Additional data for the scene.
        N)r•   r–   r"   r—   r‘   r1   r<   )r,   r•   r–   r"   r—   r‘   r1   r-   r-   r.   r/   È  s   
zSceneWizard.__init__rŽ   r
   r3   r4   c                 Ë  s|   �t j d| jj¡ | jjr| j i ¡I dH  | jjr$| jj	 
¡ I dH  | j | jj¡I dH  | jtjfi |¤ŽI dH  dS )a  
        Enter method is used to transition into a scene in the SceneWizard class.
        It sets the state, clears data and history if specified,
        and triggers entering event of the scene.

        :param kwargs: Additional keyword arguments.
        :return: None
        zEntering scene %rN)r   r<   r=   r•   r"   r‰   rC   rŠ   r–   r5   rN   rS   Ú
_on_actionrw   r{   ©r,   rŽ   r-   r-   r.   r{   ä  s   €	zSceneWizard.enterTÚ_with_historyÚboolc                 Ë  sH   �t j d| jj¡ |r| jj ¡ I dH  | jt	j
fi |¤ŽI dH  dS )a"  
        Leaves the current scene.
        This method is used to exit a scene and transition to the next scene.

        :param _with_history: Whether to include history in the snapshot. Defaults to True.
        :param kwargs: Additional keyword arguments.
        :return: None

        zLeaving scene %rN)r   r<   r=   r•   r"   r–   r5   rR   rÓ   rw   rx   )r,   rÕ   rŽ   r-   r-   r.   rx   õ  s
   €
zSceneWizard.leavec                 Ë  s`   �t j d| jj¡ | jj ¡ I dH  | jt	j
fi |¤ŽI dH  | jjdddi|¤ŽI dH  dS )z—
        Exit the current scene and enter the default scene/state.

        :param kwargs: Additional keyword arguments.
        :return: None
        zExiting scene %rNÚ_check_activeFrO   )r   r<   r=   r•   r"   r–   r5   rN   rÓ   rw   r|   r{   rÔ   r-   r-   r.   r|     s
   € zSceneWizard.exitc                 Ë  sb   �t j d| jj¡ | jdddi|¤ŽI dH  | jj ¡ I dH }| jj	|fddi|¤ŽI dH  dS )z©
        This method is used to go back to the previous scene.

        :param kwargs: Keyword arguments that can be passed to the method.
        :return: None
        z$Back to previous scene from scene %srÕ   FNr×   r-   )
r   r<   r=   r•   r"   rx   r–   r5   rV   r{   )r,   rŽ   Ú	new_scener-   r-   r.   r}     s
   €"zSceneWizard.backc                 Ë  s6   �| j jdusJ dƒ‚| j| j jfi |¤ŽI dH  dS )z¤
        This method allows to re-enter the current scene.

        :param kwargs: Additional keyword arguments to pass to the scene.
        :return: None
        NzScene state is not specified)r•   r"   r�   rÔ   r-   r-   r.   Úretake  s   € zSceneWizard.retaker<   útype[Scene] | State | strc                 Ë  s:   �| j di |¤ŽI dH  | jj|fddi|¤ŽI dH  dS )a  
        The `goto` method transitions to a new scene.
        It first calls the `leave` method to perform any necessary cleanup
        in the current scene, then calls the `enter` event to enter the specified scene.

        :param scene: The scene to transition to. Can be either a `Scene` instance
            `State` instance or a string representing the scene.
        :param kwargs: Additional keyword arguments to pass to the `enter`
            method of the scene manager.
        :return: None
        Nr×   Fr-   )rx   r–   r{   )r,   r<   rŽ   r-   r-   r.   r�   &  s   €"zSceneWizard.gotor_   rw   c                 Ë  s²   �| j s
d}t|ƒ‚tj  d|j| jj¡ | jj |i ¡}|s,tj  d|j| jj¡ dS | j	}||vrAtj  d|j|| jj¡ dS || j
| j | jfi i | j¥|¥¤ŽI d H  dS )NzScene is not initializedzCall action %r in scene %rzAction %r not found in scene %rFz,Action %r for event %r not found in scene %rT)r<   r   r   r=   r\   r•   r"   rˆ   rG   r—   rœ   r‘   r1   )r,   r_   rŽ   rs   Úaction_configr›   r-   r-   r.   rÓ   5  s0   €ýü,zSceneWizard._on_actionúMapping[str, Any]c                 Ã  s   �| j j|d�I dH  dS )z©
        Sets custom data in the current state.

        :param data: A mapping containing the custom data to be set in the current state.
        :return: None
        ©r1   N)r"   rC   )r,   r1   r-   r-   r.   rC   Q  s   €zSceneWizard.set_datac                 Ã  s   �| j  ¡ I dH S )z™
        This method returns the data stored in the current state.

        :return: A dictionary containing the data stored in the scene state.
        N)r"   r8   rM   r-   r-   r.   r8   Z  s   €zSceneWizard.get_datar(   ú
Any | Nonec                 Ã  ó   �dS )zø
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.

        :return: A dictionary containing the data stored in the scene state.
        Nr-   )r,   r(   r-   r-   r.   Ú	get_valueb  ó    zSceneWizard.get_valueÚdefaultc                 Ã  rß   )aC  
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.
        :param default: Default value to return, if ``key`` was not found.

        :return: A dictionary containing the data stored in the scene state.
        Nr-   ©r,   r(   râ   r-   r-   r.   rà   l  rá   Nc                 Ã  s   �| j  ||¡I d H S rO   )r"   rà   rã   r-   r-   r.   rà   w  s   €úMapping[str, Any] | Nonec                 Ë  s$   �|r|  |¡ | jj|d�I dH S )zõ
        This method updates the data stored in the current state

        :param data: Optional mapping of data to update.
        :param kwargs: Additional key-value pairs of data to update.
        :return: Dictionary of updated data
        rÝ   N)r¯   r"   r>   )r,   r1   rŽ   r-   r-   r.   r>   z  s   €
zSceneWizard.update_datac                 Ã  s   �|   i ¡I dH  dS )z9
        Clears the data.

        :return: None
        N)rC   rM   r-   r-   r.   Ú
clear_dataŠ  s   €zSceneWizard.clear_data)r•   r‡   r–   rÉ   r"   r   r—   r$   r‘   r   r1   r2   rÎ   ©T)rÕ   rÖ   rŽ   r
   r3   r4   )r<   rÚ   rŽ   r
   r3   r4   )r_   rw   rŽ   r
   r3   rÖ   )r1   rÜ   r3   r4   )r3   r2   )r(   r$   r3   rÞ   )r(   r$   râ   r
   r3   r
   rO   )r(   r$   râ   rÞ   r3   rÞ   )r1   rä   rŽ   r
   r3   r2   rW   )rX   rY   rZ   rÐ   r/   r{   rx   r|   r}   rÙ   r�   rÓ   rC   r8   r   rà   r>   rå   r-   r-   r-   r.   r€   º  s(    









		
þr€   c                   @  sF   e Zd ZdZd"dd„Zd#dd„Zd$dd„Z	d%d&dd„Zd'dd „Zd!S )(rÉ   z¸
    The ScenesManager class is responsible for managing scenes in an application.
    It provides methods for entering and exiting scenes, as well as retrieving the active scene.
    ÚregistryÚSceneRegistryr—   r$   r‘   r   r"   r   r1   r2   r3   r4   c                 C  s.   || _ || _|| _|| _|| _t| jƒ| _d S rO   )rç   r—   r‘   r"   r1   r   r5   )r,   rç   r—   r‘   r"   r1   r-   r-   r.   r/   ™  s   zScenesManager.__init__Ú
scene_typer~   r¥   c              	   Ã  s2   �| j  |¡}|t|j| | j| j| j| jd�d�S )Nr”   r˜   )rç   rG   r€   rš   r"   r—   r‘   r1   )r,   ré   r-   r-   r.   Ú
_get_scene©  s   €úÿzScenesManager._get_sceneúScene | Nonec                 Ã  s:   �| j  ¡ I d H }z	|  |¡I d H W S  ty   Y d S w rO   )r"   rP   rê   r   )r,   r"   r-   r-   r.   Ú_get_active_scene¶  s   €ÿzScenesManager._get_active_sceneTr×   rÖ   rŽ   r
   c                 Ë  sª   �|ri | j ¥|¥| _ |r$|  ¡ I dH }|dur$|jjdi |¤ŽI dH  z
|  |¡I dH }W n tyF   |dur:‚ | j d¡I dH  Y dS w |jjdi |¤ŽI dH  dS )a³  
        Enters the specified scene.

        :param scene_type: Optional Type[Scene], State or str representing the scene type to enter.
        :param _check_active: Optional bool indicating whether to check if
            there is an active scene to exit before entering the new scene. Defaults to True.
        :param kwargs: Additional keyword arguments to pass to the scene's wizard.enter() method.
        :return: None
        Nr-   )	r1   rì   r   r|   rê   r   r"   rS   r{   )r,   ré   r×   rŽ   Úactive_scener<   r-   r-   r.   r{   ½  s   €ýzScenesManager.enterc                 Ë  s4   �|   ¡ I dH }|sdS |jjdi |¤ŽI dH  dS )zÍ
        Close method is used to exit the currently active scene in the ScenesManager.

        :param kwargs: Additional keyword arguments passed to the scene's exit method.
        :return: None
        Nr-   )rì   r   r|   )r,   rŽ   r<   r-   r-   r.   ÚcloseÝ  s
   €zScenesManager.closeN)rç   rè   r—   r$   r‘   r   r"   r   r1   r2   r3   r4   )ré   r~   r3   r¥   )r3   rë   ræ   )ré   r~   r×   rÖ   rŽ   r
   r3   r4   rÎ   )	rX   rY   rZ   rÐ   r/   rê   rì   r{   rî   r-   r-   r-   r.   rÉ   “  s    



ý rÉ   c                   @  s^   e Zd ZdZd%d&d	d
„Zd'dd„Zd(dd„Zd(dd„Zddœd)dd„Zd*dd „Z	d+d#d$„Z
dS ),rè   zJ
    A class that represents a registry for scenes in a Telegram bot.
    Trº   r   Úregister_on_addrÖ   r3   r4   c                 C  s    || _ || _i | _|  |¡ dS )zò
        Initialize a new instance of the SceneRegistry class.

        :param router: The router instance used for scene registration.
        :param register_on_add: Whether to register the scenes to the router when they are added.
        N)rº   rï   Ú_scenesÚ_setup_middleware)r,   rº   rï   r-   r-   r.   r/   ï  s   zSceneRegistry.__init__c                 C  sH   t |tƒr|j | j¡ d S |j ¡ D ]}|jdv rq| | j¡ qd S )N>   r�   r¯   )	r¬   r   r¯   Úouter_middlewareÚ_update_middlewarer¾   ÚvaluesÚ
event_nameÚ_middleware)r,   rº   Úobserverr-   r-   r.   rñ   ü  s   

ýzSceneRegistry._setup_middlewarerh   ú"NextMiddlewareType[TelegramObject]r‘   r   r1   r2   r
   c                 Ã  s`   �t |tƒs
J dƒ‚| d¡}|d u r|||ƒI d H S t| |j|j||d�|d< |||ƒI d H S )Nz Event must be an Update instancer"   ©rç   r—   r‘   r"   r1   r’   )r¬   r   rG   rÉ   r›   r‘   )r,   rh   r‘   r1   r"   r-   r-   r.   ró     s   €

ûz SceneRegistry._update_middlewarec                 Ã  sT   �|  d¡}|d u r|||ƒI d H S |d }t| |j|||d�|d< |||ƒI d H S )Nr"   r“   rù   r’   )rG   rÉ   r›   )r,   rh   r‘   r1   r"   r¯   r-   r-   r.   rö     s   €

ûzSceneRegistry._middlewareN)rº   r’   rz   úRouter | Nonec                G  s|   |sd}t |ƒ‚|D ]1}|jj| jv rd|jj›d�}t|ƒ‚|| j|jj< |r0| | ¡ ¡ q
| jr;| j | ¡ ¡ q
dS )aÜ  
        This method adds the specified scenes to the registry
        and optionally registers it to the router.

        If a scene with the same state already exists in the registry, a SceneException is raised.

        .. warning::

            If the router is not specified, the scenes will not be registered to the router.
            You will need to include the scenes manually to the router or use the register method.

        :param scenes: A variable length parameter that accepts one or more types of scenes.
            These scenes are instances of the Scene class.
        :param router: An optional parameter that specifies the router
            to which the scenes should be added.
        :return: None
        z$At least one scene must be specifiedzScene with state z already existsN)	Ú
ValueErrorrš   r"   rð   r   Úinclude_routerrÇ   rï   rº   )r,   rº   r’   rs   r<   r-   r-   r.   rÀ   0  s   €özSceneRegistry.addc                 G  s   | j |d| jiŽ dS )z™
        Registers one or more scenes to the SceneRegistry.

        :param scenes: One or more scene classes to register.
        :return: None
        rº   N)rÀ   rº   )r,   r’   r-   r-   r.   r¿   R  s   zSceneRegistry.registerr<   r~   c                 C  s|   t  |¡rt|tƒr|jj}t|tƒr|j}|dur%t|tƒs%d}t	|ƒ‚z| j
| W S  ty=   d|›d�}t	|ƒd‚w )ae  
        This method returns the registered Scene object for the specified scene.
        The scene parameter can be either a Scene object, State object or a string representing
        the name of the scene. If a Scene object is provided, the state attribute
        of the SceneConfig object associated with the Scene object will be used as the scene name.
        If a State object is provided, the state attribute of the State object will be used as the
        scene name. If None or an invalid type is provided, a SceneException will be raised.

        If the specified scene is not registered in the SceneRegistry object,
        a SceneException will be raised.

        :param scene: A Scene object, State object or a string representing the name of the scene.
        :return: The registered Scene object corresponding to the given scene parameter.

        Nz4Scene must be a subclass of Scene, State or a stringzScene z is not registered)rp   Úisclassrª   r¥   rš   r"   r¬   r   r$   r   rð   r™   )r,   r<   rs   r-   r-   r.   rG   [  s   

þzSceneRegistry.getræ   )rº   r   rï   rÖ   r3   r4   rÏ   )rh   rø   r‘   r   r1   r2   r3   r
   )r’   rz   rº   rú   r3   r4   )r’   rz   r3   r4   )r<   r~   r3   rz   )rX   rY   rZ   rÐ   r/   rñ   ró   rö   rÀ   r¿   rG   r-   r-   r-   r.   rè   ê  s    



"	rè   c                   @  sL   e Zd ZU ded< dZded< eddd„ƒZedd	d
„ƒZeddd„ƒZdS )ÚAfterrw   r_   Nr~   r<   r3   c                 C  ó   | t jd�S ©N©r_   )rw   r|   ©r°   r-   r-   r.   r|     ó   z
After.exitc                 C  rÿ   r   )rw   r}   r  r-   r-   r.   r}   ƒ  r  z
After.backc                 C  s   | t j|d�S )N)r_   r<   )rw   r{   )r°   r<   r-   r-   r.   r�   ‡  s   z
After.goto)r3   rþ   )r<   r~   r3   rþ   )	rX   rY   rZ   r†   r<   rÑ   r|   r}   r�   r-   r-   r-   r.   rþ   z  s   
 rþ   c                   @  sN   e Zd Zddd„Zddœddd„Zddd„Zddd„Zddd„Zddd„ZdS )ÚObserverMarkerr\   r$   r3   r4   c                 C  s
   || _ d S rO   rÆ   )r,   r\   r-   r-   r.   r/   �  s   
zObserverMarker.__init__Nr¦   r]   r   ra   rb   r[   c                G  s   t | j||d�S )Nr¦   )r[   r\   )r,   ra   r]   r-   r-   r.   rt   �  s
   ýzObserverMarker.__call__c                 G  s   t | j|tjd�S r   )r[   r\   rw   r{   )r,   r]   r-   r-   r.   r{   ›  ry   zObserverMarker.enterc                 C  ó   t | jdtjd�S ©Nr-   r  )r[   r\   rw   rx   rM   r-   r-   r.   rx   ž  ry   zObserverMarker.leavec                 C  r  r  )r[   r\   rw   r|   rM   r-   r-   r.   r|   ¡  ry   zObserverMarker.exitc                 C  r  r  )r[   r\   rw   r}   rM   r-   r-   r.   r}   ¤  ry   zObserverMarker.back)r\   r$   r3   r4   )r]   r   ra   rb   r3   r[   )r]   r   r3   r[   )r3   r[   )	rX   rY   rZ   r/   rt   r{   rx   r|   r}   r-   r-   r-   r.   r  Œ  s    
ý


r  c                   @  s€   e Zd ZdZedƒZedƒZedƒZedƒZedƒZ	edƒZ
edƒZed	ƒZed
ƒZedƒZedƒZedƒZedƒZedƒZdS )ÚOnMarkera}  
    The `OnMarker` class is used as a marker class to define different
    types of events in the Scenes.

    Attributes:

    - :code:`message`: Event marker for handling `Message` events.
    - :code:`edited_message`: Event marker for handling edited `Message` events.
    - :code:`channel_post`: Event marker for handling channel `Post` events.
    - :code:`edited_channel_post`: Event marker for handling edited channel `Post` events.
    - :code:`inline_query`: Event marker for handling `InlineQuery` events.
    - :code:`chosen_inline_result`: Event marker for handling chosen `InlineResult` events.
    - :code:`callback_query`: Event marker for handling `CallbackQuery` events.
    - :code:`shipping_query`: Event marker for handling `ShippingQuery` events.
    - :code:`pre_checkout_query`: Event marker for handling `PreCheckoutQuery` events.
    - :code:`poll`: Event marker for handling `Poll` events.
    - :code:`poll_answer`: Event marker for handling `PollAnswer` events.
    - :code:`my_chat_member`: Event marker for handling my chat `Member` events.
    - :code:`chat_member`: Event marker for handling chat `Member` events.
    - :code:`chat_join_request`: Event marker for handling chat `JoinRequest` events.
    - :code:`error`: Event marker for handling `Error` events.

    .. note::

        This is a marker class and does not contain any methods or implementation logic.
    ÚmessageÚedited_messageÚchannel_postÚedited_channel_postÚinline_queryÚchosen_inline_resultr¼   Úshipping_queryÚpre_checkout_queryÚpollÚpoll_answerÚmy_chat_memberÚchat_memberÚchat_join_requestN)rX   rY   rZ   rÐ   r  r  r	  r
  r  r  r  r¼   r  r  r  r  r  r  r  r-   r-   r-   r.   r  ¨  s     r  )r�   r
   rŽ   r
   r3   r4   )AÚ
__future__r   rp   Úcollectionsr   Úcollections.abcr   Údataclassesr   r   Úenumr   r   Útypingr	   r
   r   r   Útyping_extensionsr   Úaiogramr   Úaiogram.dispatcher.dispatcherr   Ú aiogram.dispatcher.event.handlerr   r   Úaiogram.dispatcher.flagsr   Úaiogram.dispatcher.routerr   Úaiogram.exceptionsr   Úaiogram.filtersr   Úaiogram.fsm.contextr   Úaiogram.fsm.stater   Úaiogram.fsm.storage.memoryr   Úaiogram.typesr   r   Ú"aiogram.utils.class_attrs_resolverr   r   Úaiogram.dispatcher.event.basesr   r   r[   rw   ru   rj   r‡   r�   r�   r¥   r€   rÉ   rè   rþ   r  r  Úonr-   r-   r-   r.   Ú<module>   sX    J=
>  ZW 
,