
    soj                     <   d Z ddlZ ej        e          Z G d d          Z G d d          Z G d d          Z G d	 d
e          Z G d de          Z	 G d de          Z
 G d d          Z G d d          Z G d de          ZdefdZdefdZdS )al  
Drop-in replacements for telegram's plain data-container classes: inline
keyboard buttons/markup, input media (used when editing message media), and
inline query result types. None of these talk to Telethon directly - they're
consumed by src/tg_compat/_bot.py, which translates them into Telethon's
``Button`` / ``send_file`` / inline-query-result-builder calls.
    Nc            	       4    e Zd ZdZ	 	 	 	 ddedededefdZdS )	InlineKeyboardButtonz&Mirrors telegram.InlineKeyboardButton.Ntexturlswitch_inline_query switch_inline_query_current_chatc                 Z    || _         || _        || _        || _        || _        || _        d S N)r   callback_datar   r   r   extra)selfr   r   r   r   r   kwargss          /app/src/tg_compat/_keyboard.py__init__zInlineKeyboardButton.__init__   s7     	*#6 0P-
 


    )NNNN__name__
__module____qualname____doc__strr    r   r   r   r      sg        00
 #'04  	
 ! +.     r   r   c                       e Zd ZdZd ZdS )InlineKeyboardMarkupz&Mirrors telegram.InlineKeyboardMarkup.c                     || _         d S r
   )inline_keyboard)r   r   s     r   r   zInlineKeyboardMarkup.__init__)   s    .r   N)r   r   r   r   r   r   r   r   r   r   &   s)        00/ / / / /r   r   c                   $    e Zd ZdZddedefdZdS )
InputMediaz#Mirrors telegram.InputMedia (base).N
MarkdownV2caption
parse_modec                 0    || _         || _        || _        d S r
   )mediar    r!   )r   r#   r    r!   s       r   r   zInputMedia.__init__0   s    
$r   )Nr   r   r   r   r   r   r   -   sA        --% %s %s % % % % % %r   r   c                       e Zd ZdZdS )InputMediaPhotophotoNr   r   r   typer   r   r   r%   r%   6           DDDr   r%   c                       e Zd ZdZdS )InputMediaVideovideoNr'   r   r   r   r+   r+   :   r)   r   r+   c                       e Zd ZdZdS )InputMediaAnimation	animationNr'   r   r   r   r.   r.   >   s        DDDr   r.   c                   (    e Zd ZdZddededefdZdS )InputTextMessageContentz)Mirrors telegram.InputTextMessageContent.Nmessage_textr!   disable_web_page_previewc                 0    || _         || _        || _        d S r
   )r2   r!   r3   )r   r2   r!   r3   s       r   r   z InputTextMessageContent.__init__E   s    ($(@%%%r   )NN)r   r   r   r   r   boolr   r   r   r   r1   r1   B   sS        33A AS Ac A\` A A A A A Ar   r1   c                       e Zd ZdZdefdZdS )InlineQueryResultz*Mirrors telegram.InlineQueryResult (base).idc                     || _         d S r
   )r8   )r   r8   s     r   r   zInlineQueryResult.__init__N   s    r   Nr   r   r   r   r7   r7   K   s5        443      r   r7   c                   D     e Zd ZdZ	 	 	 d
dedededededef fd	Z xZS )InlineQueryResultArticlez*Mirrors telegram.InlineQueryResultArticle.Nr8   titleinput_message_contentdescriptionreply_markupthumbnail_urlc                     t                                          |           || _        || _        || _        || _        || _        d S r
   )superr   r<   r=   r>   r?   r@   )r   r8   r<   r=   r>   r?   r@   	__class__s          r   r   z!InlineQueryResultArticle.__init__U   sJ     	
%:"&(*r   )NNN)	r   r   r   r   r   r1   r   r   __classcell__)rC   s   @r   r;   r;   R   s        44  -1!+ ++ +  7	+
 + ++ + + + + + + + + + +r   r;   stylec                 r    |s S dddd}|                     |          }| S 	 ddlm}  |di |di}d	 t                                                     D             } fd
|D             }||d<    t                     di |S # t          $ r# t                              d d            cY S w xY w)aR  
    Attach a Bot API 9.4 button color (bg_primary/bg_danger/bg_success) to an
    already-constructed Telethon button object.

    Telethon's Button.* helpers may not (yet) expose `style` as a keyword, so
    this reconstructs the same TL object with the same fields plus `style`
    rather than relying on a helper parameter that might not exist. If the
    installed Telethon version's generated schema doesn't have this field
    yet, construction raises TypeError and the original, unstyled button is
    used instead - colors are a visual nicety, never worth failing a send
    over.
    
bg_success	bg_danger
bg_primary)successdangerprimaryNr   )KeyboardButtonStyleTc                 <    g | ]}|                     d           |S )_)
startswith).0ks     r   
<listcomp>z_with_style.<locals>.<listcomp>   s)    RRRQS@Q@QRqRRRr   c                 2    i | ]}|t          |          S r   )getattr)rQ   rR   	tl_buttons     r   
<dictcomp>z_with_style.<locals>.<dictcomp>   s%    @@@q!WY**@@@r   rE   z\tg_compat: this Telethon version doesn't support colored buttons (Bot API 9.4) yet; sending z without a styler   )	gettelethon.tl.typesrM   varskeysr(   	Exceptionloggerwarning)rV   rE   flag_by_styleflagrM   	style_objfield_namesr   s   `       r   _with_stylerc   f   s/      ,P\]]MU##D|999999''774,77	RR$y//"6"6"8"8RRR@@@@K@@@#wtI(((((   H*3H H H	
 	
 	
 s   A"B	 	*B65B6r?   c                    | dS ddl m} g }| j        D ]R}g }|D ]4}|j        r!|                    |j        |j                  }n|j        !|                    |j        |j                  }nw|j        #|                    |j        |j        d          }nM|j        }t          |t                    r|                    d          }|                    |j        |          }|j        pi }|                    di                               d	          p|                    d	          }	|                    t!          ||	                     6|                    |           Tt#          |          sdS |S )
zEConverts a compat InlineKeyboardMarkup into Telethon's `Button` rows.Nr   )ButtonT)	same_peerzutf-8)data
api_kwargsrE   )telethonre   r   r   r   r   switch_inliner   r   
isinstancer   encodeinliner   rX   appendrc   any)
r?   re   rowsrownew_rowbtnrV   rg   r   rE   s
             r   convert_markup_to_buttonsrt      s   tD+   	: 	:Cw 
?"JJsx99		(4"003;RSS		5A"003;_ko0pp		(dC(( 0;;w//D"MM#(M>>	IOE IIlB//33G<<R		'@R@RENN;y%889999G  t99 tKr   )r   logging	getLoggerr   r]   r   r   r   r%   r+   r.   r1   r7   r;   r   rc   rt   r   r   r   <module>rw      s    		8	$	$       0/ / / / / / / /% % % % % % % %    j       j       *   A A A A A A A A       + + + + +0 + + +("# " " " "J0,@ 0 0 0 0 0 0r   