
    ;Si#                     \    d dl Z ddlmZmZmZmZ ddlmZ ddlm	Z	 e G d de             Z
y)	    N   )EventBuilderEventCommonname_inner_event_into_id_set   )utils)typesc            	       r     e Zd ZdZddddddddd fdZ fdZedd       Z fdZ G d	 d
e	      Z
 xZS )
NewMessagea  
    Occurs whenever a new text message or a message with media arrives.

    Args:
        incoming (`bool`, optional):
            If set to `True`, only **incoming** messages will be handled.
            Mutually exclusive with ``outgoing`` (can only set one of either).

        outgoing (`bool`, optional):
            If set to `True`, only **outgoing** messages will be handled.
            Mutually exclusive with ``incoming`` (can only set one of either).

        from_users (`entity`, optional):
            Unlike `chats`, this parameter filters the *senders* of the
            message. That is, only messages *sent by these users* will be
            handled. Use `chats` if you want private messages with this/these
            users. `from_users` lets you filter by messages sent by *one or
            more* users across the desired chats (doesn't need a list).

        forwards (`bool`, optional):
            Whether forwarded messages should be handled or not. By default,
            both forwarded and normal messages are included. If it's `True`
            *only* forwards will be handled. If it's `False` only messages
            that are *not* forwards will be handled.

        pattern (`str`, `callable`, `Pattern`, optional):
            If set, only messages matching this pattern will be handled.
            You can specify a regex-like string which will be matched
            against the message, a callable function that returns `True`
            if a message is acceptable, or a compiled regex pattern.

    Example
        .. code-block:: python

            import asyncio
            from telethon import events

            @client.on(events.NewMessage(pattern='(?i)hello.+'))
            async def handler(event):
                # Respond whenever someone says "Hello" and something else
                await event.reply('Hey!')

            @client.on(events.NewMessage(outgoing=True, pattern='!ping'))
            async def handler(event):
                # Say "!pong" whenever you send "!ping", then delete both messages
                m = await event.respond('!pong')
                await asyncio.sleep(5)
                await client.delete_messages(event.chat_id, [event.id, m.id])
    NF)blacklist_chatsfuncincomingoutgoing
from_usersforwardspatternc                   |r|rd x}}n/||| }n'||| }nt        d ||fD              rt        d      t        	|   |||       || _        || _        || _        || _        t        |t              r%t        j                  |      j                  | _        nS|rt        |      r|| _        n>t        |d      r't        |j                        r|j                  | _        nt!        d      t        d | j"                  | j                  | j
                  | j                  | j                  | j                  | j                  | j$                  fD              | _        y )Nc              3   .   K   | ]  }|d uxr |   y wN .0xs     _/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/events/newmessage.py	<genexpr>z&NewMessage.__init__.<locals>.<genexpr>D   s     GQ$(q5(Gs   zNDon't create an event handler if you don't want neither incoming nor outgoing!)r   r   matchzInvalid pattern type givenc              3   $   K   | ]  }|d u  
 y wr   r   r   s     r   r   z&NewMessage.__init__.<locals>.<genexpr>W   s      1Q$Y s   )all
ValueErrorsuper__init__r   r   r   r   
isinstancestrrecompiler   r   callablehasattr	TypeErrorchatsr   	_no_check)
selfr*   r   r   r   r   r   r   r   	__class__s
            r   r"   zNewMessage.__init__;   s>    "&&Hx!h&6#|H!h&6#|HG8X2FGG I J J 	dK  $ gs#::g.44DLHW-"DLWg&8GMM+B"==DL899  JJt}}dllOOT]]DOOTYY1
      c                    K   t         |   |       d {    t        || j                         d {   | _        y 7 (7 wr   )r!   _resolver   r   )r,   clientr-   s     r   r0   zNewMessage._resolve\   s8     gv&&& ,VT__ EE 	'Es   A?AAAAc                    t        |t        j                  t        j                  f      rBt        |j                  t        j
                        sy | j                  |j                        }|S t        |t        j                        r| j                  t        j
                  |j                  |j                  |j                  |j                  |j                  t        j                  |j                        t        j                  |j                  r|n|j                        |j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                              }|S t        |t        j*                        r| j                  t        j
                  |j                  |j                  |j                  |j                  |j                  t        j                  |j                  r|n|j,                        t        j.                  |j0                        |j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                              }|S y )N)out	mentionedmedia_unreadsilentidpeer_idfrom_idmessagedatefwd_from
via_bot_idreply_toentities
ttl_period)r3   r4   r5   r6   r7   r9   r8   r:   r;   r<   r=   r>   r?   r@   )r#   r
   UpdateNewMessageUpdateNewChannelMessager:   MessageEventUpdateShortMessager3   r4   r5   r6   r7   PeerUseruser_idr;   r<   r=   r>   r?   r@   UpdateShortChatMessager9   PeerChatchat_id)clsupdateothersself_idevents        r   buildzNewMessage.build`   s   f--u/L/LMOfnnemm<IIfnn-EL K  8 89IIemmJJ **#00}}99v~~6&**w&..Q[[!,,!,, EH )  < <=IIemmJJ **#00}}99&**w&..Qv~~6[[!,,!,, E&  r.   c                 *   | j                   r|S | j                  r|j                  j                  ry | j                  r|j                  j                  sy | j
                  6t        | j
                        t        |j                  j                        k7  ry | j                  #|j                  j                  | j                  vry | j                  r3| j                  |j                  j                  xs d      }|sy ||_        t        | 5  |      S )N )r+   r   r:   r3   r   r   boolr<   r   	sender_idr   pattern_matchr!   filter)r,   rO   r   r-   s      r   rV   zNewMessage.filter   s    >>L==U]]..==!2!2==$DMM"d5==+A+A&BB??&}}&&doo=<<LL!6!6!<"=E"'Ew~e$$r.   c                   8     e Zd ZdZ fdZ fdZd Zd Z xZS )NewMessage.Eventa  
        Represents the event of a new message. This event can be treated
        to all effects as a `Message <telethon.tl.custom.message.Message>`,
        so please **refer to its documentation** to know what you can do
        with this event.

        Members:
            message (`Message <telethon.tl.custom.message.Message>`):
                This is the only difference with the received
                `Message <telethon.tl.custom.message.Message>`, and will
                return the `telethon.tl.custom.message.Message` itself,
                not the text.

                See `Message <telethon.tl.custom.message.Message>` for
                the rest of available members and methods.

            pattern_match (`obj`):
                The resulting object from calling the passed ``pattern`` function.
                Here's an example using a string (defaults to regex match):

                >>> from telethon import TelegramClient, events
                >>> client = TelegramClient(...)
                >>>
                >>> @client.on(events.NewMessage(pattern=r'hi (\w+)!'))
                ... async def handler(event):
                ...     # In this case, the result is a ``Match`` object
                ...     # since the `str` pattern was converted into
                ...     # the ``re.compile(pattern).match`` function.
                ...     print('Welcomed', event.pattern_match.group(1))
                ...
                >>>
        c                     d| j                   d<   t        | 	  |j                  |j                  t        |j                               d | _        || _        y )NF_init)	chat_peermsg_id	broadcast)	__dict__r!   r"   r8   r7   rS   postrU   r:   )r,   r:   r-   s     r   r"   zNewMessage.Event.__init__   sM    %*DMM'"Gw$+JJ$w||:L  N "&D"DLr.   c                     t         |   |       | j                  }|j                  || j                  d        d| j
                  d<   y )NTrZ   )r!   _set_clientr:   _finish_init	_entitiesr^   )r,   r1   mr-   s      r   ra   zNewMessage.Event._set_client   s;    G'ANN64>>48%)DMM'"r.   c                 h    || j                   v r| j                   |   S t        | j                  |      S r   )r^   getattrr:   )r,   items     r   __getattr__zNewMessage.Event.__getattr__   s.    t}}$}}T**t||T22r.   c                     | j                   d   r|| j                   v r|| j                   |<   y t        | j                  ||       y )NrZ   )r^   setattrr:   )r,   namevalues      r   __setattr__zNewMessage.Event.__setattr__   s7    ==)TT]]-B&+d#dE2r.   )	__name__
__module____qualname____doc__r"   ra   rh   rm   __classcell__r-   s   @r   rD   rX      s    	@	#	*	3	3r.   rD   r   )NN)rn   ro   rp   rq   r"   r0   classmethodrP   rV   r   rD   rr   rs   s   @r   r   r      sU    0be$ 4BF + +Z%093 93 93r.   r   )r%   commonr   r   r   r   rR   r	   tlr
   r   r   r.   r   <module>rw      s2    	 M M   V3 V3 V3r.   