U
    h                     @   s.   d dl mZmZ ddl mZ G dd dZdS )   )types	functions   )utilsc                   @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZd$ddddZedd Zedd Zedd Zedd Zedd Zedd Zedd Zd%d d!Zd"d# ZdS )&InlineResulta'  
    Custom class that encapsulates a bot inline result providing
    an abstraction to easily access some commonly needed features
    (such as clicking a result to select it).

    Attributes:

        result (:tl:`BotInlineResult`):
            The original :tl:`BotInlineResult` object.
    articlephotoZgifvideoZ	mpeg4_gifaudiodocumentlocationZvenuecontactZgameN)entityc                C   s   || _ || _|| _|| _d S )N)_clientresult	_query_id_entity)selfclientoriginalquery_idr    r   C/tmp/pip-unpacked-wheel-c81u5j2r/telethon/tl/custom/inlineresult.py__init__    s    zInlineResult.__init__c                 C   s   | j jS )a  
        The always-present type of this result. It will be one of:
        ``'article'``, ``'photo'``, ``'gif'``, ``'mpeg4_gif'``, ``'video'``,
        ``'audio'``, ``'voice'``, ``'document'``, ``'location'``, ``'venue'``,
        ``'contact'``, ``'game'``.

        You can access all of these constants through `InlineResult`,
        such as `InlineResult.ARTICLE`, `InlineResult.VIDEO_GIF`, etc.
        )r   typer   r   r   r   r   &   s    zInlineResult.typec                 C   s   | j jS )zz
        The always-present :tl:`BotInlineMessage` that
        will be sent if `click` is called on this result.
        )r   send_messager   r   r   r   message3   s    zInlineResult.messagec                 C   s   | j jS )zE
        The title for this inline result. It may be `None`.
        )r   titler   r   r   r   r   ;   s    zInlineResult.titlec                 C   s   | j jS )zK
        The description for this inline result. It may be `None`.
        )r   descriptionr   r   r   r   r   B   s    zInlineResult.descriptionc                 C   s   t | jtjr| jjS dS )z
        The URL present in this inline results. If you want to "click"
        this URL to open it in your browser, you should use Python's
        `webbrowser.open(url)` for such task.
        N)
isinstancer   r   BotInlineResulturlr   r   r   r   r"   I   s    zInlineResult.urlc                 C   s0   t | jtjr| jjS t | jtjr,| jjS dS )z
        Returns either the :tl:`WebDocument` thumbnail for
        normal results or the :tl:`Photo` for media results.
        N)r    r   r   r!   ZthumbBotInlineMediaResultr   r   r   r   r   r   S   s    zInlineResult.photoc                 C   s0   t | jtjr| jjS t | jtjr,| jjS dS )z
        Returns either the :tl:`WebDocument` content for
        normal results or the :tl:`Document` for media results.
        N)r    r   r   r!   contentr#   r   r   r   r   r   r   ^   s    zInlineResult.documentFc           
         s   |r| j |I dH }n| jr&| j}ntd|rL| j ||I dH \}}n|dkrXdnt|}tjj	|| j
| jj|||||dkrdnt|d}	| j |	|  |	I dH |S )a  
        Clicks this result and sends the associated `message`.

        Args:
            entity (`entity`):
                The entity to which the message of this result should be sent.

            reply_to (`int` | `Message <telethon.tl.custom.message.Message>`, optional):
                If present, the sent message will reply to this ID or message.

            comment_to (`int` | `Message <telethon.tl.custom.message.Message>`, optional):
                Similar to ``reply_to``, but replies in the linked group of a
                broadcast channel instead (effectively leaving a "comment to"
                the specified message).

            silent (`bool`, optional):
                Whether the message should notify people with sound or not.
                Defaults to `False` (send with a notification sound unless
                the person has the chat muted). Set it to `True` to alter
                this behaviour.

            clear_draft (`bool`, optional):
                Whether the draft should be removed after sending the
                message from this result or not. Defaults to `False`.

            hide_via (`bool`, optional):
                Whether the "via @bot" should be hidden or not.
                Only works with certain bots (like @bing or @gif).

            background (`bool`, optional):
                Whether the message should be send in background.

        Nz>You must provide the entity where the result should be sent to)Zpeerr   idsilent
backgroundclear_drafthide_viareply_to)r   Zget_input_entityr   
ValueErrorZ_get_comment_datar   Zget_message_idr   messagesZSendInlineBotResultRequestr   r   r%   r   ZInputReplyToMessageZ_get_response_message)
r   r   r*   Z
comment_tor&   r(   r)   r'   Zreply_idreqr   r   r   clicki   s.    $
  zInlineResult.clickc                    s2   | j s| jr.| jj| j p| jf||I dH S dS )a  
        Downloads the media in this result (if there is a document, the
        document will be downloaded; otherwise, the photo will if present).

        This is a wrapper around `client.download_media
        <telethon.client.downloads.DownloadMethods.download_media>`.
        N)r   r   r   download_media)r   argskwargsr   r   r   r/      s    
zInlineResult.download_media)N)NNNFFFN)__name__
__module____qualname____doc__ZARTICLEZPHOTOZGIFZVIDEOZ	VIDEO_GIFZAUDIOZDOCUMENTZLOCATIONZVENUEZCONTACTZGAMEr   propertyr   r   r   r   r"   r   r   r.   r/   r   r   r   r   r      sD   




	



       
=r   N) r   r   r   r   r   r   r   r   <module>   s   