Ë
    £| k   ã                  óö   — d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZ d	Zd
ZdZdZ ej&                  d«      Zdd„Zdd„Zdd„Zdd„Zddœdd„Zddddddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zy) uµ  The channel chooser used by every command that needs one of the connected channels.

The names are written out in the message as a numbered list (A to Z, 20 to a page); the buttons only carry the numbers
(5 to a row), and â—€ â–¶ underneath move to the previous / next 20. Pressing "3" means the third name of the list.
Each button carries the channel's id, never its position, so a list that changed meanwhile can't pick the wrong one.
é    )ÚannotationsN)ÚCounter)ÚCallableÚOptionalÚSequence)ÚButtoné   )ÚescÚshorté   é   é<   Úcpgz(\d+)c                ó®   — t         j                  dj                  | xs dj                  «       «      j                  «       «      }t	        d„ |D «       «      S )zSA to Z, numbers by value ("Anime 2" before "Anime 10"), upper and lower case alike.Ú Ú c              3  ón   K  — | ]-  }|d k7  sŒ	|j                  «       rdt        |«      d fndd|f–— Œ/ y­w)r   r   r	   N)ÚisdigitÚint)Ú.0Úps     ú/app/app/picker.pyÚ	<genexpr>znatural_key.<locals>.<genexpr>   s7   è ø€ ÐYÉÀ1ÐQRÐVXÓQX A§I¡I¤K�!”S˜“V˜R‘°a¸¸A°YÓ>Éùs   ‚
5�(5)Ú_DIGITSÚsplitÚjoinÚcasefoldÚtuple)ÚtitleÚpartss     r   Únatural_keyr!      s@   € ä�M‰M˜#Ÿ(™( E¢K¨R×#6Ñ#6Ó#8Ó9×BÑBÓDÓE€EÜÑYÉÓYÓYÐYó    c                ó   — t        | d„ ¬«      S )zSThe channels in the order they are listed: by name, ascending (the id breaks ties).c                óD   — t        | j                  «      | j                  fS )N)r!   r   Úid)Úcs    r   Ú<lambda>zordered.<locals>.<lambda>!   s   € ¬°A·G±GÓ(<¸a¿d¹dÑ'Cr"   )Úkey)Úsorted)Úchanss    r   Úorderedr+      s   € ä�%ÑCÔDÐDr"   c                ó,   — t        d|  t        z   «      S )Nr	   )ÚmaxÚPER_PAGE)Útotals    r   Ú
page_countr0   $   s   € Üˆq�U�FœhÑ&Ð'Ó(Ð(r"   c           	     óX   — t        dt        t        | «      t        |«      dz
  «      «      S )Nr   r	   )r-   Úminr   r0   )Úpager/   s     r   Úclampr4   (   s$   € Üˆq”#”c˜$“i¤¨EÓ!2°QÑ!6Ó7Ó8Ð8r"   F©Úwith_usernamec               óú  — | D �cg c]=  }dj                  |j                  xs dj                  «       «      j                  «       ‘Œ? }}t	        |«      }g }t        | |«      D ]‘  \  }}t        |j                  xs dt        «      xs d}|r |j                  r|d|j                  › d�z  }n7||   dkD  r/||j                  rd|j                  › d�nd|j                  › d�z  }|j                  |«       Œ“ |S c c}w )zcDisplay names (not yet escaped). Two channels with the same name get their @username (or id) added.r   r   ÚChannelz (@Ú)r	   z ()r   r   r   r   r   Úzipr   ÚNAME_MAXÚusernamer%   Úappend)r*   r6   r&   ÚkeysÚtwinsÚoutr(   Únames           r   Únames_ofrB   ,   sä   € áBGÓHÁ%¸QˆC�H‰H�a—g‘g’m ×*Ñ*Ó,Ó-×6Ñ6Õ8À%€DÐHÜ�D‹M€EØ
€CÜ�e˜TÖ"‰ˆˆ3Ü�Q—W‘W’] ¤HÓ-Ò:°ˆÙ˜QŸZšZØ�c˜!Ÿ*™*˜ QÐ'Ñ'‰DØ�3‰Z˜!Š^Ø¨1¯:ª:�c˜!Ÿ*™*˜ QÑ'¸RÀÇÁ¸vÀQ¸<ÑGˆDØ�
‰
�4Õð #ð €Jùò Is   …AC8r   © zTap the number of the channel.)ÚargÚchooseÚ
extra_rowsr6   Úhintc               óè  — t        | «      } t        | «      }	t        |	«      }
t        ||	«      }|t        z  }| ||t        z    }t        | |¬«      ||t        z    }t        |d«      D ��cg c]  \  }}||z   › dt        |«      › �‘Œ }}}|› d�dj                  |«      z   }|
dkD  r&|d|dz   › d|
› d|dz   › d	|t        |«      z   › d|	› �
z  }|�
|r|d|› �z  }g }|�yt        |d«      D ��cg c]-  \  }}t        j                  t        ||z   «       ||«      «      ‘Œ/ }}}|t        d
t        |«      t        «      D �cg c]  }|||t        z    ‘Œ c}z  }|
dkD  re|j                  t        j                  dt        › d|› d|› d|dz
  |
z  › �«      t        j                  dt        › d|› d|› d|dz   |
z  › �«      g«       ||D �cg c]  }t!        |«      ‘Œ c}z  }||fS c c}}w c c}}w c c}w c c}w )u¸  (text, button rows) of one page.

    head       the question, already HTML
    kind, arg  which screen this is - the â—€ â–¶ buttons carry them so the same screen can be drawn again
    choose     channel -> callback data of its number button (None: a list to read, no number buttons)
    extra_rows buttons under the arrows (Cancel ...)
    hint       the line under the list that says what the number buttons do (None: leave it out)
    r5   r	   z. z

Ú
z

Page z of z - channels z to r   u   â—€Ú:u   â–¶)r+   Úlenr0   r4   r.   rB   Ú	enumerater
   r   r   ÚinlineÚstrÚrangeÚPER_ROWr=   ÚPAGE_CBÚlist)r*   r3   ÚheadÚkindrD   rE   rF   r6   rG   r/   ÚpagesÚfirstÚshownÚnamesÚirA   ÚlinesÚtextÚrowsr&   ÚnumsÚrs                         r   Úrenderr_   ;   s5  € ô( �E‹N€EÜ�‹J€EÜ�uÓ€EÜ��uÓ€DØ”8‰O€EØ�%˜%¤(Ñ*Ð+€EÜ�U¨-Ô8¸ÀÌÑAQÐR€EÜ8AÀ%ÈÔ8KÔLÑ8K©W¨Q°�˜‘	ˆ{˜"œS ›Y˜KÒ(Ð8K€EÑLØˆV�4ˆ=˜4Ÿ9™9 UÓ+Ñ+€DØˆq‚yØ�)˜D 1™H˜: T¨%¨°¸UÀQ¹Y¸KÀtÈEÔTWÐX]ÓT^ÑL^ÐK_Ð_cÐdiÐcjÐkÑkˆØÐ™dØ�$�t�f�ÑˆØ€DØÐÜENÈuÐVWÔEXÔYÑEX¹T¸QÀ”—‘œc %¨!¡)›n©f°Q«iÕ8ÐEXˆÑYØ´°a¼¸T»ÄGÔ0LÓMÑ0L¨1��a˜!œg™+Ò&Ð0LÑMÑMˆØˆq‚yØ�‰ä—‘˜e¬ y°°$°°q¸¸¸QÀÀqÁÈEÑ?QÐ>RÐ%SÓTÜ—‘˜e¬ y°°$°°q¸¸¸QÀÀqÁÈEÑ?QÐ>RÐ%SÓTðô	
ð 	™jÓ)™j˜ŒT�!�W˜jÑ)Ñ)€DØ�ˆ:Ðùó% Mùó ZùÚMùò *s   Á)GÃ*2G$Ä<G*ÇG/)r   úOptional[str]Úreturnr   )r*   r   ra   rR   )r/   r   ra   r   )r3   r   r/   r   ra   r   )r*   r   r6   Úboolra   rR   )r*   r   r3   r   rS   rN   rT   rN   rD   rN   rE   zOptional[Callable]rF   r   r6   rb   rG   r`   ra   r   )Ú__doc__Ú
__future__r   ÚreÚcollectionsr   Útypingr   r   r   Útelethonr   Útgutilr
   r   r.   rP   r;   rQ   Úcompiler   r!   r+   r0   r4   rB   r_   rC   r"   r   Ú<module>rk      sÛ   ðñõ #ã 	Ý ß /Ñ /å ç à€Ø
€Ø€Ø
€à
ˆ"�*‰*�XÓ
€óZóEó
)ó9ð 8=õ ð* Ø!%ØØØ:ñ-Øð-à
ð-ð ð	-ð
 ð-ð 
ð-ð ð-ð ð-ð ð-ð ð-ð ô-r"   