
    i%T                       U d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlT ddlmZ dd	lmZmZ dd
lmZ ddlmZmZ erLd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$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddlm+Z+ ddl,m-Z.m/Z0m1Z1 ee*e)f         Z2de3d<   	 ddl4Z5ddl6Z5dZ7n# e8$ r dZ7Y nw xY wdZ9 ej:        e;          Z< G d d          Z= G d de=          Z>d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)AnyCallableListOptionalTYPE_CHECKINGTupleUnion   )opus)*)ClientException)AudioPlayerAudioSource)MISSING)VoiceConnectionStatehas_dave)DiscordVoiceWebSocket)Client)Guild)ConnectionState)
ClientUser)EncoderAPPLICATION_CTLBAND_CTL
SIGNAL_CTL)StageChannelVoiceChannel)abc)GuildVoiceStateVoiceServerUpdateSupportedModesboolhas_naclTF)VoiceProtocolVoiceClientc                  J    e Zd ZdZddZddZddZdddddZddZd dZ	dS )!r%   a  A class that represents the Discord voice protocol.

    This is an abstract class. The library provides a concrete implementation
    under :class:`VoiceClient`.

    This class allows you to implement a protocol to allow for an external
    method of sending voice, such as Lavalink_ or a native library implementation.

    These classes are passed to :meth:`abc.Connectable.connect <VoiceChannel.connect>`.

    .. _Lavalink: https://github.com/freyacodes/Lavalink

    Parameters
    ------------
    client: :class:`Client`
        The client (or its subclasses) that started the connection request.
    channel: :class:`abc.Connectable`
        The voice channel that is being connected to.
    clientr   channelabc.ConnectablereturnNonec                "    || _         || _        d S N)r(   r)   )selfr(   r)   s      U/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/discord/voice_client.py__init__zVoiceProtocol.__init__b   s    $(/    dataGuildVoiceStatePayloadc                  K   t           )a  |coro|

        An abstract method that is called when the client's voice state
        has changed. This corresponds to ``VOICE_STATE_UPDATE``.

        .. warning::

            This method is not the same as the event. See: :func:`on_voice_state_update`

        Parameters
        ------------
        data: :class:`dict`
            The raw :ddocs:`voice state payload <resources/voice#voice-state-object>`.
        NotImplementedErrorr/   r3   s     r0   on_voice_state_updatez#VoiceProtocol.on_voice_state_updatef   s       "!r2   VoiceServerUpdatePayloadc                  K   t           )a>  |coro|

        An abstract method that is called when initially connecting to voice.
        This corresponds to ``VOICE_SERVER_UPDATE``.

        Parameters
        ------------
        data: :class:`dict`
            The raw :ddocs:`voice server update payload <topics/gateway-events#voice-server-update>`.
        r6   r8   s     r0   on_voice_server_updatez$VoiceProtocol.on_voice_server_updatew   s       "!r2   F	self_deaf	self_mutetimeoutfloat	reconnectr#   r>   r?   c                  K   t           )a@  |coro|

        An abstract method called when the client initiates the connection request.

        When a connection is requested initially, the library calls the constructor
        under ``__init__`` and then calls :meth:`connect`. If :meth:`connect` fails at
        some point then :meth:`disconnect` is called.

        Within this method, to start the voice connection flow it is recommended to
        use :meth:`Guild.change_voice_state` to start the flow. After which,
        :meth:`on_voice_server_update` and :meth:`on_voice_state_update` will be called.
        The order that these two are called is unspecified.

        Parameters
        ------------
        timeout: :class:`float`
            The timeout for the connection.
        reconnect: :class:`bool`
            Whether reconnection is expected.
        self_mute: :class:`bool`
            Indicates if the client should be self-muted.

            .. versionadded:: 2.0
        self_deaf: :class:`bool`
            Indicates if the client should be self-deafened.

            .. versionadded:: 2.0
        r6   )r/   r@   rB   r>   r?   s        r0   connectzVoiceProtocol.connect   s      : "!r2   forcec                  K   t           )z|coro|

        An abstract method called when the client terminates the connection.

        See :meth:`cleanup`.

        Parameters
        ------------
        force: :class:`bool`
            Whether the disconnection was forced.
        r6   r/   rE   s     r0   
disconnectzVoiceProtocol.disconnect   s       "!r2   c                |    | j                                         \  }}| j        j                            |           dS )a  This method *must* be called to ensure proper clean-up during a disconnect.

        It is advisable to call this from within :meth:`disconnect` when you are
        completely done with the voice protocol instance.

        This method removes it from the internal state cache that keeps track of
        currently alive voice clients. Failure to clean-up will cause subsequent
        connections to report that it's still connected.
        N)r)   _get_voice_client_keyr(   _connection_remove_voice_client)r/   key_id_s      r0   cleanupzVoiceProtocol.cleanup   s:     L6688	44V<<<<<r2   Nr(   r   r)   r*   r+   r,   r3   r4   r+   r,   r3   r:   r+   r,   )
r@   rA   rB   r#   r>   r#   r?   r#   r+   r,   rE   r#   r+   r,   r+   r,   )
__name__
__module____qualname____doc__r1   r9   r<   rD   rH   rO    r2   r0   r%   r%   M   s         (0 0 0 0" " " """ " " " SXkp " " " " " ">" " " "= = = = = =r2   r%   c                      e Zd ZU dZded<   dj fd	Ze Zd
ed<   e Z	d
ed<   dZ
ded<   edkd            Zedld            Zedmd            Zedmd            Zedmd            Zednd            Zedod            Zedpd            Zedqd            Zedrd!            Zedmd"            Zdsd'Zdtd)Zdud,Zdvd.Zd/d/d0dwd5Zdxdyd8Zedrd9            Zedrd:            Zd/d;dzd=Zd6d>d{d@Z d|dAZ!d}dCZ"d~dEZ#d~dFZ$d~dGZ%d~dHZ&dIdJdKdLdMdNdOdPdd^Z'd|d_Z(d|d`Z)ddaZ*ddbZ+ddcZ,edde            Z-e-j.        ddf            Z-dLdgddiZ/ xZ0S )r&   a  Represents a Discord voice connection.

    You do not create these, you typically get them from
    e.g. :meth:`VoiceChannel.connect`.

    Warning
    --------
    In order to use PCM based AudioSources, you must have the opus library
    installed on your system and loaded through :func:`opus.load_opus`.
    Otherwise, your AudioSources must be opus encoded (e.g. using :class:`FFmpegOpusAudio`)
    or the library will not be able to transmit audio.

    Attributes
    -----------
    session_id: :class:`str`
        The voice connection session ID.
    token: :class:`str`
        The voice connection token.
    endpoint: :class:`str`
        The endpoint we are connecting to.
    channel: Union[:class:`VoiceChannel`, :class:`StageChannel`]
        The voice channel connected to.
    VocalGuildChannelr)   r(   r   r*   r+   r,   c                   t           st          d          t          st          d          t                                          ||           |j        }t          | _        t          | _        |j	        | _	        || _
        d| _        d| _        d | _        t          | _        d| _        |                                 | _        d S )Nz+PyNaCl library needed in order to use voicez*davey library needed in order to use voicer   )r$   RuntimeErrorr   superr1   rK   r   	server_idsocketloop_statesequence	timestamp_playerencoder_incr_noncecreate_connection_state)r/   r(   r)   state	__class__s       r0   r1   zVoiceClient.__init__   s     	NLMMM 	MKLLL)))"%/4z	',.2 ' !151M1M1O1Or2   r#   	warn_nacl	warn_dave)aead_xchacha20_poly1305_rtpsizexsalsa20_poly1305_litexsalsa20_poly1305_suffixxsalsa20_poly1305zTuple[SupportedModes, ...]supported_modesr   c                    | j         j        S )z-:class:`Guild`: The guild we're connected to.)r)   guildr/   s    r0   rs   zVoiceClient.guild   s     |!!r2   r   c                    | j         j        S )zB:class:`ClientUser`: The user connected to voice (i.e. ourselves).)rb   userrt   s    r0   rv   zVoiceClient.user   s     {r2   Optional[str]c                    | j         j        S r.   )rK   
session_idrt   s    r0   ry   zVoiceClient.session_id      **r2   c                    | j         j        S r.   )rK   tokenrt   s    r0   r|   zVoiceClient.token  s    %%r2   c                    | j         j        S r.   )rK   endpointrt   s    r0   r~   zVoiceClient.endpoint
  s    ((r2   intc                    | j         j        S r.   )rK   ssrcrt   s    r0   r   zVoiceClient.ssrc      $$r2   r"   c                    | j         j        S r.   )rK   modert   s    r0   r   zVoiceClient.mode  r   r2   	List[int]c                    | j         j        S r.   )rK   
secret_keyrt   s    r0   r   zVoiceClient.secret_key  rz   r2   r   c                    | j         j        S r.   )rK   wsrt   s    r0   r   zVoiceClient.ws  s    ""r2   rA   c                    | j         j        S r.   )rK   r@   rt   s    r0   r@   zVoiceClient.timeout  s    ''r2   c                @    | j         j        r| j         j        j        ndS )a  :class:`str`: Get the voice privacy code of this E2EE session's group.

        A new privacy code is created and cached each time a new transition is executed.
        This can be None if there is no active DAVE session happening.

        .. versionadded:: 2.7
        N)rK   dave_sessionvoice_privacy_codert   s    r0   r   zVoiceClient.voice_privacy_code"  s&     DHCSC`jt,??fjjr2   attrstrvaluelimitc                    t          | |          }||z   |k    rt          | |d           d S t          | |||z              d S )Nr   )getattrsetattr)r/   r   r   r   vals        r0   checked_addzVoiceClient.checked_add-  sT    dD!!;D$"""""D$e,,,,,r2   r   c                     t          |           S r.   )r   rt   s    r0   rh   z#VoiceClient.create_connection_state6  s    #D)))r2   r3   r4   c                J   K   | j                             |           d {V  d S r.   )rK   voice_state_updater8   s     r0   r9   z!VoiceClient.on_voice_state_update9  s5      11$77777777777r2   r:   c                J   K   | j                             |           d {V  d S r.   )rK   voice_server_updater8   s     r0   r<   z"VoiceClient.on_voice_server_update<  s5      22488888888888r2   Fr=   rB   r@   r>   r?   c               T   K   | j                             ||||d           d {V  d S )NF)rB   r@   r>   r?   resume)rK   rD   )r/   rB   r@   r>   r?   s        r0   rD   zVoiceClient.connect?  s[      &&IQZch ' 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r2         >@Optional[float]c                h    | j                             |           | j                                         S r.   )rK   waitis_connected)r/   r@   s     r0   wait_until_connectedz VoiceClient.wait_until_connectedD  s.    g&&&,,...r2   c                J    | j         j        }|st          d          n|j        S )a  :class:`float`: Latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds.

        This could be referred to as the Discord Voice WebSocket latency and is
        an analogue of user's voice latencies as seen in the Discord client.

        .. versionadded:: 1.4
        inf)rK   r   rA   latencyr/   r   s     r0   r   zVoiceClient.latencyH  s&      #%5uU|||2:5r2   c                J    | j         j        }|st          d          n|j        S )zq:class:`float`: Average of most recent 20 HEARTBEAT latencies in seconds.

        .. versionadded:: 1.4
        r   )rK   r   rA   average_latencyr   s     r0   r   zVoiceClient.average_latencyT  s'      #%=uU|||2+==r2   )rE   rE   c                  K   |                                   | j                            |d           d{V  |                                  dS )zB|coro|

        Disconnects this voice client from voice.
        T)rE   r   N)stoprK   rH   rO   rG   s     r0   rH   zVoiceClient.disconnect]  sT      
 			))D)AAAAAAAAAr2   )r@   Optional[abc.Snowflake]c               L   K   | j                             ||           d{V  dS )a  |coro|

        Moves you to a different voice channel.

        Parameters
        -----------
        channel: Optional[:class:`abc.Snowflake`]
            The channel to move to. Must be a voice channel.
        timeout: Optional[:class:`float`]
            How long to wait for the move to complete.

            .. versionadded:: 2.4

        Raises
        -------
        asyncio.TimeoutError
            The move did not complete in time, but may still be ongoing.
        N)rK   move_to)r/   r)   r@   s      r0   r   zVoiceClient.move_tof  s9      & &&w88888888888r2   c                4    | j                                         S )z4Indicates if the voice client is connected to voice.)rK   r   rt   s    r0   r   zVoiceClient.is_connected{  s    ,,...r2   bytesc                   | j         j        r+| j         j        r| j         j                            |          n|}t	          d          }d|d<   d|d<   t          j        d|d| j                   t          j        d|d	| j                   t          j        d|d
| j	                   t          | d| j        z             } |||          S )N      r   x   r   z>H   >I      	_encrypt_)rK   r   can_encryptencrypt_opus	bytearraystruct	pack_intorc   rd   r   r   r   )r/   r3   packetheaderencrypt_packets        r0   _get_voice_packetzVoiceClient._get_voice_packet  s     ,151A1MD)66t<<< 	
 2 q	q	vq$-888vq$.999vq$)444 {TY'>??~ff---r2   r   c                   t           j                            t          | j                            }t          d          }t          j        d| j                  |d d<   | 	                    ddd           ||
                    t          |          t          |          t          |                    j        z   |d d         z   S N   r   r   rg   r       )naclsecretAeadr   r   r   r   packrg   r   encrypt
ciphertextr/   r   r3   boxnonces        r0   (_encrypt_aead_xchacha20_poly1305_rtpsizez4VoiceClient._encrypt_aead_xchacha20_poly1305_rtpsize  s     kuT_5566"Kd&677bqb	:666E$KKveMMXX[`acbcac[dddr2   c                    t           j                            t          | j                            }t          d          }||d d<   ||                    t          |          t          |                    j        z   S )Nr   r   )r   r   	SecretBoxr   r   r   r   r   r   s        r0   _encrypt_xsalsa20_poly1305z&VoiceClient._encrypt_xsalsa20_poly1305  sc     k##E$/$:$:;;"crc
E$KKu>>IIIr2   c                &   t           j                            t          | j                            }t           j                            t           j        j        j                  }||                    t          |          |          j	        z   |z   S r.   )
r   r   r   r   r   utilsrandom
NONCE_SIZEr   r   r   s        r0   !_encrypt_xsalsa20_poly1305_suffixz-VoiceClient._encrypt_xsalsa20_poly1305_suffix  sg     k##E$/$:$:;;
!!$+"7"BCCE$KK77BBUJJr2   c                t   t           j                            t          | j                            }t          d          }t          j        d| j                  |d d<   | 	                    ddd           ||
                    t          |          t          |                    j        z   |d d         z   S r   )r   r   r   r   r   r   r   r   rg   r   r   r   r   s        r0   _encrypt_xsalsa20_poly1305_litez+VoiceClient._encrypt_xsalsa20_poly1305_lite  s     k##E$/$:$:;;"Kd&677bqb	:666E$KKu>>IIERTSTRTIUUr2   Naudior   Tg333333?fullauto)afterapplicationbitratefecexpected_packet_loss	bandwidthsignal_typesourcer   r   .Optional[Callable[[Optional[Exception]], Any]]r   r   r   r   r   r   r   r   r   c                  |                                  st          d          |                                 rt          d          t          |t                    st          d|j        j                   |                                st          j
        ||||||          | _        t          || |          | _        | j                                         dS )a
  Plays an :class:`AudioSource`.

        The finalizer, ``after`` is called after the source has been exhausted
        or an error occurred.

        If an error happens while the audio player is running, the exception is
        caught and the audio player is then stopped.  If no after callback is
        passed, any caught exception will be logged using the library logger.

        Extra parameters may be passed to the internal opus encoder if a PCM based
        source is used.  Otherwise, they are ignored.

        .. versionchanged:: 2.0
            Instead of writing to ``sys.stderr``, the library's logger is used.

        .. versionchanged:: 2.4
            Added encoder parameters as keyword arguments.

        Parameters
        -----------
        source: :class:`AudioSource`
            The audio source we're reading from.
        after: Callable[[Optional[:class:`Exception`]], Any]
            The finalizer that is called after the stream is exhausted.
            This function must have a single parameter, ``error``, that
            denotes an optional exception that was raised during playing.
        application: :class:`str`
            Configures the encoder's intended application.  Can be one of:
            ``'audio'``, ``'voip'``, ``'lowdelay'``.
            Defaults to ``'audio'``.
        bitrate: :class:`int`
            Configures the bitrate in the encoder.  Can be between ``16`` and ``512``.
            Defaults to ``128``.
        fec: :class:`bool`
            Configures the encoder's use of inband forward error correction.
            Defaults to ``True``.
        expected_packet_loss: :class:`float`
            Configures the encoder's expected packet loss percentage.  Requires FEC.
            Defaults to ``0.15``.
        bandwidth: :class:`str`
            Configures the encoder's bandpass.  Can be one of:
            ``'narrow'``, ``'medium'``, ``'wide'``, ``'superwide'``, ``'full'``.
            Defaults to ``'full'``.
        signal_type: :class:`str`
            Configures the type of signal being encoded.  Can be one of:
            ``'auto'``, ``'voice'``, ``'music'``.
            Defaults to ``'auto'``.

        Raises
        -------
        ClientException
            Already playing audio or not connected.
        TypeError
            Source is not a :class:`AudioSource` or after is not a callable.
        OpusNotLoaded
            Source is not opus encoded and opus is not loaded.
        ValueError
            An improper value was passed as an encoder parameter.
        zNot connected to voice.zAlready playing audio.z"source must be an AudioSource not )r   r   r   r   r   r   )r   N)r   r   
is_playing
isinstancer   	TypeErrorrj   rU   is_opusr   r   rf   r   re   start)	r/   r   r   r   r   r   r   r   r   s	            r0   playzVoiceClient.play  s    P   "" 	=!";<<<?? 	<!":;;;&+.. 	^\AQAZ\\]]]~~ 	<'%9#'  DL #64u===r2   c                F    | j         duo| j                                         S )z+Indicates if we're currently playing audio.N)re   r   rt   s    r0   r   zVoiceClient.is_playing  s"    |4'EDL,C,C,E,EEr2   c                F    | j         duo| j                                         S )z6Indicates if we're playing audio, but if we're paused.N)re   	is_pausedrt   s    r0   r   zVoiceClient.is_paused  s"    |4'DDL,B,B,D,DDr2   c                X    | j         r"| j                                          d| _         dS dS )zStops playing audio.N)re   r   rt   s    r0   r   zVoiceClient.stop!  s5    < 	 LDLLL	  	 r2   c                J    | j         r| j                                          dS dS )zPauses the audio playing.N)re   pausert   s    r0   r   zVoiceClient.pause'  s0    < 	!L     	! 	!r2   c                J    | j         r| j                                          dS dS )zResumes the audio playing.N)re   r   rt   s    r0   r   zVoiceClient.resume,  s0    < 	"L!!!!!	" 	"r2   Optional[AudioSource]c                ,    | j         r| j         j        ndS )zOptional[:class:`AudioSource`]: The audio source being played, if playing.

        This property can also be used to change the audio source currently being played.
        N)re   r   rt   s    r0   r   zVoiceClient.source1  s     '+l<t|""<r2   c                    t          |t                    st          d|j        j         d          | j        t          d          | j                            |           d S )Nzexpected AudioSource not .zNot playing anything.)r   r   r   rj   rU   re   
ValueError
set_source)r/   r   s     r0   r   zVoiceClient.source9  sg    %-- 	US8PSSSTTT<4555&&&&&r2   )encoder   c                  |                      ddd           |r&| j                            || j        j                  }n|}|                     |          }	 | j                            |           n6# t          $ r) t          	                    d| j
        | j                   Y nw xY w|                      dt          j        j        d           dS )a  Sends an audio packet composed of the data.

        You must be connected to play audio.

        Parameters
        ----------
        data: :class:`bytes`
            The :term:`py:bytes-like object` denoting PCM or Opus voice data.
        encode: :class:`bool`
            Indicates if ``data`` should be encoded into Opus.

        Raises
        -------
        ClientException
            You are not connected.
        opus.OpusError
            Encoding the data failed.
        rc   r   i  z2A packet has been dropped (seq: %s, timestamp: %s)rd   r   N)r   rf   r   SAMPLES_PER_FRAMEr   rK   send_packetOSError_logdebugrc   rd   r   r   )r/   r3   r   encoded_datar   s        r0   send_audio_packetzVoiceClient.send_audio_packetC  s    ( 	Q... 	 <..tT\5STTLLL''55	l((0000 	l 	l 	lJJKT]\`\jkkkkk	l 	dl&DjQQQQQs   A3 30B&%B&rP   )r+   r   )r+   r   )r+   rw   )r+   r   )r+   r"   )r+   r   )r+   r   )r+   rA   )r   r   r   r   r   r   r+   r,   )r+   r   rQ   rR   )
rB   r#   r@   rA   r>   r#   r?   r#   r+   r,   )r   )r@   r   r+   r#   rS   )r)   r   r@   r   r+   r,   )r+   r#   )r3   r   )r   r   r+   r   )r   r   r   r   r   r   r   r   r   r#   r   rA   r   r   r   r   r+   r,   rT   )r+   r   )r   r   r+   r,   )r3   r   r   r#   r+   r,   )1rU   rV   rW   rX   __annotations__r1   r$   rk   r   rl   rq   propertyrs   rv   ry   r|   r~   r   r   r   r   r@   r   r   rh   r9   r<   rD   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   setterr  __classcell__)rj   s   @r0   r&   r&      s         0 P P P P P P* #lI"""""lI""""3O     " " " X"       X  + + + X+ & & & X& ) ) ) X) % % % X% % % % X% + + + X+ # # # X# ( ( ( X( k k k Xk- - - -* * * *8 8 8 89 9 9 9 SXkp 
 
 
 
 
 

/ / / / / 	6 	6 	6 X	6 > > > X> 16       ]a 9 9 9 9 9 9*/ / / /. . . .$
e 
e 
e 
eJ J J JK K K K	V 	V 	V 	V AE'.&*$"(\ \ \ \ \ \|F F F FE E E E       ! ! ! !
" " " "
 = = = X= ]' ' ' ]' @D R R R R R R R R R Rr2   r&   )?rX   
__future__r   asynciologgingr   typingr   r   r   r   r   r	   r
    r   gatewayerrorsr   playerr   r   r   r   voice_stater   r   r   r(   r   rs   r   ri   r   rv   r   r   r   r   r   r)   r   r   r   types.voicer    r4   r!   r:   r"   r[   r  nacl.secretr   
nacl.utilsr$   ImportError__all__	getLoggerrU   r   r%   r&   rY   r2   r0   <module>r     s    0 # " " " " "    M M M M M M M M M M M M M M M M M M           # # # # # # , , , , , , , ,       7 7 7 7 7 7 7 7 :......&&&&&&      DDDDDDDDDDDD33333333          lL89 HH   HHH w""o= o= o= o= o= o= o= o=dcR cR cR cR cR- cR cR cR cR cRs   "
B- -B76B7