
    h                    r    d dl mZ d dlmZ d dlmZ d dlZd dlmZm	Z	m
Z
mZ ddlmZ  G d d	e          ZdS )
    )annotations)iscoroutinefunction)CallableN)
IdentifierListenerListenerTypesMessage   )Handlerc                  N     e Zd ZdZdd fdZedd            ZddZddZ xZ	S )MessageHandlera  The Message handler class. Used to handle new messages.
    It is intended to be used with :meth:`~hydrogram.Client.add_handler`

    For a nicer way to register this handler, have a look at the
    :meth:`~hydrogram.Client.on_message` decorator.

    Parameters:
        callback (``Callable``):
            Pass a function that will be called when a new Message arrives. It takes *(client, message)*
            as positional arguments (look at the section below for a detailed description).

        filters (:obj:`Filters`):
            Pass one or more filters to allow only a subset of messages to be passed
            in your callback function.

    Other parameters:
        client (:obj:`~hydrogram.Client`):
            The Client itself, useful when you want to call other API methods inside the message handler.

        message (:obj:`~hydrogram.types.Message`):
            The received message.
    Ncallbackr   c                d    || _         t                                          | j        |           d S N)original_callbacksuper__init__resolve_future_or_callback)selfr   filters	__class__s      b/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/hydrogram/handlers/message_handler.pyr   zMessageHandler.__init__7   s.    !)8'BBBBB    clienthydrogram.Clientmessager	   returntuple[bool, Listener | None]c           	       K   |j         }|r|j        nd}|r|j        nd}t          |dt          |dd                    }t	          ||j        j        |j        j        g||g          }|                     |t          j                  }d}|rc|j	        }	t          |	          rKt          |	j                  r |	| |           d{V }n&| j                            d|	| |           d{V }nd}||fS )a  
        Checks if the message has a matching listener.

        Parameters:
            client (:obj:`~hydrogram.Client`):
                The Client object to check with.

            message (:obj:`~hydrogram.types.Message`):
                The Message object to check with.

        Returns:
            ``tuple``: A tuple of two elements, the first one is whether the message has a matching listener or not,
            the second one is the matching listener if exists.
        Nid
message_id)r!   chat_idfrom_user_idFT)	from_userr    usernamegetattrr   chatget_listener_matching_with_datar   MESSAGEr   callabler   __call__looprun_in_executor)
r   r   r$   r#   from_user_usernamer!   datalistenerlistener_does_matchr   s
             r   check_if_has_matching_listenerz-MessageHandler.check_if_has_matching_listener;   sP     $ %	'0:y||d3<FY//$WdGG\4,P,PQQ
!\_gl&;<&(:;
 
 
 99$@UVV# 
	+&G   +&w'788 070H0H*H*H*H*H*H*H''060K0Kgvw1 1 + + + + + +'' '+#"H,,r   boolc                <  K   |                      ||           d{V d         }t          | j                  r_t          | j        j                  r|                     ||           d{V }n+|j                            d| j        ||           d{V }nd}|p|S )a  
        Checks if the message has a matching listener or handler and its filters does match with the Message.

        Parameters:
            client (:obj:`~hydrogram.Client`):
                The Client object to check with.

            message (:obj:`~hydrogram.types.Message`):
                The Message object to check with.

        Returns:
            ``bool``: Whether the message has a matching listener or handler and its filters does match with the Message.
        Nr   T)r2   r*   r   r   r+   r,   r-   )r   r   r   r1   handler_does_matchs        r   checkzMessageHandler.checkk   s       &*%H%HQX%Y%YYYYYYY[\]DL!! 	&"4<#899 +/<<+H+H%H%H%H%H%H%H""+1;+F+F$,, , & & & & & &"" "& #8&88r   c                  K   |                      ||           d{V \  }}|r|r|                    |           |j        r?|j                                        s&|j                            |           t
          j        |j        rEt          |j                  r |j        ||g|R   d{V  n |j        ||g|R   t
          j        t          d           | j
        ||g|R   d{V  dS )a  
        Resolves the future or calls the callback of the listener if the message has a matching listener.

        Parameters:
            client (:obj:`~hydrogram.Client`):
                The Client object to resolve or call with.

            message (:obj:`~hydrogram.types.Message`):
                The Message object to resolve or call with.

            args (``tuple``):
                Arguments to call the callback with.
        Nz0Listener must have either a future or a callback)r2   remove_listenerfuturedone
set_result	hydrogramStopPropagationr   r   
ValueErrorr   )r   r   r   argsr1   r0   s         r   r   z)MessageHandler.resolve_future_or_callback   sU      /3.Q.QRXZa.b.b(b(b(b(b(b(b%X 	Q+ 	Q""8,,, 0x';';'='= 0**7333//  0&x'899 >+(+FGCdCCCCCCCCCCC%H%fg=====//OPPP$d$VW<t<<<<<<<<<<<<r   r   )r   r   )r   r   r   r	   r   r   )r   r   r   r	   r   r3   )r   r   r   r	   )
__name__
__module____qualname____doc__r   staticmethodr2   r6   r   __classcell__)r   s   @r   r   r      s         .C C C C C C C -- -- -- \--^9 9 9 9<!= != != != != != != !=r   r   )
__future__r   inspectr   typingr   r<   hydrogram.typesr   r   r   r	   handlerr   r    r   r   <module>rL      s   ( # " " " " " ' ' ' ' ' '           H H H H H H H H H H H H      K= K= K= K= K=W K= K= K= K= K=r   