Ë
    £| k«G  ã                  óª  — d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZmZmZ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&  ejN                  e(«      Z)dZ*dZ+e G d„ d«      «       Z,e G d„ d«      «       Z-d(d„Z.	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d„Z/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*d„Z0ddde*ddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d„Z1dde*ddddœ	 	 	 	 	 	 	 	 	 d,d„Z2dde*ddddœ	 	 	 	 	 	 	 	 	 d,d„Z3d-d„Z4dde*ddddœ	 	 	 	 	 	 	 	 	 d,d„Z5dde*ddddœ	 	 	 	 	 	 	 	 	 d,d„Z6d.d „Z7d!d"d#œd/d$„Z8d%d&œd0d'„Z9y)1a  Links to posts that moved: pointed at their new place in EVERY connected channel.

/repost gives every post of a channel a new message id, and /shift -c puts the posts into another channel. A link to
the old post - https://t.me/name/52, https://t.me/c/123/52, a hyperlink behind some text, a button - that sits in ANY
connected channel would lead nowhere once the old post is gone. relink_channels reads the connected channels, finds
those links and points them at the equivalent new post. Only the digits of the id change (for /shift also the channel
part of the link); the text around a link, the formatting and all other buttons stay exactly as they are.

Rules
  * only a link whose old post HAS a copy is changed: a link to a post that was not copied stays as it is;
  * running it again changes nothing more - a link that already points at a copy is not an old link any more;
  * a post is read again right before it is edited, so something an admin changed meanwhile is never overwritten;
  * a post of somebody else is edited only if the bot has the "Edit messages of others" right; otherwise it is only
    counted, so the report can say so;
  * what Telegram holds back (a copyright notice instead of the post) and a channel Telegram restricts are not edited;
  * nothing is deleted anywhere.
é    )ÚannotationsN)Ú	dataclassÚfield)ÚAnyÚ	AwaitableÚCallableÚOptional)ÚerrorsÚtypesé   )Úensure_markupÚ	link_urls)Ú	PostLinksÚrelink_message)ÚCHUNKÚfetch_messagesÚis_skippableÚpreview_flag)Úmessage_restrictionÚprobe_channel)ÚFATALÚedit_rawÚescÚflood_retryÚ
get_rightsÚpeer_ofÚser_entitiesÚ
ser_markupg      Ð?é   c                  óÒ   — e Zd ZU dZded<   dZded<   dZded<   dZded<   dZded	<   dZ	ded
<   dZ
ded<   dZded<   dZded<   dZded<    ee¬«      Zded<   dZded<   dZded<   y)ÚChannelLinksz'What was found and done in one channel.r   Úchannelr   ÚintÚscannedÚtopÚcheckedÚfoundÚrelinkedÚlinksÚnot_allowedÚ	held_backÚgone©Údefault_factoryÚlistÚfailedNzOptional[str]ÚskippedÚaborted)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r$   r%   r&   r'   r(   r)   r*   r+   r,   r   r/   r0   r1   r2   © ó    ú/app/app/crosslinks.pyr!   r!   '   sƒ   … á1àƒLØ€GˆSÓØ€CˆƒLØ€GˆSÓØ€Eˆ3ƒNØ€HˆcÓØ€Eˆ3ƒNØ€K�ÓØ€IˆsÓØ€Dˆ#ƒMÙ¨Ô.€FˆDÓ.Ø!€Gˆ]Ó!Ø!€Gˆ]Ô!r9   r!   c                  óò   — e Zd ZU dZ ee¬«      Zded<   dZded<   dZ	ded<   d	Z
d
ed<   dZded<   dZded<   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y	)ÚCrossResultzNWhat a run did in all the channels (also handed to `progress` while it works).r-   r/   Úchannelsr   r#   ÚtotalÚindexNzOptional[ChannelLinks]ÚcurrentÚ ÚstrÚphaseFÚboolÚstoppedc                ó:   — t        d„ | j                  D «       «      S )Nc              3  ó4   K  — | ]  }|j                   –— Œ y ­w©N)r(   ©Ú.0Úcs     r:   Ú	<genexpr>z'CrossResult.relinked.<locals>.<genexpr>G   s   è ø€ Ð5¡} !�1—:•:¡}ùó   ‚©Úsumr=   ©Úselfs    r:   r(   zCrossResult.relinkedE   s   € äÑ5 t§}¢}Ó5Ó5Ð5r9   c                ó:   — t        d„ | j                  D «       «      S )Nc              3  ó4   K  — | ]  }|j                   –— Œ y ­wrH   )r)   rI   s     r:   rL   z$CrossResult.links.<locals>.<genexpr>K   s   è ø€ Ð2¡M˜q�1—7•7¡MùrM   rN   rP   s    r:   r)   zCrossResult.linksI   s   € äÑ2 D§M¢MÓ2Ó2Ð2r9   c           	     óŽ   — | j                   D ���cg c]%  }|j                  D ]  \  }}|j                  ||f‘Œ Œ' c}}}S c c}}}w rH   )r=   r0   r"   )rQ   rK   ÚmidÚnames       r:   r0   zCrossResult.failedM   s:   € à04·²ÕX±¨1ÈqÏxÌxÁ)À#Àt�—‘˜C Ò&ÈxÐ&°ÓXÐXùÔXs   ‘*A c                ó:   — t        d„ | j                  D «       «      S )Nc              3  ó4   K  — | ]  }|j                   –— Œ y ­wrH   )r*   rI   s     r:   rL   z*CrossResult.not_allowed.<locals>.<genexpr>S   s   è ø€ Ð8©- Q�1—=•=©-ùrM   rN   rP   s    r:   r*   zCrossResult.not_allowedQ   s   € äÑ8¨$¯-ª-Ó8Ó8Ð8r9   c                óZ   — | j                   D �cg c]  }|j                  sŒ|‘Œ c}S c c}w rH   )r=   r(   ©rQ   rK   s     r:   Úchanged_channelszCrossResult.changed_channelsU   s$   € àŸ=š=Ó7™=�a¨A¯J«J’˜=Ñ7Ð7ùÒ7ó   �(¡(c                óZ   — | j                   D �cg c]  }|j                  sŒ|‘Œ c}S c c}w rH   )r=   r1   rZ   s     r:   r1   zCrossResult.skippedY   s$   € àŸ=š=Ó6™=�a¨A¯I«I’˜=Ñ6Ð6ùÒ6r\   c                ó–   — | j                    xr; | j                   xr, | j                   xr t        d„ | j                  D «       «       S )z(Everything that had to be done was done.c              3  ó4   K  — | ]  }|j                   –— Œ y ­wrH   )r2   rI   s     r:   rL   z$CrossResult.clean.<locals>.<genexpr>`   s   è ø€ ÐXzÑlyÐghÐYZ×YbÕYbÑlyùrM   )rE   r0   r*   Úanyr=   rP   s    r:   ÚcleanzCrossResult.clean]   sE   € ð —<‘<ÐÒz¨¯© OÒz¸D×<LÑ<LÐ8LÒzÔUXÑXzÐlp×lyÒlyÓXzÓUzÐQzÐzr9   )Úreturnr#   )rb   r/   )rb   rD   )r3   r4   r5   r6   r   r/   r=   r7   r>   r?   r@   rC   rE   Úpropertyr(   r)   r0   r*   r[   r1   ra   r8   r9   r:   r<   r<   :   sÒ   … áXá¨4Ô0€HˆdÓ0Ø€Eˆ3ƒNØ€Eˆ3ƒNØ&*€GÐ#Ó*Ø€Eˆ3ƒOØ€GˆTÓàò6ó ð6ð ò3ó ð3ð òYó ðYð ò9ó ð9ð ò8ó ð8ð ò7ó ð7ð ò{ó ñ{r9   r<   c              ƒ  ó  K  — |j                   rLt        | ||j                  |j                  |j                  |j
                  t        |«      ¬«      ƒ d {  –—†  y t        | ||j                  |j
                  ¬«      ƒ d {  –—†  y 7 Œ17 Œ­w)N)ÚtextÚentitiesÚmarkupÚpreview)rg   )Útext_changedr   Úidre   rf   rg   r   )ÚclientÚpeerÚmÚrls       r:   Ú_editro   c   sg   è ø€ Ø	‡‚Ü�v˜t Q§T¡T°·±À"Ç+Á+ÐVX×V_ÑV_ÔiuÐvwÓixÔy×yÑyä�v˜t Q§T¡T°"·)±)Ô<×<Ñ<ð 	zøà<ús$   ‚ABÁBÁ+BÂB	ÂBÂ	Bc             ƒ  ó$  K  — g }d}||k  �rz|
r
 |
«       r	 |S t        |t        z   dz
  |«      }t        | |t        t	        ||dz   «      «      «      ƒ d{  –—† D ]ä  }|�*t        |t        j                  t        j                  f«      rŒ0|xj                  dz  c_	        |j                  |v rŒTt        |«      r|xj                  dz  c_        Œut        ||«      €Œ‚|xj                  dz  c_        t        |dd«      s&|j                  |v s|s|xj                   dz  c_        ŒÊ|j#                  |j                  «       Œæ ||_        |dz   } |	«       ƒ d{  –—†  |r"||k  rt'        j(                  |«      ƒ d{  –—†  ||k  r�Œz|S 7 �Œ47 Œ47 Œ­w)zmRead ids 1..top; the ids of the posts that have links to change (and may be changed) come back, oldest first.r   NÚoutF)Úminr   r   r/   ÚrangeÚ
isinstancer   ÚMessageEmptyÚMessageServicer&   rj   r   r+   r   r'   Úgetattrr*   Úappendr$   ÚasyncioÚsleep)rk   rl   r%   r)   ÚleaveÚmineÚcan_edit_othersÚresÚpauseÚtickÚshould_stopÚtodoÚaÚhirm   s                  r:   Ú_scanr…   j   sm  è ø€ ð
 €DØ	€AØ
ˆs‹(Ù™;œ=Øð. €Kô- �”U‘˜Q‘ Ó$ˆÜ% f¨d´D¼¸qÀ"ÀqÁ&Ó9IÓ4JÓK×KÒKˆAØˆyœJ q¬5×+=Ñ+=¼u×?SÑ?SÐ*TÔUØØ�KŠK˜1Ñ�KØ�t‰t�u‰}ØÜ" 1Ô%Ø—’ Ñ"•ØÜ˜a Ó'Ð/ØØ�IŠI˜‰N�IÜ˜A˜u eÔ,°·±¸±ÁoØ—’ 1Ñ$•ØØ�K‰K˜Ÿ™Õð Lð  ˆŒØ�‰FˆÙ‹f�ˆÙ�Q˜#’XÜ—-‘- Ó&×&Ð&ð1 ˆsŒ(ð2 €Kð+ Lùð$ 	øà&ús=   ‚AFÁF	ÁDFÅFÅ#FÅ;FÅ<	FÆFÆFÆFc          	   ƒ  óÜ  ‡ ‡‡‡K  — d\  }}|D �]Ê  }|
r	 |
«       r yt        ‰ ‰|g«      ƒ d{  –—† \  Št        ‰«      r|xj                  dz  c_        ŒHt        ‰«      r|xj                  dz  c_        Œit        ‰|«      Š‰€Œx	 t        ˆ ˆˆˆfd„«      ƒ d{  –—†  t        ‰j                  «      r,t        ‰ ‰‰j                  ‰j                  |¬«      ƒ d{  –—†  d\  }}|xj.                  dz  c_        |xj0                  ‰j0                  z  c_        i }‰j2                  r0|j5                  ‰j6                  t9        ‰j:                  «      ¬	«       ‰j<                  rt?        ‰j                  «      |d
<   	  |j@                  |j                  ‰j                  fi |¤Žƒ d{  –—†   |	«       ƒ d{  –—†  tC        jD                  |«      ƒ d{  –—†  �ŒÍ y7 �Œ¯7 �ŒE7 �Œ# t        j                  $ r Y �Œît        $ r }t        |«      j                  }t         j#                  d|j                  ‰j                  ||«       |j$                  j'                  ‰j                  |f«       ||k(  r|dz   nd}|}|t(        v s	|t*        k\  r||_        Y d}~ yY d}~�Œ‘d}~ww xY w7 Œþ# t        $ r1 t         j#                  d|j                  ‰j                  d¬«       Y �Œ5w xY w7 �Œ/7 �Œ­w)zSEdit the posts in `ids`, each one read again first. False when the run was stopped.)r   NFNr   c                 ó    •— t        ‰ ‰‰‰«      S rH   )ro   )rk   rm   rl   rn   s   €€€€r:   Ú<lambda>z_apply.<locals>.<lambda>¡   s   ø€ ¤e¨F°D¸!¸RÔ&@r9   )r   z*could not update the links of %s/%s: %s %sT)re   rf   Úbuttonsz%could not save the new links of %s/%s)Úexc_info)#r   r   r,   r   r+   r   r   r   rg   r   rj   r
   ÚMessageNotModifiedErrorÚ	ExceptionÚtyper3   ÚlogÚwarningr0   rx   r   ÚABORT_AFTERr2   r(   r)   ri   Úupdatere   r   rf   Úmarkup_changedr   Úupdate_post_by_messagery   rz   )rk   ÚdbÚchrl   Úidsr)   r~   ÚdelayÚsettle_pauser€   r�   ÚstreakÚ	last_namerU   ÚerV   Úfieldsrm   rn   s   `  `             @@r:   Ú_applyr�   �   sf  ûè ø€ ð
  Ñ€FˆIÜˆÙ™;œ=ÙÜ# F¨D°3°%Ó8×8‰ˆÜ˜Œ?Ø�HŠH˜‰M�HØÜ˜qÔ!Ø�MŠM˜QÑ�MØÜ˜A˜uÓ%ˆØˆ:Øð	ÜÖ@ÓA×AÐAÜ˜Ÿ™Ô#Ü# F¨D°!·$±$¸¿	¹	ÈÔV×VÐVð $Ñˆ�	Ø�Š˜Ñ�Ø�	Š	�R—X‘XÑ�	ØˆØ�?Š?Ø�M‰M˜rŸw™w´¸b¿k¹kÓ1JˆMÔKØ×ÒÜ *¨2¯9©9Ó 5ˆF�9Ñð	]Ø+�"×+Ñ+¨B¯E©E°1·4±4ÑB¸6ÑB×BÐBñ ‹f�ˆÜ�m‰m˜EÓ"×"Ò"ðU ðV ðQ 9ùð BùàVúÜ×-Ñ-ò 	ÚÜò 		Ü˜“7×#Ñ#ˆDÜ�K‰KÐDÀbÇeÁeÈQÏTÉTÐSWÐYZÔ[Ø�J‰J×Ñ˜qŸt™t T˜lÔ+Ø#'¨9Ò#4�V˜a’Z¸!ˆFØˆIØ”u‰} ¬+Ò 5Ø"�”ÝÝûð		úð& CùÜò 	]Ü�K‰KÐ?ÀÇÁÈÏÉÐW[ˆK×\ð	]úàùØ"ûsÁ   †(K,®G¯AK,ÂG&ÂG ÂA G&ÃG#ÃG&Ã!BK,Å=+J)Æ(J'Æ)J)Æ-
K,Æ7K&Æ8K,ÇK)Ç	K,Ç G&Ç#G&Ç&J$Ç9K,Ç<J$ÈBJÊK,ÊJ$Ê$K,Ê'J)Ê)6K#ËK,Ë"K#Ë#K,Ë)K,g333333ó?gffffffæ?©r{   r—   r˜   r   Úprogressr�   Úresultc             ƒ  ó\  ‡‡K  — |
�|
n	t        «       Št        |«      ‰_        |xs i }|j                  s‰S dˆˆfd„}t	        |d«      D �]Í  \  }}|	r |	«       r
d‰_         �n·t        |¬«      }‰j                  j                  |«       ||dc‰_	        ‰_
        ‰_         |«       ƒ d{  –—†  t        |«      }t        | |«      ƒ d{  –—† }|�|j                  sd|_        Œ›|� |j                   s|j"                  sd|_        Œ½|€dnt%        |j"                  «      }t'        | |«      ƒ d{  –—† \  }}}|r||_        Œø|rd	|› d
�|_        �Œ|xs d|_        	 t+        | ||j(                  |t-        |j/                  |j0                  d«      «      |j3                  |j0                  «      ƒ d{  –—† |||||	¬«      ƒ d{  –—† }|	r |	«       r	d‰_         n@d‰_         |«       ƒ d{  –—†  t5        | ||||||||||	¬«      ƒ d{  –—† s	d‰_         n�ŒÐ d\  ‰_        ‰_
        ‰S 7 �Œ�7 �Œe7 �Œ7 Œ‚7 Œr7 ŒL7 Œ0# t6        j8                  $ rY}t:        j=                  d|j0                  t?        |«      j@                  «       t?        |«      j@                  |_!        Y d}~�ŒZd}~ww xY w­w)a6  Point every link that `links` knows (old post -> its new place) at the new place, in each of `channels`.

    `leave` ({channel id: message ids}) are posts that must not be touched, such as the originals of a repost.
    `result` may be given to watch a run from outside: it is filled in while the run goes on.Nc               “  ó8   •K  — ‰ r ‰ ‰«      ƒ d {  –—†  y y 7 Œ­wrH   r8   )rŸ   r~   s   €€r:   r€   zrelink_channels.<locals>.tickÙ   s   øè ø€ ÙÙ˜3“-×Ñð Øús   ƒ‘’r   T)r"   Úscanzthe bot is not an admin therez*the bot has no right to post or edit therez!Telegram restricts this channel (Ú)r   r8   )r   r€   r�   Úedit)r—   r˜   r€   r�   z;could not read %s while pointing links at the new posts: %s)rA   N©rb   ÚNone)"r<   Úlenr>   r–   Ú	enumeraterE   r!   r=   rx   r?   r@   rC   r   r   Úadminr1   Úpostr¥   rD   r   r%   r…   ÚsetÚgetrj   Úmine_message_idsr�   r
   ÚRPCErrorrŽ   r�   r�   r3   r2   )rk   r”   r)   r=   r{   r—   r˜   r   rŸ   r�   r    r€   Únr•   Úonerl   ÚrightsÚ
can_othersr%   ÚwhyÚerrr‚   r›   r~   s           `              @r:   Úrelink_channelsr¶   Á   sˆ  ùè ø€ ð$ Ð&‰&¬K«M€CÜ�H“€C„IØŠK�R€EØ�9Š9Øˆ
ö ô ˜8 Q×'‰ˆˆ2Ù™;œ=ØˆCŒKÚÜ 2Ô&ˆØ�‰×Ñ˜CÔ Ø,-¨s°FÐ)ˆŒ	�3”; ¤	Ù‹f�ˆÜ�r‹{ˆÜ! &¨"Ó-×-ˆØÐ f§l¢lØ9ˆCŒKØØÐ v§{¢{°f·k²kØFˆCŒKØØ#˜^‘T´°f·k±kÓ1Bˆ
Ü+¨F°DÓ9×9‰ˆˆS�#ÙØˆCŒKØÙØ=¸c¸UÀ!ÐDˆCŒKÙØ’(˜ˆŒð	+ÜØ˜˜cŸg™g u¬c°%·)±)¸B¿E¹EÀ2Ó2FÓ.GÈr×ObÑObÐce×chÑchÓOi×IiÐkuØ˜5 t¸ô÷ ˆDñ ™{œ}Ø"�”ÙØˆCŒIÙ“&�LˆLÜØ˜˜B  d¨E°3¸eÐR^ÐeiØ'ô÷ ð ð #�”ÙñðG (ðX &Ñ€C„IˆsŒ{Ø€JðM 	ùà-ùð :ùð Jjøðøð øðùô �‰ò 	+Ü�K‰KÐUÐWY×W\ÑW\Ô^bÐcdÓ^e×^nÑ^nÔoÜ˜q›'×*Ñ*ˆC�KŠKûð	+üs·   „B'J,Â+H,Â,J,Ã
H/ÃA$J,Ä/H2Ä0,J,ÅAH=Æ2H5Æ3H=ÇH7ÇH=ÇJ,ÇH=Ç,H9Ç-H=È
H;ÈH=ÈJ,È/J,È2J,È5H=È7H=È9H=È;H=È=J)ÉAJ$ÊJ,Ê$J)Ê)J,©r—   r˜   r   rŸ   r�   r    c             ƒ  óš  K  — |	�|	n	t        «       }
t        |j                  |j                  ¬«      ƒ d{  –—† «      }|s|
S |j	                  |j                  d«      ƒ d{  –—†  t        | |t        j                  ||«      |j                  «       ƒ d{  –—† |j                  t        |«      i||||||
¬«      ƒ d{  –—† S 7 Œ�7 Œc7 Œ17 Œ
­w)zÔAfter /repost: every link to an old post of `ch`, in any connected channel, points at the copy of that post.
    The originals themselves are not touched (they are deleted later, or kept if the repost is undone).N©rU   r)   rž   )
r<   ÚdictÚmigration_pairsrj   Úset_markr¶   r   Úfor_channelÚlist_channelsr¬   )rk   r”   r•   Úmigr—   r˜   r   rŸ   r�   r    r~   r–   s               r:   Úrelink_after_repostrÀ     sÂ   è ø€ ð Ð&‰&¬K«M€CÜ
�R×'Ñ'¨C¯F©FÐ'Ó3×3Ó
4€CÙØˆ
Ø
�+‰+�c—f‘f˜gÓ
&×&Ð&Ü Ø�”I×)Ñ)¨"¨cÓ2¸"×:JÑ:JÓ:L×4LÐUW×UZÑUZÔ\_Ð`cÓ\dÐTeÐmrØ!¨¸È{Ðcfô÷ ð ð	 4øð 'øà4LøðúsE   ‚3CµC¶+CÁ!CÁ"3CÂCÂ(CÂ>C	Â?CÃCÃCÃ	Cc             ƒ  ó¶  K  — |	�|	n	t        «       }
|j                  |j                  d«      ƒ d{  –—† s|
S |j                  |j                  ¬«      ƒ d{  –—† D ��ci c]  \  }}||“Œ
 }}}t	        | |t        j                  ||«      |j                  «       ƒ d{  –—† |j                  t        |«      i||||||
¬«      ƒ d{  –—† S 7 Œš7 Œvc c}}w 7 Œ77 Œ­w)ziBefore the copies of a repost are removed: links that were pointed at them go back to the original posts.Nr)   r¹   rž   )	r<   Úhas_markrj   r»   r¶   r   r½   r¾   r¬   )rk   r”   r•   r¿   r—   r˜   r   rŸ   r�   r    r~   ÚoldÚnewÚbacks                 r:   Úrestore_after_undorÆ     sÖ   è ø€ ð
 Ð&‰&¬K«M€CØ—‘˜SŸV™V WÓ-×-Ð-Øˆ
Ø+-×+=Ñ+=À#Ç&Á&Ð+=Ó+I×%IÐ%IÔJÑ%I™˜˜cˆC�‰HÐ%I€DÑJÜ Ø�”I×)Ñ)¨"¨dÓ3¸2×;KÑ;KÓ;M×5MÐVX×V[ÑV[Ô]`ÐaeÓ]fÐUgÐotØ!¨¸È{Ðcfô÷ ð ð .øà%IúÓJà5MøðúsQ   ‚.C°C±%CÁCÁCÁCÁ+2CÂCÂ(CÃCÃCÃCÃCÃCc                ór   — t        | j                  | j                  ||j                  |j                  ¬«      S )zoLinks to the posts of the source channel -> the equivalent posts of the destination (`ids`: source id -> copy).©ÚusernameÚ
channel_idr–   Útarget_usernameÚ	target_id)r   rÉ   rj   )ÚsrcÚdstr–   s      r:   Úshift_linksrÏ   .  s-   € äØ—‘¨#¯&©&°cÈ3Ï<É<Ðcf×ciÑciôð r9   c             ƒ  ó¶  K  — |
�|
n	t        «       }t        |j                  |j                  «      ƒ d{  –—† «      }|s|S |j	                  |j                  d«      ƒ d{  –—†  |j                  «       ƒ d{  –—† D �cg c]  }|j                  |j                  k7  sŒ|‘Œ  }}t        | |t        |||«      ||||||	|¬«
      ƒ d{  –—† S 7 Œ—7 Œm7 ŒWc c}w 7 Œ­w)zºAfter /shift -c: a link to a post of the source channel, in any connected channel (the source itself is only
    read, never changed), points at the copy of that post in the destination.Nr)   r·   )r<   rº   Úshift_pairsrj   r¼   r¾   r¶   rÏ   )rk   r”   ÚshiftrÍ   rÎ   r—   r˜   r   rŸ   r�   r    r~   r–   rK   Úchanss                  r:   Úrelink_after_shiftrÔ   5  sÍ   è ø€ ð Ð&‰&¬K«M€CÜ
�R—^‘^ E§H¡HÓ-×-Ó
.€CÙØˆ
Ø
�+‰+�e—h‘h Ó
(×(Ð(Ø ×.Ñ.Ó0×0Ð0ÓCÑ0�1°A·D±D¸C¿F¹F³NŠQÐ0€EÐCÜ Ø�”K  S¨#Ó.°¸UÐQ]ÐejØ {¸3ô÷ ð ð .øð )øØ0úÒCðúsW   ‚2C´Cµ+CÁ CÁ!CÁ8CÁ9CÁ?CÂCÂ"%CÃCÃCÃCÃCÃCc             ƒ  óX  K  — |
�|
n	t        «       }|j                  |j                  d«      ƒ d{  –—† s|S |j                  |j                  «      ƒ d{  –—† D ��ci c]  \  }}||“Œ
 }}}t	        |j
                  |j                  ||j
                  |j                  ¬«      }|j                  «       ƒ d{  –—† D �cg c]  }|j                  |j                  k7  sŒ|‘Œ  }}t        | ||||j                  t        |«      i|||||	|¬«      ƒ d{  –—† S 7 Œæ7 ŒÃc c}}w 7 Œhc c}w 7 Œ­w)zfBefore the copies of a shift are removed: links that were pointed at them go back to the source posts.Nr)   rÈ   rž   )	r<   rÂ   rj   rÑ   r   rÉ   r¾   r¶   r¬   )rk   r”   rÒ   rÍ   rÎ   r—   r˜   r   rŸ   r�   r    r~   rÃ   rÄ   rÅ   r)   rK   rÓ   s                     r:   Úrestore_after_shift_undorÖ   G  s  è ø€ ð
 Ð&‰&¬K«M€CØ—‘˜UŸX™X wÓ/×/Ð/Øˆ
Ø+-¯>©>¸%¿(¹(Ó+C×%CÐ%CÔDÑ%C™˜˜cˆC�‰HÐ%C€DÑDÜØ—‘¨#¯&©&°dÈCÏLÉLÐdg×djÑdjô€Eð !×.Ñ.Ó0×0Ð0ÓCÑ0�1°A·D±D¸C¿F¹F³NŠQÐ0€EÐCÜ Ø��E˜5¨¯©´°T³Ð(;À5ÐWcÐkpØ {¸3ô÷ ð ð 0øà%CúÓDð 1úÒCðúsd   ‚.D*°D±$D*ÁDÁD*ÁDÁ*AD*Â8D!Â9D*Â?D#ÃD#Ã"0D*ÄD(ÄD*ÄD*ÄD*Ä#D*c           	     ó^   — t        t        | dd «      xs t        t        | dd«      «      «      S )NÚtitlerj   Ú?)r   rw   rB   )r•   s    r:   Ú_namerÚ   [  s)   € ÜŒw�r˜7 DÓ)ÒH¬S´¸¸TÀ3Ó1GÓ-HÓIÐIr9   zthe new copiesF)ÚwhatrÅ   c               óÔ  — g }| j                   D �cg c]  }|j                  rŒ|‘Œ }}| j                  r½t        | j                  «      }|j                  d| j                  › d| j                  › d|› d|rdnd|z   › d�	«       |dkD  s|dk(  r£t        |«      dkD  r•| j                  d	d
 D ]D  }|j                  dt        |j                  «      › d|j                  › d|j                  › d�«       ŒF n>|r<| j                  s0t        d„ |D «       «      s|j                  dt        |«      › d�«       | j                  rCdj                  d„ | j                   D «       «      }|j                  | j                  › d|› d�«       | j                  }|rpdj                  d„ |d	d D «       «      }	|j                  t        |«      › d|	› t        |«      dkD  rdnd› d�«       t        d„ |D «       «      r|j                  d«       | j                   D ]M  }|j                  sŒ|j                  dt        |j                  «      › dt        |j                  «      › d�«       ŒO | j                  }
|
r-|j                  dd j                  d!„ |
d	d" D «       «      z   «       t!        d#„ | j                   D «       «      }|r|j                  |› d$�«       | j                  r|j                  d%«       |S c c}w )&zpLines (HTML) for the end of a repost / shift. `what`: where the links point now. `back`: they were pointed back.õ   ðŸ”— z link(s) in z post(s) of z channel(s) z point back at the original postsznow point at Ú.r   Né   u   â€¢ z: z post(s)c              3  óP   K  — | ]  }|j                   xs |j                  –— Œ  y ­wrH   )r2   r0   rI   s     r:   rL   zreport_lines.<locals>.<genexpr>l  s!   è ø€ Ð-RÉTÈ¨a¯i©iÒ.C¸1¿8¹8Ó.CÉTùs   ‚$&u   ðŸ”— Checked z+ channel(s): no link there needed changing.z, c              3  ó`   K  — | ]&  }|j                   sŒt        |j                  «      –— Œ( y ­wrH   )r*   rÚ   r"   rI   s     r:   rL   zreport_lines.<locals>.<genexpr>o  s    è ø€ ÐR±L¨qÀAÇMÃMœ% §	¡	×*±Lùs   ‚.”.zT post(s) with such a link were made by somebody else and the bot may not edit them (u`   ). Give the bot the â€œEdit messages of othersâ€� right and press â€œðŸ”— Update links againâ€�.c              3  ó\   K  — | ]$  \  }}}t        |«      › d |› dt        |«      › �–— Œ& y­w)z #Ú N)rÚ   r   )rJ   rK   rU   rV   s       r:   rL   zreport_lines.<locals>.<genexpr>v  s2   è ø€ Ð[ÑPZÁÀÀ3Èœe A›h˜Z r¨#¨¨a´°D³	¨{Ô;ÑPZùs   ‚*,r   z, post(s) could not get their links updated (õ   â€¦rA   z).c              3  ó,   K  — | ]  \  }}}|d v –— Œ y­w))ÚMessageIdInvalidErrorÚMessageAuthorRequiredErrorNr8   )rJ   Ú_rV   s      r:   rL   zreport_lines.<locals>.<genexpr>x  s#   è ø€ ÐhÑagÑS]ÐSTÐVWÐY]ˆtÐNÔNÑagùs   ‚zˆTelegram refuses edits to posts that other bots (or other people) made or put buttons on: those links have to be changed by their owner.zGave up on ú (zNot looked at: z; c              3  óx   K  — | ]2  }t        |j                  «      › d t        |j                  «      › d�–— Œ4 y­w)ré   r¤   N)rÚ   r"   r   r1   rI   s     r:   rL   zreport_lines.<locals>.<genexpr>‚  s5   è ø€ Ð0oÑcnÐ^_´E¸!¿)¹)Ó4DÐ3EÀRÌÈAÏIÉIËÐGWÐWXÔ1YÑcnùs   ‚8:é   c              3  ó4   K  — | ]  }|j                   –— Œ y ­wrH   )r+   rI   s     r:   rL   zreport_lines.<locals>.<genexpr>ƒ  s   è ø€ Ð1¡L˜qˆq�{�{¡LùrM   zJ post(s) are held back by Telegram (copyright notice) and were left alone.uZ   â�¹ Stopped before every channel was done - press â€œðŸ”— Update links againâ€� to finish.)r=   r1   r(   r¨   r[   rx   r)   rÚ   r"   rE   r`   r*   Újoinr0   r2   r   rO   )r~   rÛ   rÅ   rq   rK   Údoner°   Únamesr0   Úsampler1   Úhelds               r:   Úreport_linesrò   _  s¦  € à€CØ—|’|Ó5‘|�!¨1¯9«9ŠA�|€DÐ5Ø
‡|‚|Ü�×$Ñ$Ó%ˆØ�
‰
Ø�C—I‘I�;˜l¨3¯<©<¨.¸ÀQÀCÀ|Ù59Ñ1¸ÐQUÑ?UÐVÐVWðYô	
ð ˆqŠ5�Q˜!’V¤ D£	¨A¢Ø×)Ñ)¨#¨2Ó.�Ø—
‘
˜T¤%¨¯	©	Ó"2Ð!3°2°a·g±g°Y¸lÈ1Ï:É:È,ÐV^Ð_Õ`ñ /á	�c—k’k¬#Ñ-RÉTÓ-RÔ*RØ�
‰
�]¤3 t£9 +Ð-XÐYÔZØ
‡‚Ø—	‘	ÑR°C·L²LÓRÓRˆØ�
‰
Ø�‰Ðð  ØˆwÐvðxô	
ð �Z‰Z€FÙØ—‘Ñ[ÐPVÐWYÐXYÑPZÓ[Ó[ˆØ�
‰
”c˜&“k�]Ð"NÈvÈhÔ`cÐdjÓ`kÐnoÒ`oÑW\ÐuwÐVxÐxzÐ{Ô|ÜÑhÑagÓhÔhØ�J‰Jð;ôð �\Œ\ˆØ�9‹9Ø�J‰J˜¤U¨1¯9©9Ó%5Ð$6°b¼¸Q¿Y¹Y»Ð8HÈÐKÕLð ð �k‰k€GÙØ�
‰
Ð$ t§y¡yÑ0oÐcjÐkmÐlmÑcnÓ0oÓ'oÑoÔpÜÑ1 C§L¢LÓ1Ó1€DÙØ�
‰
�d�VÐeÐfÔgØ
‡{‚{Ø�
‰
ÐoÔpØ€JùòM 6s
   ‘K%£K%z Pointing links at the new copies)rØ   c               óÌ  — | j                   }|�dt        |j                  «      › �nd}| j                  rd| j                  › d| j                  › d�nd}|�9| j
                  dk(  r*|j                  rd|j                  › d|j                  › d�}n>|�:| j
                  d	k(  r+d
|j                  › d|j                  |j                  z
  › d�}nd}d|› |› |› |› d| j                  › d�S )z'The line shown while a run is going on.z - rA   ré   z of r¤   r£   z
Reading posts rä   r¥   z
Changing links: u    post(s) doneâ€¦rÝ   Ú
z link(s) changed so far.)r@   rÚ   r"   r>   r?   rC   r%   r$   r(   r'   r*   r)   )r~   rØ   ÚcurÚwhereÚstepÚdetails         r:   Úprogress_textrù   ‹  sß   € à
�+‰+€CØ*-¨/ˆc”%˜Ÿ™Ó$Ð%Ñ&¸r€EØ/2¯yªyˆR�—	‘	ˆ{˜$˜sŸy™y˜k¨Ñ+¸b€DØ
€˜3Ÿ9™9¨Ò.°3·7²7Ø# C§K¡K =°°S·W±W°I¸SÐA‰Ø	ˆ˜SŸY™Y¨&Ò0Ø% c§l¡l ^°4¸¿	¹	ÀCÇOÁOÑ8SÐ7TÐTdÐe‰àˆØ�5�'˜$˜ ˜w v h¨b°·±°Ð;SÐTÐTr9   r¦   )r%   r#   r)   r   r{   r¬   r|   r¬   r}   rD   r~   r!   r   Úfloatr€   úCallable[[], Awaitable[None]]r�   úOptional[Callable[[], bool]]rb   r/   )r–   r/   r)   r   r~   r!   r—   rú   r˜   rú   r€   rû   r�   rü   rb   rD   )r)   r   r=   r/   r{   zOptional[dict]r—   rú   r˜   rú   r   rú   rŸ   z2Optional[Callable[[CrossResult], Awaitable[None]]]r�   rü   r    úOptional[CrossResult]rb   r<   )
r—   rú   r˜   rú   r   rú   r    rý   rb   r<   )r–   rº   rb   r   )rb   rB   )r~   r<   rÛ   rB   rÅ   rD   rb   r/   )r~   r<   rØ   rB   rb   rB   ):r6   Ú
__future__r   ry   ÚloggingÚdataclassesr   r   Útypingr   r   r   r	   Útelethonr
   r   Úbuttons_syncr   r   Ú	postlinksr   r   Úreplace_enginer   r   r   r   Úrestrictionsr   r   Útgutilr   r   r   r   r   r   r   r   Ú	getLoggerr3   rŽ   ÚPAUSEr�   r!   r<   ro   r…   r�   r¶   rÀ   rÆ   rÏ   rÔ   rÖ   rÚ   rò   rù   r8   r9   r:   Ú<module>r
     sã  ðñõ" #ã Û ß (ß 5Ó 5ç "ç 2ß 0ß MÓ Mß <ß d× dÓ dà€g×Ñ˜Ó!€à€Ø€ð ÷"ð "ó ð"ð$ ÷%{ð %{ó ð%{óP=ð Øð Ø#,ð Ø58ð Ø@Cð ØVZð Øamð àð à5ð àD`ð ð 
ó ðF1Ø#ð1Ø,5ð1Ø<Hð1àð1à %ð1à-Jð1àYuð1ð 
ó1ðt !ØØØØCGØ04Ø$(ñIð ðIð ð	Ið ðIð ðIð ðIð ðIð AðIð .ðIð "ðIð óIð\ ,/ÀcÐZ_Ø˜tÀTñØ#(ðØ>CðØRWðà-Bðð óð$ ,/ÀcÐZ_Ø˜tÀTñØ#(ðØ>CðØRWðà-Bðð óóð 47ÈcÐbgØ˜tÀTñØ+0ðØFKðØZ_ðà-Bðð óð& 47ÈcÐbgØ˜tÀTñØ+0ðØFKðØZ_ðà-Bðð óó(Jð 3CÐQVõ )ðX 5Wö Ur9   