§
    «eîi�Y  ã                  óà  — d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlT dd	lmZmZmZmZmZ dd
lmZ ddlmZmZmZmZmZmZmZmZ er4ddlm Z  ddlm!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl	m(Z(  G d„ de(d¬¦  «        Z)dZ* ej+        e,¦  «        Z- G d„ d¦  «        Z. G d„ d¦  «        Z/ G d„ d¦  «        Z0 G d„ d¦  «        Z1 G d„ d ¦  «        Z2 G d!„ d"e
¦  «        Z3dS )#a:  
The MIT License (MIT)

Copyright (c) 2015-present Rapptz

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
é    )ÚannotationsNé   )ÚAutoShardedConnectionState)ÚClient)ÚExponentialBackoff)Ú*)ÚClientExceptionÚHTTPExceptionÚGatewayNotFoundÚConnectionClosedÚPrivilegedIntentsRequired)ÚStatus)ÚTYPE_CHECKINGÚAnyÚCallableÚTupleÚTypeÚOptionalÚListÚDict)ÚUnpack)ÚDiscordWebSocket)ÚBaseActivity)ÚIntents)ÚSessionStartLimit)Ú_ClientOptionsc                  ó$   — e Zd ZU ded<   ded<   dS )Ú_AutoShardedClientOptionsz	List[int]Ú	shard_idszOptional[float]Úshard_connect_timeoutN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© ó    úQ/home/div/.hermes/hermes-agent/venv/lib/python3.11/site-packages/discord/shard.pyr   r   9   s*   € € € € € € ØÐÐÑØ.Ð.Ð.Ñ.Ð.Ð.r&   r   F)Útotal)ÚAutoShardedClientÚ	ShardInfoÚSessionStartLimitsc                  ó&   — e Zd ZdZdZdZdZdZdZdS )Ú	EventTyper   r   é   é   é   é   N)	r!   r"   r#   ÚcloseÚ	reconnectÚresumeÚidentifyÚ	terminateÚclean_closer%   r&   r'   r-   r-   G   s,   € € € € € Ø€EØ€IØ€FØ€HØ€IØ€K€K€Kr&   r-   c                  ó2   — e Zd ZdZdd
„Zdd„Zdd„Zdd„ZdS )Ú	EventItem©ÚtypeÚshardÚerrorÚetypeÚintr<   úOptional['Shard']r=   úOptional[Exception]ÚreturnÚNonec                ó0   — || _         || _        || _        d S ©Nr:   )Úselfr>   r<   r=   s       r'   Ú__init__zEventItem.__init__S   s   € ØˆŒ	Ø(-ˆŒ
Ø*/ˆŒ
ˆ
ˆ
r&   ÚotherÚobjectÚboolc                óZ   — t          |t          ¦  «        st          S | j        |j        k     S rE   ©Ú
isinstancer9   ÚNotImplementedr;   ©rF   rH   s     r'   Ú__lt__zEventItem.__lt__X   s)   € Ý˜%¥Ñ+Ô+ð 	"Ý!Ð!ØŒy˜5œ:Ò%Ð%r&   c                óZ   — t          |t          ¦  «        st          S | j        |j        k    S rE   rL   rO   s     r'   Ú__eq__zEventItem.__eq__]   s)   € Ý˜%¥Ñ+Ô+ð 	"Ý!Ð!ØŒy˜EœJÒ&Ð&r&   c                ó*   — t          | j        ¦  «        S rE   )Úhashr;   ©rF   s    r'   Ú__hash__zEventItem.__hash__b   s   € Ý�D”I‰ŒÐr&   N)r>   r?   r<   r@   r=   rA   rB   rC   )rH   rI   rB   rJ   ©rB   r?   )r!   r"   r#   Ú	__slots__rG   rP   rR   rV   r%   r&   r'   r9   r9   P   si   € € € € € Ø*€Ið0ð 0ð 0ð 0ð
&ð &ð &ð &ð
'ð 'ð 'ð 'ð
ð ð ð ð ð r&   r9   c                  ón   — e Zd Zdd	„Zedd„¦   «         Zdd„Zdd„Zdd„Zdd„Z	dd„Z
dd„Zdd„Zdd„ZdS )ÚShardÚwsr   Úclientr)   Ú	queue_putúCallable[[EventItem], None]rB   rC   c                ó  — || _         || _        |j        | _        || _        d| _        |j        | _        t          ¦   «         | _        d | _	        t          t          t          t          t          j        t           j        f| _        d S )NF)r[   Ú_clientÚdispatchÚ	_dispatchÚ
_queue_putÚ_disconnectÚ
_reconnectr   Ú_backoffÚ_taskÚOSErrorr
   r   r   ÚaiohttpÚClientErrorÚasyncioÚTimeoutErrorÚ_handled_exceptions)rF   r[   r\   r]   s       r'   rG   zShard.__init__g   so   € Ø$&ˆŒØ%ˆŒØ.4¬oˆŒØ7@ˆŒØ!&ˆÔØ Ô+ˆŒÝ,>Ñ,@Ô,@ˆŒØ-1ˆŒ
åÝÝÝÝÔÝÔ ðA
ˆÔ Ð Ð r&   r?   c                ó   — | j         j        S rE   )r[   Úshard_idrU   s    r'   ÚidzShard.idy   s   € ð ŒwÔÐr&   c                ór   — | j         j                             |                      ¦   «         ¦  «        | _        d S rE   )r`   ÚloopÚcreate_taskÚworkerrg   rU   s    r'   ÚlaunchzShard.launch~   s(   € Ø”\Ô&×2Ò2°4·;²;±=´=ÑAÔAˆŒ
ˆ
ˆ
r&   c                ó€   — | j         �4| j                              ¦   «         s| j                              ¦   «          d S d S d S rE   )rg   ÚdoneÚcancelrU   s    r'   Ú_cancel_taskzShard._cancel_task�   sC   € ØŒ:Ð!¨$¬*¯/ª/Ñ*;Ô*;Ð!ØŒJ×ÒÑÔÐÐÐð "Ð!Ð!Ð!r&   c              ƒ  ót   K  — |                       ¦   «          | j                             d¬¦  «        ƒ d {V —† d S )Néè  )Úcode)ry   r[   r2   rU   s    r'   r2   zShard.close…   sF   è è € Ø×ÒÑÔÐØŒg�mŠm ˆmÑ&Ô&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&r&   c              ƒ  ót   K  — |                       ¦   «         ƒ d {V —† |                      d| j        ¦  «         d S )NÚshard_disconnect)r2   rb   rp   rU   s    r'   Ú
disconnectzShard.disconnect‰   sC   è è € Ø�jŠj‰lŒlÐÐÐÐÐÐÐØ�ŠÐ)¨4¬7Ñ3Ô3Ð3Ð3Ð3r&   ÚeÚ	Exceptionc           	   ƒ  ó  K  — |                       d¦  «         |                       d| j        ¦  «         | j        s0|                      t	          t
          j        | |¦  «        ¦  «         d S | j                             ¦   «         rd S t          |t          ¦  «        rO|j        dv rFt          | j        d¬¦  «        }|                      t	          t
          j        | |¦  «        ¦  «         d S t          |t          ¦  «        rˆ|j        dk    rB|                      t	          t
          j        | t#          | j        ¦  «        ¦  «        ¦  «         d S |j        dk    r0|                      t	          t
          j        | |¦  «        ¦  «         d S | j                             ¦   «         }t(                               d| j        ||¬	¦  «         t-          j        |¦  «        ƒ d {V —† |                      t	          t
          j        | |¦  «        ¦  «         d S )
Nr   r~   )é6   iF'  T)r4   é®  r{   z/Attempting a reconnect for shard ID %s in %.2fs)Úexc_info)rb   rp   re   rc   r9   r-   r2   r`   Ú	is_closedrM   rh   ÚerrnoÚReconnectWebSocketr4   r   r|   r6   r   rf   ÚdelayÚ_logr=   rk   Úsleepr3   )rF   r€   ÚexcÚretrys       r'   Ú_handle_disconnectzShard._handle_disconnect�   sÌ  è è € Ø�Š�|Ñ$Ô$Ð$Ø�ŠÐ)¨4¬7Ñ3Ô3Ð3ØŒð 	Ø�OŠO�I¥i¤o°t¸QÑ?Ô?Ñ@Ô@Ð@ØˆFàŒ<×!Ò!Ñ#Ô#ð 	ØˆFå�a�Ñ!Ô!ð 	 a¤g°Ð&<Ð&<å$ T¤W°TÐ:Ñ:Ô:ˆCØ�OŠO�I¥iÔ&6¸¸cÑBÔBÑCÔCÐCØˆFå�aÕ)Ñ*Ô*ð 	ØŒv˜Š~ˆ~Ø—’¥	­)Ô*=¸tÕE^Ð_cÔ_fÑEgÔEgÑ hÔ hÑiÔiÐiØ�ØŒv˜Š~ˆ~Ø—’¥	­)¬/¸4ÀÑ CÔ CÑDÔDÐDØ�à”×#Ò#Ñ%Ô%ˆÝ�
Š
ÐDÀdÄgÈuÐ_`ˆ
ÑaÔaÐaÝŒm˜EÑ"Ô"Ð"Ð"Ð"Ð"Ð"Ð"Ð"Ø�Š�	¥)Ô"5°t¸QÑ?Ô?Ñ@Ô@Ð@Ð@Ð@r&   c              ƒ  ón  K  — | j                              ¦   «         �s	 | j                             ¦   «         ƒ d {V —† nÛ# t          $ rN}|j        rt          j        nt          j        }|                      t          || |¦  «        ¦  «         Y d }~d S d }~w| j
        $ r&}|                      |¦  «        ƒ d {V —† Y d }~d S d }~wt          j        $ r Y d S t          $ r9}|                      t          t          j        | |¦  «        ¦  «         Y d }~d S d }~ww xY w| j                              ¦   «         �¯d S d S rE   )r`   r†   r[   Ú
poll_eventrˆ   r4   r-   r5   rc   r9   rm   rŽ   rk   ÚCancelledErrorr�   r6   )rF   r€   r>   s      r'   rt   zShard.workerª   sƒ  è è € Ø”,×(Ò(Ñ*Ô*ñ 	ðØ”g×(Ò(Ñ*Ô*Ð*Ð*Ð*Ð*Ð*Ð*Ð*Ð*øÝ%ð ð ð Ø,-¬HÐL�	Ô(Ð(½)Ô:L�Ø—’¥	¨%°°qÑ 9Ô 9Ñ:Ô:Ð:Ø�����øøøøØÔ+ð ð ð Ø×-Ò-¨aÑ0Ô0Ð0Ð0Ð0Ð0Ð0Ð0Ð0Ø�����øøøøÝÔ)ð ð ð Ø��Ýð ð ð Ø—’¥	­)Ô*=¸tÀQÑ GÔ GÑHÔHÐHØ�����øøøøðøøøð ”,×(Ò(Ñ*Ô*ñ 	ð 	ð 	ð 	ð 	s4   ž> ¾
DÁABÂDÂB?Â?DÃ	DÃ.DÄDrŒ   rˆ   c              ƒ  óø  K  — |                       ¦   «          |                      d¦  «         |                      d| j        ¦  «         t                               d|j        | j        ¦  «         	 t          j        | j        |j	        |j	        sd n| j
        j        | j        | j
        j        | j
        j        ¬¦  «        }t          j        |d¬¦  «        ƒ d {V —†| _
        |                      ¦   «          d S # | j        $ r&}|                      |¦  «        ƒ d {V —† Y d }~d S d }~wt&          $ rz}t                               d|j        |j        | j        ¦  «         |j	        rt(          j	        nt(          j        }|                      t/          || |¦  «        ¦  «         Y d }~d S d }~wt          j        $ r Y d S t2          $ r9}|                      t/          t(          j        | |¦  «        ¦  «         Y d }~d S d }~ww xY w)Nr   r~   z1Got a request to %s the websocket at Shard ID %s.)r4   Úgatewayro   ÚsessionÚsequenceç      N@©Útimeoutz:Somehow got a signal to %s while trying to %s shard ID %s.)ry   rb   rp   rŠ   ÚdebugÚopr   Úfrom_clientr`   r4   r[   r“   Ú
session_idr•   rk   Úwait_forru   rm   rŽ   rˆ   r-   r5   rc   r9   r‘   r�   r6   )rF   rŒ   Úcoror€   rš   s        r'   Ú
reidentifyzShard.reidentify»   s0  è è € Ø×ÒÑÔÐØ�Š�|Ñ$Ô$Ð$Ø�ŠÐ)¨4¬7Ñ3Ô3Ð3Ý�
Š
ÐFÈÌÐPTÔPWÑXÔXÐXð	Ý#Ô/Ø”Ø”zØ$'¤JÐC˜˜°D´G´OØœØœÔ*ØœÔ)ðñ ô ˆDõ $Ô,¨T¸4Ð@Ñ@Ô@Ð@Ð@Ð@Ð@Ð@Ð@ˆDŒGð �KŠK‰MŒMˆMˆMˆMøð Ô'ð 	-ð 	-ð 	-Ø×)Ò)¨!Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,øøøøÝ!ð 	4ð 	4ð 	4Ý�JŠJÐSÐUVÔUYÐ[^Ô[aÐcgÔcjÑkÔkÐkØ%&¤XÐE•Ô!Ð!µ9Ô3EˆBØ�OŠO�I b¨$°Ñ2Ô2Ñ3Ô3Ð3Ð3Ð3Ð3Ð3Ð3Ð3øøøøÝÔ%ð 	ð 	ð 	ØˆFˆFÝð 	Eð 	Eð 	EØ�OŠO�I¥iÔ&9¸4ÀÑCÔCÑDÔDÐDÐDÐDÐDÐDÐDÐDøøøøð	Eøøøs8   Á.A1C5 Ã5
G9Ã?D Ä G9Ä-A/F"Æ"G9Æ7	G9Ç .G4Ç4G9c              ƒ  óè  K  — |                       ¦   «          	 t          j        | j        | j        ¬¦  «        }t          j        |d¬¦  «        ƒ d {V —†| _        |                      ¦   «          d S # | j	        $ r&}|  
                    |¦  «        ƒ d {V —† Y d }~d S d }~wt
          j        $ r Y d S t          $ r9}|                      t          t          j        | |¦  «        ¦  «         Y d }~d S d }~ww xY w)N©ro   r–   r—   )ry   r   r›   r`   rp   rk   r�   r[   ru   rm   rŽ   r‘   r�   rc   r9   r-   r6   )rF   rž   r€   s      r'   r3   zShard.reconnect×   s7  è è € Ø×ÒÑÔÐð
	Ý#Ô/°´ÀtÄwÐOÑOÔOˆDÝ#Ô,¨T¸4Ð@Ñ@Ô@Ð@Ð@Ð@Ð@Ð@Ð@ˆDŒGð �KŠK‰MŒMˆMˆMˆMøð Ô'ð 	-ð 	-ð 	-Ø×)Ò)¨!Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,øøøøÝÔ%ð 	ð 	ð 	ØˆFˆFÝð 	Eð 	Eð 	EØ�OŠO�I¥iÔ&9¸4ÀÑCÔCÑDÔDÐDÐDÐDÐDÐDÐDÐDøøøøð	Eøøøs*   ˜AA/ Á/
C1Á9BÂC1Â/	C1Â8.C,Ã,C1N)r[   r   r\   r)   r]   r^   rB   rC   rW   ©rB   rC   )r€   r�   rB   rC   )rŒ   rˆ   rB   rC   )r!   r"   r#   rG   Úpropertyrp   ru   ry   r2   r   rŽ   rt   rŸ   r3   r%   r&   r'   rZ   rZ   f   sð   € € € € € ð
ð 
ð 
ð 
ð$ ð ð  ð  ñ „Xð ðBð Bð Bð Bð ð  ð  ð  ð'ð 'ð 'ð 'ð4ð 4ð 4ð 4ðAð Að Að Að:ð ð ð ð"ð ð ð ð8ð ð ð ð ð r&   rZ   c                  ó^   — e Zd ZdZdZdd	„Zdd„Zdd„Zdd„Zdd„Z	e
dd„¦   «         Zdd„ZdS )r*   a·  A class that gives information and control over a specific shard.

    You can retrieve this object via :meth:`AutoShardedClient.get_shard`
    or :attr:`AutoShardedClient.shards`.

    .. versionadded:: 1.4

    Attributes
    ------------
    id: :class:`int`
        The shard ID for this shard.
    shard_count: Optional[:class:`int`]
        The shard count for this cluster. If this is ``None`` then the bot has not started yet.
    ©Ú_parentrp   Úshard_countÚparentrZ   r§   úOptional[int]rB   rC   c                ó:   — || _         |j        | _        || _        d S rE   r¥   )rF   r¨   r§   s      r'   rG   zShardInfo.__init__ø   s    € Ø$ˆŒØ”yˆŒØ*5ˆÔÐÐr&   rJ   c                ó&   — | j         j        j         S )z@:class:`bool`: Whether the shard connection is currently closed.)r¦   r[   ÚopenrU   s    r'   r†   zShardInfo.is_closedý   s   € à”<”?Ô'Ð'Ð'r&   c              ƒ  ót   K  — |                       ¦   «         rdS | j                             ¦   «         ƒ d{V —† dS )z¸|coro|

        Disconnects a shard. When this is called, the shard connection will no
        longer be open.

        If the shard is already disconnected this does nothing.
        N)r†   r¦   r   rU   s    r'   r   zShardInfo.disconnect  sK   è è € ð �>Š>ÑÔð 	ØˆFàŒl×%Ò%Ñ'Ô'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'Ð'r&   c              ƒ  ó®   K  — |                       ¦   «         s| j                             ¦   «         ƒ d{V —† | j                             ¦   «         ƒ d{V —† dS )zG|coro|

        Disconnects and then connects the shard again.
        N)r†   r¦   r   r3   rU   s    r'   r3   zShardInfo.reconnect  sl   è è € ð
 �~Š~ÑÔð 	,Ø”,×)Ò)Ñ+Ô+Ð+Ð+Ð+Ð+Ð+Ð+Ð+ØŒl×$Ò$Ñ&Ô&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&r&   c              ƒ  ót   K  — |                       ¦   «         sdS | j                             ¦   «         ƒ d{V —† dS )z_|coro|

        Connects a shard. If the shard is already connected this does nothing.
        N)r†   r¦   r3   rU   s    r'   ÚconnectzShardInfo.connect  sK   è è € ð
 �~Š~ÑÔð 	ØˆFàŒl×$Ò$Ñ&Ô&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&Ð&r&   Úfloatc                ó$   — | j         j        j        S )zc:class:`float`: Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds for this shard.)r¦   r[   ÚlatencyrU   s    r'   r³   zShardInfo.latency!  s   € ð Œ|ŒÔ&Ð&r&   c                ó>   — | j         j                             ¦   «         S )zá:class:`bool`: Whether the websocket is currently rate limited.

        This can be useful to know when deciding whether you should query members
        using HTTP or via the gateway.

        .. versionadded:: 1.6
        )r¦   r[   Úis_ratelimitedrU   s    r'   Úis_ws_ratelimitedzShardInfo.is_ws_ratelimited&  s   € ð Œ|Œ×-Ò-Ñ/Ô/Ð/r&   N)r¨   rZ   r§   r©   rB   rC   ©rB   rJ   r¢   ©rB   r±   )r!   r"   r#   Ú__doc__rX   rG   r†   r   r3   r°   r£   r³   r¶   r%   r&   r'   r*   r*   æ   s½   € € € € € ðð ð 1€Ið6ð 6ð 6ð 6ð
(ð (ð (ð (ð(ð (ð (ð (ð'ð 'ð 'ð 'ð'ð 'ð 'ð 'ð ð'ð 'ð 'ñ „Xð'ð0ð 0ð 0ð 0ð 0ð 0r&   r*   c                  ó   — e Zd ZdZdZdd„ZdS )r+   aõ  A class that holds info about session start limits

    .. versionadded:: 2.5

    Attributes
    ----------
    total: :class:`int`
        The total number of session starts the current user is allowed
    remaining: :class:`int`
        Remaining remaining number of session starts the current user is allowed
    reset_after: :class:`int`
        The number of milliseconds until the limit resets
    max_concurrency: :class:`int`
        The number of identify requests allowed per 5 seconds
    ©r(   Ú	remainingÚreset_afterÚmax_concurrencyÚkwargsúUnpack[SessionStartLimit]c                ón   — |d         | _         |d         | _        |d         | _        |d         | _        d S )Nr(   r¼   r½   r¾   r»   )rF   r¿   s     r'   rG   zSessionStartLimits.__init__D  s:   € Ø  œ/ˆŒ
Ø$ [Ô1ˆŒØ & }Ô 5ˆÔØ$*Ð+<Ô$=ˆÔÐÐr&   N)r¿   rÀ   )r!   r"   r#   r¹   rX   rG   r%   r&   r'   r+   r+   1  s:   € € € € € ðð ð  I€Ið>ð >ð >ð >ð >ð >r&   r+   c                  óö   ‡ — e Zd ZU dZerded<   d6ˆ fd„Zd7ddœd8d„Zd9d„Ze	d:d„¦   «         Z
e	d;d„¦   «         Zd<d„Ze	d=d„¦   «         Zd>d „Zd!d"œd?d'„Zd@d(„Zd@ˆ fd)„Zd*d+œdAd-„Zd@d.„Zdddd/œdBd4„ZdCd5„Zˆ xZS )Dr)   aÑ  A client similar to :class:`Client` except it handles the complications
    of sharding for the user into a more manageable and transparent single
    process bot.

    When using this client, you will be able to use it as-if it was a regular
    :class:`Client` with a single shard when implementation wise internally it
    is split up into multiple shards. This allows you to not have to deal with
    IPC or other complicated infrastructure.

    It is recommended to use this client only if you have surpassed at least
    1000 guilds.

    If no :attr:`.shard_count` is provided, then the library will use the
    Bot Gateway endpoint call to figure out how many shards to use.

    If a ``shard_ids`` parameter is given, then those shard IDs will be used
    to launch the internal shards. Note that :attr:`.shard_count` must be provided
    if this is used. By default, when omitted, the client will launch shards from
    0 to ``shard_count - 1``.

    .. container:: operations

        .. describe:: async with x

            Asynchronously initialises the client and automatically cleans up.

            .. versionadded:: 2.0

    Attributes
    ------------
    shard_ids: Optional[List[:class:`int`]]
        An optional list of shard_ids to launch the shards with.
    shard_connect_timeout: Optional[:class:`float`]
        The maximum number of seconds to wait before timing out when launching a shard.
        Defaults to 180 seconds.

        .. versionadded:: 2.4
    r   Ú_connectionÚargsr   Úintentsr   r¿   ú!Unpack[_AutoShardedClientOptions]rB   rC   c               óÀ  •‡ — |                      dd ¦  «         |                      dd ¦  «        ‰ _        |                      dd¦  «        ‰ _         t          ¦   «         j        |d|i|¤Ž ‰ j        �F‰ j        €t          d¦  «        ‚t          ‰ j        t          t          f¦  «        st          d¦  «        ‚i ‰ _
        ‰ j        ‰ j        _        ˆ fd„‰ j        _        d S )	Nro   r   r    g     €f@rÅ   z>When passing manual shard_ids, you must provide a shard_count.z.shard_ids parameter must be a list or a tuple.c                 ó   •— ‰ S rE   r%   rU   s   €r'   ú<lambda>z,AutoShardedClient.__init__.<locals>.<lambda>‡  s   ø€ ¨t€ r&   )Úpopr   r    ÚsuperrG   r§   r	   rM   ÚlistÚtupleÚ_AutoShardedClient__shardsÚ_get_websocketrÃ   Ú_get_client)rF   rÅ   rÄ   r¿   Ú	__class__s   `   €r'   rG   zAutoShardedClient.__init__v  sÜ   øø€ Ø�
Š
�:˜tÑ$Ô$Ð$Ø.4¯jªj¸ÀdÑ.KÔ.KˆŒØ6<·j²jÐAXÐZ_Ñ6`Ô6`ˆÔ"à�‰ŒÔ˜$Ð:¨Ð:°6Ð:Ð:Ð:àŒ>Ð%ØÔÐ'Ý%Ð&fÑgÔgÐgÝ ¤µµu°Ñ>Ô>ð XÝ%Ð&VÑWÔWÐWð ˆŒØ*.Ô*=ˆÔÔ'Ø'3 | | |ˆÔÔ$Ð$Ð$r&   Nr¡   Úguild_idr©   ro   r   c               óD   — |€|dz	  | j         z  }| j        |         j        S )Né   )r§   rÎ   r[   )rF   rÒ   ro   s      r'   rÏ   z AutoShardedClient._get_websocket‰  s)   € ØÐà  B™¨$Ô*:Ñ:ˆHØŒ}˜XÔ&Ô)Ð)r&   Úoptionsc                óL   — t          d| j        | j        | j        | j        dœ|¤ŽS )N)ra   ÚhandlersÚhooksÚhttpr%   )r   ra   Ú	_handlersÚ_hooksrÙ   )rF   rÕ   s     r'   Ú
_get_statezAutoShardedClient._get_state�  s<   € Ý)ð 
Ø”]Ø”^Ø”+Ø”ð	
ð 
ð
 ð
ð 
ð 	
r&   r±   c                ó”   — | j         st          d¦  «        S t          d„ | j        D ¦   «         ¦  «        t	          | j         ¦  «        z  S )aY  :class:`float`: Measures latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds.

        This operates similarly to :meth:`Client.latency` except it uses the average
        latency of every shard's latency. To get a list of shard latency, check the
        :attr:`latencies` property. Returns ``nan`` if there are no shards ready.
        Únanc              3  ó    K  — | ]	\  }}|V — Œ
d S rE   r%   )Ú.0Ú_r³   s      r'   ú	<genexpr>z,AutoShardedClient.latency.<locals>.<genexpr>¢  s&   è è € Ð<Ð<™z˜q '�7Ð<Ð<Ð<Ð<Ð<Ð<r&   )rÎ   r±   ÚsumÚ	latenciesÚlenrU   s    r'   r³   zAutoShardedClient.latency˜  sH   € ð Œ}ð 	 Ý˜‘<”<ÐÝÐ<Ð<¨T¬^Ð<Ñ<Ô<Ñ<Ô<½sÀ4Ä=Ñ?QÔ?QÑQÐQr&   úList[Tuple[int, float]]c                óH   — d„ | j                              ¦   «         D ¦   «         S )zÉList[Tuple[:class:`int`, :class:`float`]]: A list of latencies between a HEARTBEAT and a HEARTBEAT_ACK in seconds.

        This returns a list of tuples with elements ``(shard_id, latency)``.
        c                ó0   — g | ]\  }}||j         j        f‘ŒS r%   )r[   r³   )rà   ro   r<   s      r'   ú
<listcomp>z/AutoShardedClient.latencies.<locals>.<listcomp>ª  s&   € ÐZÐZÐZ±°¸5�˜5œ8Ô+Ð,ÐZÐZÐZr&   ©rÎ   ÚitemsrU   s    r'   rä   zAutoShardedClient.latencies¤  s'   € ð [ÐZÀDÄM×DWÒDWÑDYÔDYÐZÑZÔZÐZr&   r?   úOptional[ShardInfo]c               ój   — 	 | j         |         }t          || j        ¦  «        S # t          $ r Y dS w xY w)aL  
        Gets the shard information at a given shard ID or ``None`` if not found.

        .. versionchanged:: 2.0

            ``shard_id`` parameter is now positional-only.

        Returns
        --------
        Optional[:class:`ShardInfo`]
            Information about the shard with given ID. ``None`` if not found.
        N)rÎ   r*   r§   ÚKeyError)rF   ro   r¨   s      r'   Ú	get_shardzAutoShardedClient.get_shard¬  sL   € ð	7Ø”] 8Ô,ˆFõ ˜V TÔ%5Ñ6Ô6Ð6øõ ð 	ð 	ð 	Ø�4�4ð	øøøs   ‚$ ¤
2±2úDict[int, ShardInfo]c                óN   ‡ — ˆ fd„‰ j                              ¦   «         D ¦   «         S )zaMapping[int, :class:`ShardInfo`]: Returns a mapping of shard IDs to their respective info object.c                óB   •— i | ]\  }}|t          |‰j        ¦  «        “ŒS r%   )r*   r§   )rà   ro   r¨   rF   s      €r'   ú
<dictcomp>z,AutoShardedClient.shards.<locals>.<dictcomp>Ã  s-   ø€ ÐlÐlÐlÑBRÀ(ÈF��) F¨DÔ,<Ñ=Ô=ÐlÐlÐlr&   rê   rU   s   `r'   ÚshardszAutoShardedClient.shardsÀ  s0   ø€ ð mÐlÐlÐlÐVZÔVc×ViÒViÑVkÔVkÐlÑlÔlÐlr&   r+   c              ƒ  ód   K  — | j                              ¦   «         ƒ d{V —†\  }}}t          di |¤ŽS )a�  |coro|

        Get the session start limits.

        This is not typically needed, and will be handled for you by default.

        At the point where you are launching multiple instances
        with manual shard ranges and are considered required to use large bot
        sharding by Discord, this function when used along IPC and a
        before_identity_hook can speed up session start.

        .. versionadded:: 2.5

        Returns
        -------
        :class:`SessionStartLimits`
            A class containing the session start limits

        Raises
        ------
        GatewayNotFound
            The gateway was unreachable
        Nr%   )rÙ   Úget_bot_gatewayr+   )rF   rá   Úlimitss      r'   Úfetch_session_start_limitsz,AutoShardedClient.fetch_session_start_limitsÅ  sG   è è € ð0 "œY×6Ò6Ñ8Ô8Ð8Ð8Ð8Ð8Ð8Ð8‰ˆˆ1ˆfÝ!Ð+Ð+ FÐ+Ð+Ð+r&   F©Úinitialr“   úyarl.URLrú   rJ   c             ƒ  ó´  K  — 	 t          j        | |||¬¦  «        }t          j        || j        ¬¦  «        ƒ d {V —†}na# t
          $ rT t                               d|¦  «         t          j        d¦  «        ƒ d {V —† |  	                    ||¦  «        ƒ d {V —†cY S w xY wt          || | j        j        ¦  «        x| j        |<   }|                     ¦   «          d S )N)rú   r“   ro   r—   z/Failed to connect for shard_id: %s. Retrying...g      @)r   r›   rk   r�   r    r�   rŠ   Ú	exceptionr‹   Úlaunch_shardrZ   Ú_AutoShardedClient__queueÚ
put_nowaitrÎ   ru   )rF   r“   ro   rú   rž   r[   Úrets          r'   rþ   zAutoShardedClient.launch_shardà  s  è è € ð	>Ý#Ô/°¸gÈwÐaiÐjÑjÔjˆDÝÔ'¨°dÔ6PÐQÑQÔQÐQÐQÐQÐQÐQÐQˆBˆBøÝð 	>ð 	>ð 	>Ý�NŠNÐLÈhÑWÔWÐWÝ”- Ñ$Ô$Ð$Ð$Ð$Ð$Ð$Ð$Ð$Ø×*Ò*¨7°HÑ=Ô=Ð=Ð=Ð=Ð=Ð=Ð=Ð=Ð=Ð=ð	>øøøõ ).¨b°$¸¼Ô8OÑ(PÔ(PÐPˆŒ�hÑ #Ø�
Š
‰Œˆˆˆs   „9> ¾ABÂBc              ƒ  ó¨  K  — |                       ¦   «         rd S | j        €?|  | j                             ¦   «         ƒ d {V —†\  | _        }}t	          j        |¦  «        }nt          j        }| j        | j        _        | j	        pt          | j        ¦  «        }|| j        _	        |D ],}||d         k    }|                      |||¬¦  «        ƒ d {V —† Œ-d S )Nr   rù   )r†   r§   rÙ   rö   ÚyarlÚURLr   ÚDEFAULT_GATEWAYrÃ   r   Úrangerþ   )rF   Úgateway_urlÚ_session_start_limitr“   r   ro   rú   s          r'   Úlaunch_shardszAutoShardedClient.launch_shardsí  s   è è € Ø�>Š>ÑÔð 	ØˆFàÔÐ#ØÐ!ØHLÌ	×HaÒHaÑHcÔHcÐBcÐBcÐBcÐBcÐBcÐBcÑ?ˆDÔ˜kÐ+?Ý”h˜{Ñ+Ô+ˆGˆGå&Ô6ˆGà'+Ô'7ˆÔÔ$à”NÐ=¥e¨DÔ,<Ñ&=Ô&=ˆ	Ø%.ˆÔÔ"à!ð 	Hð 	HˆHØ )¨A¤,Ò.ˆGØ×#Ò# G¨X¸wÐ#ÑGÔGÐGÐGÐGÐGÐGÐGÐGÐGð	Hð 	Hr&   c              ƒ  óˆ   •K  — t          ¦   «                              ¦   «         ƒ d {V —† t          j        ¦   «         | _        d S rE   )rË   Ú_async_setup_hookrk   ÚPriorityQueuerÿ   )rF   rÑ   s    €r'   r  z#AutoShardedClient._async_setup_hook  sC   øè è € Ý‰gŒg×'Ò'Ñ)Ô)Ð)Ð)Ð)Ð)Ð)Ð)Ð)ÝÔ,Ñ.Ô.ˆŒˆˆr&   T)r3   r3   c             ƒ  óˆ  K  — || _         |                      ¦   «         ƒ d {V —† |                      ¦   «         �s‰| j                             ¦   «         ƒ d {V —†}|j        t          j        k    rw|                      ¦   «         ƒ d {V —† t          |j	        t          ¦  «        rA|j	        j        dk    rt          |j        j        ¦  «        d ‚|j	        j        dk    r|j	        ‚d S |j        t          j        t          j        fv r&|j                             |j	        ¦  «        ƒ d {V —† n‚|j        t          j        k    r |j                             ¦   «         ƒ d {V —† nM|j        t          j        k    r!|                      ¦   «         ƒ d {V —† |j	        ‚|j        t          j        k    rd S |                      ¦   «         �¯‡d S d S )Nr„   r{   )re   r	  r†   rÿ   Úgetr;   r-   r2   rM   r=   r   r|   r   r<   rp   r5   r4   rŸ   r3   r6   r7   )rF   r3   Úitems      r'   r°   zAutoShardedClient.connect  sÞ  è è € Ø#ˆŒØ× Ò Ñ"Ô"Ð"Ð"Ð"Ð"Ð"Ð"Ð"à—.’.Ñ"Ô"ñ 	Øœ×)Ò)Ñ+Ô+Ð+Ð+Ð+Ð+Ð+Ð+ˆDØŒy�IœOÒ+Ð+Ø—j’j‘l”lÐ"Ð"Ð"Ð"Ð"Ð"Ð"Ý˜dœjÕ*:Ñ;Ô;ð )Ø”z”¨$Ò.Ð.Ý7¸¼
¼ÑFÔFÈDÐPØ”z”¨$Ò.Ð.Ø"œjÐ(Ø�Ø”�yÔ1µ9Ô3CÐDÐDÐDØ”j×+Ò+¨D¬JÑ7Ô7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ð7Ø”�iÔ1Ò1Ð1Ø”j×*Ò*Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ø”�iÔ1Ò1Ð1Ø—j’j‘l”lÐ"Ð"Ð"Ð"Ð"Ð"Ð"Ø”jÐ Ø”�iÔ3Ò3Ð3Ø�ð% —.’.Ñ"Ô"ñ 	ð 	ð 	ð 	ð 	r&   c              ƒ  óš   ‡ K  — ‰ j         r‰ j         ƒ d{V —†S ˆ fd„}t          j         |¦   «         ¦  «        ‰ _         ‰ j         ƒ d{V —† dS )z:|coro|

        Closes the connection to Discord.
        Nc               “  óp  •K  — ‰j                              ¦   «         ƒ d {V —† ˆfd„‰j                             ¦   «         D ¦   «         } | rt	          j        | ¦  «        ƒ d {V —† ‰j                             ¦   «         ƒ d {V —† ‰j                             t          t          j        d d ¦  «        ¦  «         d S )Nc                ój   •— g | ]/}t          j        |                     ¦   «         ‰j        ¬ ¦  «        ‘Œ0S ))rr   )rk   Úensure_futurer2   rr   )rà   r<   rF   s     €r'   ré   z;AutoShardedClient.close.<locals>._close.<locals>.<listcomp>(  s4   ø€ ÐqÐqÐqÐQV�Ô-¨e¯kªk©m¬mÀ$Ä)ÐLÑLÔLÐqÐqÐqr&   )rÃ   r2   rÎ   Úvaluesrk   ÚwaitrÙ   rÿ   r   r9   r-   r7   )Úto_closerF   s    €r'   Ú_closez'AutoShardedClient.close.<locals>._close%  sÐ   øè è € ØÔ"×(Ò(Ñ*Ô*Ð*Ð*Ð*Ð*Ð*Ð*Ð*àqÐqÐqÐqÐZ^ÔZg×ZnÒZnÑZpÔZpÐqÑqÔqˆHØð -Ý”l 8Ñ,Ô,Ð,Ð,Ð,Ð,Ð,Ð,Ð,à”)—/’/Ñ#Ô#Ð#Ð#Ð#Ð#Ð#Ð#Ð#ØŒL×#Ò#¥I­iÔ.CÀTÈ4Ñ$PÔ$PÑQÔQÐQÐQÐQr&   )Ú_closing_taskrk   rs   )rF   r  s   ` r'   r2   zAutoShardedClient.close  s‰   øè è € ð
 Ôð 	,ØÔ+Ð+Ð+Ð+Ð+Ð+Ð+Ð+ð	Rð 	Rð 	Rð 	Rð 	Rõ %Ô0°°±´Ñ:Ô:ˆÔØÔ Ð Ð Ð Ð Ð Ð Ð Ð Ð r&   )ÚactivityÚstatusro   r  úOptional[BaseActivity]r  úOptional[Status]c             ƒ  óú  ‡K  — |€d}t           j        }n.|t           j        u rd}t           j        }n|}t          |¦  «        }‰€K| j                             ¦   «         D ]$}|j                             ||¬¦  «        ƒ d{V —† Œ%| j        j	        }nG| j        ‰         }|j                             ||¬¦  «        ƒ d{V —† ˆfd„| j        j	        D ¦   «         }|€dn|f}|D ]}	|	j
        }
|
€Œ||
_        ||
_        ŒdS )a>  |coro|

        Changes the client's presence.

        Example: ::

            game = discord.Game("with the API")
            await client.change_presence(status=discord.Status.idle, activity=game)

        .. versionchanged:: 2.0
            Removed the ``afk`` keyword-only parameter.

        .. versionchanged:: 2.0
            This function will now raise :exc:`TypeError` instead of
            ``InvalidArgument``.

        Parameters
        ----------
        activity: Optional[:class:`BaseActivity`]
            The activity being done. ``None`` if no currently active activity is done.
        status: Optional[:class:`Status`]
            Indicates what status to change to. If ``None``, then
            :attr:`Status.online` is used.
        shard_id: Optional[:class:`int`]
            The shard_id to change the presence to. If not specified
            or ``None``, then it will change the presence of every
            shard the bot can see.

        Raises
        ------
        TypeError
            If the ``activity`` parameter is not of proper type.
        NÚonlineÚ	invisible)r  r  c                ó*   •— g | ]}|j         ‰k    ¯|‘ŒS r%   r¡   )rà   Úgro   s     €r'   ré   z5AutoShardedClient.change_presence.<locals>.<listcomp>m  s%   ø€ ÐSÐSÐS˜A¸A¼JÈ(Ò<RÐ<R�aÐ<RÐ<RÐ<Rr&   r%   )r   r  ÚofflineÚstrrÎ   r  r[   Úchange_presencerÃ   ÚguildsÚmeÚ
activitiesr  )rF   r  r  ro   Ústatus_valueÚstatus_enumr<   r%  r'  Úguildr&  s      `       r'   r$  z!AutoShardedClient.change_presence2  sL  øè è € ðR ˆ>Ø#ˆLÝ œ-ˆKˆKØ•v”~Ð%Ð%Ø&ˆLÝ œ.ˆKˆKà ˆKÝ˜v™;œ;ˆLàÐØœ×-Ò-Ñ/Ô/ð Wð W�Ø”h×.Ò.¸ÈÐ.ÑVÔVÐVÐVÐVÐVÐVÐVÐVÐVàÔ%Ô,ˆFˆFà”M (Ô+ˆEØ”(×*Ò*°HÀ\Ð*ÑRÔRÐRÐRÐRÐRÐRÐRÐRØSÐSÐSÐS Ô!1Ô!8ÐSÑSÔSˆFà#Ð+�R�R°(°ˆ
Øð 	$ð 	$ˆEØ”ˆBØˆzØð 'ˆBŒMØ#ˆBŒIˆIð	$ð 	$r&   c                ób   — t          d„ | j                             ¦   «         D ¦   «         ¦  «        S )a}  :class:`bool`: Whether the websocket is currently rate limited.

        This can be useful to know when deciding whether you should query members
        using HTTP or via the gateway.

        This implementation checks if any of the shards are rate limited.
        For more granular control, consider :meth:`ShardInfo.is_ws_ratelimited`.

        .. versionadded:: 1.6
        c              3  óH   K  — | ]}|j                              ¦   «         V — Œd S rE   )r[   rµ   )rà   r<   s     r'   râ   z6AutoShardedClient.is_ws_ratelimited.<locals>.<genexpr>„  s0   è è € ÐQÐQ°�5”8×*Ò*Ñ,Ô,ÐQÐQÐQÐQÐQÐQr&   )ÚanyrÎ   r  rU   s    r'   r¶   z#AutoShardedClient.is_ws_ratelimitedy  s/   € õ ÐQÐQ¸$¼-×:NÒ:NÑ:PÔ:PÐQÑQÔQÑQÔQÐQr&   )rÄ   r   rÅ   r   r¿   rÆ   rB   rC   rE   )rÒ   r©   ro   r©   rB   r   )rÕ   r   rB   r   r¸   )rB   ræ   )ro   r?   rB   rì   )rB   rð   )rB   r+   )r“   rû   ro   r?   rú   rJ   rB   rC   r¢   )r3   rJ   rB   rC   )r  r  r  r  ro   r©   rB   rC   r·   )r!   r"   r#   r¹   r   r$   rG   rÏ   rÜ   r£   r³   rä   rï   rô   rø   rþ   r	  r  r°   r2   r$  r¶   Ú__classcell__)rÑ   s   @r'   r)   r)   K  s  ø€ € € € € € ð%ð %ðN ð 0Ø/Ð/Ð/Ñ/ð4ð 4ð 4ð 4ð 4ð 4ð&*ÐZ^ð *ð *ð *ð *ð *ð *ð
ð 
ð 
ð 
ð ð	Rð 	Rð 	Rñ „Xð	Rð ð[ð [ð [ñ „Xð[ð7ð 7ð 7ð 7ð( ðmð mð mñ „Xðmð,ð ,ð ,ð ,ð6 W\ð ð ð ð ð ð ðHð Hð Hð Hð(/ð /ð /ð /ð /ð /ð 26ð ð ð ð ð ð ð0!ð !ð !ð !ð0 ,0Ø#'Ø"&ðE$ð E$ð E$ð E$ð E$ð E$ðNRð Rð Rð Rð Rð Rð Rð Rr&   r)   )4r¹   Ú
__future__r   rk   Úloggingri   r  Ústater   r\   r   Úbackoffr   r“   Úerrorsr	   r
   r   r   r   Úenumsr   Útypingr   r   r   r   r   r   r   r   Útyping_extensionsr   r   r  r   Úflagsr   Útypes.gatewayr   r   r   Ú__all__Ú	getLoggerr!   rŠ   r-   r9   rZ   r*   r+   r)   r%   r&   r'   ú<module>r;     s  ððð ð0 #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€à €€€Ø €€€à -Ð -Ð -Ð -Ð -Ð -Ø Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð Ð Ð Ð Ð Ð à RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Ràð 
/Ø(Ð(Ð(Ð(Ð(Ð(Ø)Ð)Ð)Ð)Ð)Ð)Ø&Ð&Ð&Ð&Ð&Ð&ØÐÐÐÐÐØ0Ð0Ð0Ð0Ð0Ð0Ø&Ð&Ð&Ð&Ð&Ð&ð/ð /ð /ð /ð / N¸%ð /ñ /ô /ð /ð
€ð €wÔ˜Ñ"Ô"€ðð ð ð ð ñ ô ð ðð ð ð ð ñ ô ð ð,}ð }ð }ð }ð }ñ }ô }ð }ð@H0ð H0ð H0ð H0ð H0ñ H0ô H0ð H0ðV>ð >ð >ð >ð >ñ >ô >ð >ð4yRð yRð yRð yRð yR˜ñ yRô yRð yRð yRð yRr&   