
    ;Si#                         d dl Z d dlZd dlZddlmZmZmZ ddlmZm	Z	 ddl
mZmZmZ ddlmZ e G d d	e             Zy)
    N   )EventBuilderEventCommonname_inner_event   )utilshelpers)types	functionscustom)SenderGetterc                   d     e Zd ZdZ	 d
dddd fdZedd       Z fdZ G d d	ee	      Z
 xZS )InlineQuerya  
    Occurs whenever you sign in as a bot and a user
    sends an inline query such as ``@bot query``.

    Args:
        users (`entity`, optional):
            May be one or more entities (username/peer/etc.), preferably IDs.
            By default, only inline queries from these users will be handled.

        blacklist_users (`bool`, optional):
            Whether to treat the users as a blacklist instead of
            as a whitelist (default). This means that every chat
            will be handled *except* those specified in ``users``
            which will be ignored if ``blacklist_users=True``.

        pattern (`str`, `callable`, `Pattern`, optional):
            If set, only queries 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

            from telethon import events

            @client.on(events.InlineQuery)
            async def handler(event):
                builder = event.builder

                # Two options (convert user text to UPPERCASE or lowercase)
                await event.answer([
                    builder.article('UPPERCASE', text=event.text.upper()),
                    builder.article('lowercase', text=event.text.lower()),
                ])
    NF)blacklist_usersfuncpatternc                8   t         |   |||       t        |t              r%t	        j
                  |      j                  | _        y |rt        |      r|| _        y t        |d      r't        |j                        r|j                  | _        y t        d      )N)blacklist_chatsr   matchzInvalid pattern type given)super__init__
isinstancestrrecompiler   r   callablehasattr	TypeError)selfusersr   r   r   	__class__s        `/var/www/OnlineNewsSite/project/venv/lib/python3.12/site-packages/telethon/events/inlinequery.pyr   zInlineQuery.__init__2   st    dKgs#::g.44DLHW-"DLWg&8GMM+B"==DL899    c                 Z    t        |t        j                        r| j                  |      S y N)r   r
   UpdateBotInlineQueryEvent)clsupdateothersself_ids       r"   buildzInlineQuery.build?   s&    fe88999V$$ :r#   c                     | j                   r%| j                  |j                        }|sy ||_        t        |   |      S r%   )r   textpattern_matchr   filter)r   eventr   r!   s      r"   r0   zInlineQuery.filterD   s9    <<LL,E"'Ew~e$$r#   c                        e Zd ZdZ fdZ fdZed        Zed        Zed        Z	ed        Z
ed        Z	 dd
d	d
d	dddZed        Z xZS )InlineQuery.Eventa
  
        Represents the event of a new callback query.

        Members:
            query (:tl:`UpdateBotInlineQuery`):
                The original :tl:`UpdateBotInlineQuery`.

                Make sure to access the `text` property of the query if
                you want the text rather than the actual query object.

            pattern_match (`obj`, optional):
                The resulting object from calling the passed ``pattern``
                function, which is ``re.compile(...).match`` by default.
        c                     t         |   t        j                  |j                               t        j                  | |j                         || _        d | _        d| _        y )N)	chat_peerF)	r   r   r
   PeerUseruser_idr   queryr/   	_answered)r   r8   r!   s     r"   r   zInlineQuery.Event.__init__\   sJ    Gu~~emm'DE!!$6DJ!%D"DNr#   c                     t         |   |       t        j                  | j                  | j
                  |j                        \  | _        | _        y r%   )	r   _set_clientr   _get_entity_pair	sender_id	_entities_mb_entity_cache_sender_input_sender)r   clientr!   s     r"   r;   zInlineQuery.Event._set_clientc   s@    G'/4/E/E0G0G0I,DL$,r#   c                 .    | j                   j                  S )zI
            Returns the unique identifier for the query ID.
            )r8   query_idr   s    r"   idzInlineQuery.Event.idh   s    
 ::&&&r#   c                 .    | j                   j                   S )zR
            Returns the text the user used to make the inline query.
            )r8   rE   s    r"   r.   zInlineQuery.Event.texto   s    
 ::###r#   c                 .    | j                   j                  S )z
            The string the user's client used as an offset for the query.
            This will either be empty or equal to offsets passed to `answer`.
            )r8   offsetrE   s    r"   rI   zInlineQuery.Event.offsetv   s     ::$$$r#   c                 .    | j                   j                  S )z
            If the user location is requested when using inline mode
            and the user's device is able to send it, this will return
            the :tl:`GeoPoint` with the position of the user.
            )r8   georE   s    r"   rK   zInlineQuery.Event.geo~   s     ::>>!r#   c                 @    t        j                  | j                        S )z~
            Returns a new `InlineBuilder
            <telethon.tl.custom.inlinebuilder.InlineBuilder>` instance.
            )r   InlineBuilder_clientrE   s    r"   builderzInlineQuery.Event.builder   s     ''55r#   NF )gallerynext_offsetprivate	switch_pmswitch_pm_paramc                  K   | j                   ry|rY|D cg c]  }| j                  |       }	}t        j                  |	       d{    |	D cg c]  }|j	                          }}ng }|rt        j                  ||      }| j                  t        j                  j                  | j                  j                  ||||||             d{   S c c}w 7 c c}w 7 w)a	  
            Answers the inline query with the given results.

            See the documentation for `builder` to know what kind of answers
            can be given.

            Args:
                results (`list`, optional):
                    A list of :tl:`InputBotInlineResult` to use.
                    You should use `builder` to create these:

                    .. code-block:: python

                        builder = inline.builder
                        r1 = builder.article('Be nice', text='Have a nice day')
                        r2 = builder.article('Be bad', text="I don't like you")
                        await inline.answer([r1, r2])

                    You can send up to 50 results as documented in
                    https://core.telegram.org/bots/api#answerinlinequery.
                    Sending more will raise ``ResultsTooMuchError``,
                    and you should consider using `next_offset` to
                    paginate them.

                cache_time (`int`, optional):
                    For how long this result should be cached on
                    the user's client. Defaults to 0 for no cache.

                gallery (`bool`, optional):
                    Whether the results should show as a gallery (grid) or not.

                next_offset (`str`, optional):
                    The offset the client will send when the user scrolls the
                    results and it repeats the request.

                private (`bool`, optional):
                    Whether the results should be cached by Telegram
                    (not private) or by the user's client (private).

                switch_pm (`str`, optional):
                    If set, this text will be shown in the results
                    to allow the user to switch to private messages.

                switch_pm_param (`str`, optional):
                    Optional parameter to start the bot with if
                    `switch_pm` was used.

            Example:

                .. code-block:: python

                    @bot.on(events.InlineQuery)
                    async def handler(event):
                        builder = event.builder

                        rev_text = event.text[::-1]
                        await event.answer([
                            builder.article('Reverse text', text=rev_text),
                            builder.photo('/path/to/photo.jpg')
                        ])
            N)rD   results
cache_timerQ   rR   rS   rT   )r9   
_as_futureasynciowaitresultr
   InlineBotSwitchPMrN   r   messagesSetInlineBotResultsRequestr8   rD   )
r   rW   rX   rQ   rR   rS   rT   rU   xfuturess
             r"   answerzInlineQuery.Event.answer   s     B ~~7>?!4??1-??ll7+++ 077!188:77!33IO	""==!ZZ00#)# +#' > 
 
 
! @+ 8
s:   C$CC$C	C$C(A)C$C"
C$C$c                     t        j                  |       rt        j                  |       S t	        j
                         j                         }|j                  |        |S r%   )inspectisawaitablerZ   ensure_futurer	   get_running_loopcreate_future
set_result)objfs     r"   rY   zInlineQuery.Event._as_future   sI    ""3',,S11((*88:ALLHr#   )Nr   )__name__
__module____qualname____doc__r   r;   propertyrF   r.   rI   rK   rO   rb   staticmethodrY   __classcell__r!   s   @r"   r'   r3   M   s    		#	I
 
	' 
	' 
	$ 
	$ 
	% 
	% 
	" 
	" 
	6 
	6 01_	4_	B 
	 
	r#   r'   r%   )NN)rl   rm   rn   ro   r   classmethodr,   r0   r   r   r'   rr   rs   s   @r"   r   r      sN    #J :16T4: % %%j\ j jr#   r   )rd   r   rZ   commonr   r   r   rP   r   r	   tlr
   r   r   tl.custom.sendergetterr   r    r#   r"   <module>ry      s>     	  ? ?  ) ) 1 j, j jr#   