Ë
    £| k²!  ã                  ó$  — d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z" dd	l#m$Z$m%Z%m&Z& dd
l'm(Z( ddl)m*Z*  ejV                  e,«      Z-dddœZ.dZ/dZ0dd„Z1ddd„Z)dd„Z2y)zàAutomatic publishing from the Database Channel: the listener for the autorename bot's messages in the communication chat,
and /autopublish - the message text and the button name of the posts this bot makes by itself (owner).é    )ÚannotationsN)ÚSimpleNamespace)ÚButtonÚeventsé   )ÚCtxÚ	UserErrorÚclear_stateÚcmdÚguardÚon_cbÚon_textÚrequire_ownerÚsayÚ	send_postÚ	set_stateÚshow)Ú
BUTTON_MAXÚDEFAULT_BUTTONÚDEFAULT_TEXTÚTEXT_MAXÚAutoPublisherÚ	TemplatesÚload_templatesÚmarked_chat_idÚrender_postÚreset_templatesÚsave_templatesÚunknown_variables)Úclassify_mediaÚescÚ	utf16_len)ÚCANCELé   )Ú	read_textÚ05zYour channel)ÚepisodeÚchannelzhttps://t.me/telegramz³<code>{episode}</code> - the episode number the autorename bot wrote in its message, as it wrote it (05 stays 05)
<code>{channel}</code> - the name of the channel the post goes toc                óÜ   — | j                   }|j                  rd|j                  › d|j                  › d�S dj	                  d„ d|j                  fd|j                  ffD «       «      }d|› d	�S )
Nu{   âœ… <b>On.</b> When the autorename bot writes â€œFile uploaded to the Database Channelâ€� in the communication chat (<code>zX</code>), I post that episode in the channel its message names.
Database Channel: <code>z</code>z and c              3  ó,   K  — | ]  \  }}|rŒ	|–— Œ y ­w©N© )Ú.0ÚnÚvs      ú/app/app/handlers/dbpublish.pyÚ	<genexpr>zstatus_line.<locals>.<genexpr>0   s   è ø€ ÐzÑ)p¡  AÒxyœ1Ñ)pùs   ‚
�Ú
DB_CHANNELÚCOMMUNICATION_CHATu   â�¸ <b>Off.</b> Set z# to switch it on (both are needed).)ÚcfgÚauto_publishÚ	comm_chatÚ
db_channelÚjoin)Úctxr4   Úmissings      r0   Ústatus_liner;   (   s~   € Ø
�'‰'€CØ
×ÒðØ—m‘m�_ð %'Ø'*§~¡~Ð&6°gð?ð	
ð
 �l‰lÑz¨<¸¿¹Ð*HÐK_Ðad×anÑanÐJoÑ)pÓzÓz€GØ! ' Ð*MÐNÐNó    c                ó  — dt        | «      dd|j                  rdnd› d�dt        |j                  «      › d�d	|j                  rdnd› d�dt        |j
                  «      › d�d
ddt        g}|j                  r|j                  dd«       |r|› d�nddj                  |«      z   }t        j                  dd«      t        j                  dd«      gt        j                  dd«      gg}g }|j                  r%|j                  t        j                  dd«      «       |j                  r%|j                  t        j                  dd«      «       |r|j                  |«       |j                  t        j                  dd«      g«       ||fS )Nu    ðŸ¤– <b>Automatic publishing</b>Ú u   ðŸ“� <b>Message text</b> (zyour ownÚdefaultÚ)z<pre>ú</pre>u   ðŸ”˜ <b>Button name</b> (uY   The button opens the file link of the ðŸ”� Share URL button of the Database Channel post.z
Variables:é   uB   <i>It has formatting (bold, links ...): ðŸ‘� Preview shows it.</i>z

Ú
u   âœ�ï¸� Message textzdpb:tu   âœ�ï¸� Button namezdpb:bu   ðŸ‘� Previewzdpb:vu   â†©ï¸� Default textzdpb:rtu   â†©ï¸� Default buttonzdpb:rbu   âœ–ï¸� Closezdpb:x)r;   Úcustom_textr!   ÚtextÚcustom_buttonÚbuttonÚ	VARIABLESÚentitiesÚinsertr8   r   ÚinlineÚappend)r9   ÚtÚnoteÚlinesrE   ÚrowsÚresetss          r0   ÚpanelrR   4   s]  € à*Ü�CÓØ
Ø
$°1·=²=¡ZÀiÐ$PÐPQÐRØ
”�A—F‘F“ˆ}˜FÐ#Ø
#°!·/²/¡JÀyÐ#QÐQRÐSØ
”�A—H‘H“ˆ˜fÐ%ØcØ
ØÜð€Eð 	‡z‚zØ�‰�QÐ\Ô]Ù!ˆtˆf�D‰M r¨T¯Y©Y°uÓ-=Ñ=€Dä	�‰Ð,¨gÓ	6¼¿¹ÐFZÐ\cÓ8dÐeÜ	�‰�~ wÓ	/Ð0ð€Dð €FØ‡}‚}Ø�‰”f—m‘mÐ$9¸8ÓDÔEØ‡‚Ø�‰”f—m‘mÐ$;¸XÓFÔGÙØ�‰�FÔØ‡K�K”—‘˜~¨wÓ7Ð8Ô9Ø�ˆ:Ðr<   c                ó4  ‡ ‡‡‡‡	‡
— ‰ j                   ‰ j                  ‰ j                  cŠŠ	Š‰j                  r—t	        ‰ «      ‰ _        t        ‰j                  «      Š‰j                  t        j                  d‰‰j                  ¬«      «      ˆˆˆ fd„«       }t        j                  d‰j                  ‰j                  ‰j                  «       nK‰j                  s‰j                  r3t        j                  d‰j                  xs d‰j                  xs d«       ddˆ ˆ	fd„Š
‰j                  t!        d«      «      t#        ‰ d¬	«      ˆ ˆ
fd
„«       «       }t%        ‰ d«      ˆˆ ˆ	ˆ
fd„«       }t'        ‰ d«      ˆˆ ˆ	ˆ
fd„«       }t'        ‰ d«      ˆ ˆ	ˆ
fd„«       }y )NT)ÚincomingÚchatsÚ
from_usersc              “  ó®   •K  — t        | dd «      ‰k7  st        | dd «      ‰j                  k7  ry ‰j                  j                  | «      ƒ d {  –—†  y 7 Œ­w)NÚchat_idÚ	sender_id)ÚgetattrÚautorename_bot_idÚ	publisherÚhandle)Úeventr4   Úchatr9   s    €€€r0   Úh_noticezregister.<locals>.h_notice\   sK   øè ø€ ä�u˜i¨Ó.°$Ò6¼'À%ÈÐVZÓ:[Ð_b×_tÑ_tÒ:tØØ—-‘-×&Ñ& uÓ-×-Ò-ús   ƒA
AÁAÁAzYautomatic publishing is on: Database Channel %s, communication chat %s, autorename bot %szVautomatic publishing is off: it needs both DB_CHANNEL (%s) and COMMUNICATION_CHAT (%s)r:   c              “  ó¶   •K  — t        ‰t        ‰«      ƒ d {  –—† |«      \  }}|rt        | ||«      ƒ d {  –—†  y t        | ||«      ƒ d {  –—†  y 7 Œ:7 Œ7 Œ	­wr+   )rR   r   r   r   )r^   rN   ÚnewrE   Úkbr9   Údbs        €€r0   Ú
show_panelzregister.<locals>.show_panelm   sU   øè ø€ Ü˜¤N°2Ó$6×6¸Ó=‰ˆˆbÙÜ�e˜T 2Ó&×&Ñ&ä�u˜d BÓ'×'Ñ'ð	 7øà&øà'ús1   ƒA˜A
™A·A¸AÁAÁAÁAÁAÚautopublish)Úownerc              “  ób   •K  — t        ‰| j                  «        ‰| d¬«      ƒ d {  –—†  y 7 Œ­w)NT©rb   )r
   rY   )r^   r9   re   s    €€r0   Úh_autopublishzregister.<locals>.h_autopublisht   s'   øè ø€ ô 	�C˜Ÿ™Ô)Ù˜ DÔ)×)Ò)ús   ƒ$/§-¨/Údpbc              “  ó@  •K  — t        ‰
| «       |d   | j                  }}|dk(  rht        ‰«      ƒ d {  –—† }t        ‰
|d«       t	        | dt
        › dt        |j                  «      › dt        t        «      › d�t        «      ƒ d {  –—†  y |dk(  rot        ‰«      ƒ d {  –—† }t        ‰
|d	«       t	        | d
t        › dt
        › dt        |j                  «      › dt        t        «      › d�	t        «      ƒ d {  –—†  y |dk(  r€t        ‰«      ƒ d {  –—† }t        |t        «      \  }}}t        |||t         dœggd d¬«      }t#        ‰	| j%                  «       ƒ d {  –—† |«      ƒ d {  –—†  t'        | d«      ƒ d {  –—†  y |dk(  r't)        ‰d¬«      ƒ d {  –—†   ‰| d«      ƒ d {  –—†  y |dk(  r't)        ‰d¬«      ƒ d {  –—†   ‰| d«      ƒ d {  –—†  y t+        ‰
|«       t	        | d«      ƒ d {  –—†  y 7 �ŒÌ7 �Œ{7 �Œe7 �Œ7 Œö7 Œ­7 Œ¢7 Œ�7 Œw7 Œh7 ŒO7 Œ@7 Œ!­w)Nr   rM   Údpb_textu¯   âœ�ï¸� <b>Send the new message text.</b>
Telegram formatting is kept (bold, links, spoilers ...); no Telegram editor at hand? Type HTML or Markdown (/formatting).

Variables:
z

Now:
<pre>z</pre>
Default:
<pre>rA   ÚbÚ
dpb_buttonu:   âœ�ï¸� <b>Send the new button name</b> (one line, at most z characters).

Variables:
r/   )rM   ÚuF)rE   rI   ÚbuttonsÚmedia_file_idÚlink_previewuQ   ðŸ‘† A post for episode 05 looks like this (its button opens a sample link here).ÚrtT)rE   u-   â†©ï¸� The message text is the default again.Úrb©rG   u,   â†©ï¸� The button name is the default again.zClosed.)r   rY   r   r   r   rH   r!   rE   r   r#   r   rG   r   r   ÚSAMPLEr   ÚSAMPLE_LINKr   Úget_input_chatr   r   r
   )r^   ÚpartsÚactionÚuidrM   rE   rI   ÚlabelÚshapeÚclientr9   rd   re   s            €€€€r0   Úcb_panelzregister.<locals>.cb_panelz   s1  øè ø€ ä�c˜5Ô!Ø˜A‘h §¡�ˆØ�SŠ=Ü$ RÓ(×(ˆAÜ�c˜3 
Ô+ÜØðä(˜kð *Ü! !§&¡&›k˜]Ð*AÄ#ÄlÓBSÐATÐTZð\ô ó÷ ñ ð �sŠ]Ü$ RÓ(×(ˆAÜ�c˜3 Ô-ÜØØLÌZÈLð YÜ(˜kð *Ü! !§(¡(›m˜_Ð,CÄCÌÓDWÐCXÐX^ð`ô ó÷ ñ ð �sŠ]Ü$ RÓ(×(ˆAÜ$/°´6Ó$:Ñ!ˆD�(˜EÜ#Ø H¸eÌ+Ñ8VÐ7WÐ6XÐhlð  |AôˆEô ˜F¨%×*>Ñ*>Ó*@×$@À%ÓH×HÐHÜ�eÐpÓq×qÑqØ�tŠ^Ü! "¨4Ô0×0Ð0Ù˜UÐ$SÓT×TÑTØ�tŠ^Ü! "¨TÔ2×2Ð2Ù˜UÐ$RÓS×SÑSä˜˜SÔ!Ü�u˜iÓ(×(Ñ(ðI )ùðùð )ùðùð )øð
 %AøÐHøØqøà0øØTøà2øØSøð )úsê   ƒ1H´H µAHÂHÂ	HÂ!HÂ"AHÃ<H	Ã=HÄHÄA
HÅ H
Å!HÅ-HÅ.HÆHÆHÆHÆHÆ-HÆ.HÇHÇ	HÇHÇ HÇ:HÇ;HÈHÈHÈ	HÈHÈHÈHÈHÈHÈHÈHÈHÈHrm   c              “  ó  •K  — | j                   }t        |«      rt        d«      ‚t        |‰j                  d d¬«      \  }}}|j                  «       st        d«      ‚t        |«      t        kD  rt        dt        › dt        |«      › d�«      ‚t        |«      }|rt        dj                  |«      › d	�«      ‚t        ‰
||¬
«      ƒ d {  –—†  t        ‰	| j                  «       d|dv rdndz   } ‰| |d¬«      ƒ d {  –—†  y 7 Œ97 Œ­w)NzPSend the text only: the posts made by themselves are text posts with one button.F)Ú
allow_richzSend some text.úThat is too long: at most ú characters (yours has ú).ú, zP is not a variable. Use {episode} or {channel}. Send the text again, or /cancel.)rE   rI   u   âœ… Message text saved.)ÚhtmlÚmarkdownz& Formatting read from HTML / Markdown.r>   Tri   )Úmessager    r	   r%   Úmarkup_inputÚstripr"   r   r   r8   r   r
   rY   )r^   ÚstÚmrE   rI   ÚhowÚbadrN   r4   r9   rd   re   s           €€€€r0   Úh_textzregister.<locals>.h_text¥   s  øè ø€ à�M‰MˆÜ˜!ÔÜÐnÓoÐoÜ'¨¨3×+;Ñ+;¸TÈeÔTÑˆˆh˜Ø�z‰zŒ|ÜÐ-Ó.Ð.Ü�T‹?œXÒ%ÜÐ8¼¸
ÐBYÔZcÐdhÓZiÐYjÐjlÐmÓnÐnÜ Ó%ˆÙÜ˜tŸy™y¨›~Ð.ð  /Cð  Dó  Eð  EÜ˜R d°XÔ>×>Ð>Ü�C˜Ÿ™Ô)Ø(ÐX[Ð_sÑXsÑ,TÐy{Ñ|ˆÙ˜ ¨$Ô/×/Ñ/ð 	?øð 	0ús$   ƒCDÃ
DÃ3DÃ>DÃ?DÄDro   c              “  ó¼  •K  — | j                   xs dj                  «       }|st        d«      ‚d|v rt        d«      ‚t        |«      t        kD  rt        dt        › dt        |«      › d�«      ‚t        |«      }|rt        dj                  |«      › d	�«      ‚t        ‰|¬
«      ƒ d {  –—†  t        ‰| j                  «        ‰| dd¬«      ƒ d {  –—†  y 7 Œ.7 Œ­w)Nr>   zSend the button name as text.rC   z5A button name is one line. Send it again, or /cancel.rƒ   r„   r…   r†   zP is not a variable. Use {episode} or {channel}. Send the name again, or /cancel.rv   u   âœ… Button name saved.Tri   )
Úraw_textr‹   r	   Úlenr   r   r8   r   r
   rY   )r^   rŒ   Úrawr�   r9   rd   re   s       €€€r0   Úh_buttonzregister.<locals>.h_button·   sà   øè ø€ à�~‰~Ò# ×*Ñ*Ó,ˆÙÜÐ;Ó<Ð<Ø�3‰;ÜÐSÓTÐTÜˆs‹8”jÒ ÜÐ8¼¸ÐD[Ô\_Ð`cÓ\dÐ[eÐegÐhÓiÐiÜ Ó$ˆÙÜ˜tŸy™y¨›~Ð.ð  /Cð  Dó  Eð  EÜ˜R¨Ô,×,Ð,Ü�C˜Ÿ™Ô)Ù˜Ð 8¸dÔC×CÑCð 	-øàCús$   ƒB&CÂ)CÂ*(CÃCÃCÃC)r>   F)rN   Ústrrb   ÚboolÚreturnÚNone)r   rd   r4   r5   r   r\   r   r6   Úonr   Ú
NewMessager[   ÚlogÚinfor7   Úwarningr   r   r   r   )r9   r`   rj   r€   r�   r•   r4   r_   r   rd   re   s   `     @@@@@r0   ÚregisterrŸ   T   sY  ý€ Ø—j‘j #§&¡&¨#¯'©'€O€FˆB�ð ×ÒÜ% cÓ*ˆŒÜ˜cŸm™mÓ,ˆà	�‰”6×$Ñ$¨d¸$È3×K`ÑK`ÔaÓ	bõ	.ó 
cð	.ô
 	�‰ØgØ�N‰N˜CŸM™M¨3×+@Ñ+@õ	
ð 
�Š˜3Ÿ=š=Ü�‰ØdØ�N‰NÒ'˜i¨¯©Ò)C¸)ô	
÷(ð ‡Y�YŒs�=Ó!Ó"Ü
ˆ3�dÔô*ó ó #ð*ô ˆ3�Óö()ó ð()ôT ˆS�*Óö0ó ð0ô" ˆS�,ÓõDó  ñDr<   )r9   r   r˜   r–   )r>   )r9   r   rM   r   rN   r–   r˜   Útuple)r9   r   r˜   r™   )3Ú__doc__Ú
__future__r   ÚloggingÚtypesr   Útelethonr   r   Úcommonr   r	   r
   r   r   r   r   r   r   r   r   r   Ú	dbpublishr   r   r   r   r   r   r   r   r   r   r   r   Útgutilr    r!   r"   Úuir#   rR   r%   Ú	getLoggerÚ__name__rœ   rw   rx   rH   r;   rŸ   r,   r<   r0   Ú<module>r¬      s„   ðñjå "ã Ý !ç #ç |× |× |Ó |÷÷ ÷ ó ÷ 4Ñ 3Ý Ý à€g×Ñ˜Ó!€à nÑ	5€Ø%€ðHð 
ó	Oôô@qDr<   