2626from __future__ import annotations
2727
2828import asyncio
29- from collections import namedtuple
3029import logging
3130import struct
3231import sys
3332import time
33+ from collections import namedtuple
3434from collections .abc import Callable , Coroutine , Iterable
3535from functools import partial
36- import threading
3736from typing import TYPE_CHECKING , Any , Generic , TypeVar , overload
3837
39- from discord import utils , opus
38+ from discord import opus , utils
4039from discord .enums import SpeakingState
4140from discord .utils import MISSING
4241
@@ -154,16 +153,25 @@ def filter_speaking_state(
154153
155154 @overload
156155 async def filter_user_connect (
157- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
156+ self ,
157+ sink : S ,
158+ user : abc .Snowflake ,
159+ channel : abc .Snowflake ,
158160 ) -> bool : ...
159161
160162 @overload
161163 def filter_user_connect (
162- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
164+ self ,
165+ sink : S ,
166+ user : abc .Snowflake ,
167+ channel : abc .Snowflake ,
163168 ) -> bool : ...
164169
165170 def filter_user_connect (
166- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
171+ self ,
172+ sink : S ,
173+ user : abc .Snowflake ,
174+ channel : abc .Snowflake ,
167175 ) -> bool | Coroutine [Any , Any , bool ]:
168176 """|maybecoro|
169177
@@ -256,16 +264,25 @@ def handle_speaking_state(
256264
257265 @overload
258266 async def handle_user_connect (
259- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
267+ self ,
268+ sink : S ,
269+ user : abc .Snowflake ,
270+ channel : abc .Snowflake ,
260271 ) -> Any : ...
261272
262273 @overload
263274 def handle_user_connect (
264- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
275+ self ,
276+ sink : S ,
277+ user : abc .Snowflake ,
278+ channel : abc .Snowflake ,
265279 ) -> Any : ...
266280
267281 def handle_user_connect (
268- self , sink : S , user : abc .Snowflake , channel : abc .Snowflake ,
282+ self ,
283+ sink : S ,
284+ user : abc .Snowflake ,
285+ channel : abc .Snowflake ,
269286 ) -> Any | Coroutine [Any , Any , Any ]:
270287 """|maybecoro|
271288
@@ -292,9 +309,9 @@ class RawData:
292309 .. versionadded:: 2.0
293310 """
294311
295- unpacker = struct .Struct (' >xxHII' )
296- _ext_header = namedtuple (' Extension' , ' profile length values' )
297- _ext_magic = b' \xbe \xde '
312+ unpacker = struct .Struct (" >xxHII" )
313+ _ext_header = namedtuple (" Extension" , " profile length values" )
314+ _ext_magic = b" \xbe \xde "
298315
299316 if TYPE_CHECKING :
300317 sequence : int
@@ -322,14 +339,14 @@ def __init__(self, raw_data: bytes, client: VoiceClient):
322339 self .decrypted_data : bytes | None = None
323340 self .decoded_data : bytes = MISSING
324341
325- self .nonce : bytes = b''
342+ self .nonce : bytes = b""
326343 self ._rtpsize : bool = False
327344
328345 self ._decoder : opus .Decoder = opus .Decoder ()
329346 self .receive_time : float = time .perf_counter ()
330347
331348 if self .cc :
332- fmt = ' >%sI' % self .cc
349+ fmt = " >%sI" % self .cc
333350 offset = struct .calcsize (fmt ) + 12
334351 self .csrcs = struct .unpack (fmt , data [12 :offset ])
335352 self .data = data [offset :]
@@ -351,12 +368,12 @@ def update_headers(self, data: bytes) -> int:
351368 if self ._rtpsize :
352369 data = self .header [- 4 :] + data
353370
354- profile , length = struct .unpack_from (' >2sH' , data )
371+ profile , length = struct .unpack_from (" >2sH" , data )
355372
356373 if profile == self ._ext_magic :
357374 self ._parse_bede_header (data , length )
358375
359- values = struct .unpack (' >%sI' % length , data [4 : 4 + length * 4 ])
376+ values = struct .unpack (" >%sI" % length , data [4 : 4 + length * 4 ])
360377 self .extension = self ._ext_header (profile , length , values )
361378
362379 offset = 4 + length * 4
@@ -371,23 +388,25 @@ def _parse_bede_header(self, data: bytes, length: int) -> None:
371388 while n < length :
372389 next_byte = data [offset : offset + 1 ]
373390
374- if next_byte == b' \x00 ' :
391+ if next_byte == b" \x00 " :
375392 offset += 1
376393 continue
377394
378- header = struct .unpack ('>B' , next_byte )[0 ]
395+ header = struct .unpack (">B" , next_byte )[0 ]
379396
380397 element_id = header >> 4
381398 element_len = 1 + (header & 0b0000_1111 )
382399
383- self .extension_data [element_id ] = data [offset + 1 : offset + 1 + element_len ]
400+ self .extension_data [element_id ] = data [
401+ offset + 1 : offset + 1 + element_len
402+ ]
384403 offset += 1 + element_len
385404 n += 1
386405
387406 async def decode (self ) -> bytes :
388407 if not self .decrypted_data :
389- _log .debug (' Attempted to decode an empty decrypted data frame' )
390- return b''
408+ _log .debug (" Attempted to decode an empty decrypted data frame" )
409+ return b""
391410
392411 return await asyncio .to_thread (
393412 self ._decoder .decode ,
@@ -529,7 +548,9 @@ def _call_voice_packet_handlers(self, user: abc.Snowflake, packet: RawData) -> N
529548 task .add_done_callback (self .__dispatch_set .discard )
530549
531550 def _call_user_connect_handlers (
532- self , user : abc .Snowflake , channel : abc .Snowflake ,
551+ self ,
552+ user : abc .Snowflake ,
553+ channel : abc .Snowflake ,
533554 ) -> None :
534555 for handler in self ._handlers :
535556 task = asyncio .create_task (
@@ -742,7 +763,9 @@ async def on_unfiltered_speaking_state_update(
742763 pass
743764
744765 async def on_user_connect (
745- self , user : abc .Snowflake , channel : abc .Snowflake ,
766+ self ,
767+ user : abc .Snowflake ,
768+ channel : abc .Snowflake ,
746769 ) -> None :
747770 pass
748771
0 commit comments