|
@ -45,11 +45,6 @@ import asyncio |
|
|
import logging |
|
|
import logging |
|
|
import threading |
|
|
import threading |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
from asyncio import timeout as atimeout # type: ignore |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
from async_timeout import timeout as atimeout # type: ignore |
|
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING, Optional, Dict, List, Callable, Coroutine, Any, Tuple |
|
|
from typing import TYPE_CHECKING, Optional, Dict, List, Callable, Coroutine, Any, Tuple |
|
|
|
|
|
|
|
|
from .enums import Enum |
|
|
from .enums import Enum |
|
@ -400,10 +395,7 @@ class VoiceConnectionState: |
|
|
await self.disconnect() |
|
|
await self.disconnect() |
|
|
raise |
|
|
raise |
|
|
|
|
|
|
|
|
async def _connect(self, reconnect: bool, timeout: float, self_deaf: bool, self_mute: bool, resume: bool) -> None: |
|
|
async def _inner_connect(self, reconnect: bool, self_deaf: bool, self_mute: bool, resume: bool) -> None: |
|
|
_log.info('Connecting to voice...') |
|
|
|
|
|
|
|
|
|
|
|
async with atimeout(timeout): |
|
|
|
|
|
for i in range(5): |
|
|
for i in range(5): |
|
|
_log.info('Starting voice handshake... (connection attempt %d)', i + 1) |
|
|
_log.info('Starting voice handshake... (connection attempt %d)', i + 1) |
|
|
|
|
|
|
|
@ -431,6 +423,13 @@ class VoiceConnectionState: |
|
|
await self.disconnect() |
|
|
await self.disconnect() |
|
|
raise |
|
|
raise |
|
|
|
|
|
|
|
|
|
|
|
async def _connect(self, reconnect: bool, timeout: float, self_deaf: bool, self_mute: bool, resume: bool) -> None: |
|
|
|
|
|
_log.info('Connecting to voice...') |
|
|
|
|
|
|
|
|
|
|
|
await asyncio.wait_for( |
|
|
|
|
|
self._inner_connect(reconnect=reconnect, self_deaf=self_deaf, self_mute=self_mute, resume=resume), |
|
|
|
|
|
timeout=timeout, |
|
|
|
|
|
) |
|
|
_log.info('Voice connection complete.') |
|
|
_log.info('Voice connection complete.') |
|
|
|
|
|
|
|
|
if not self._runner: |
|
|
if not self._runner: |
|
@ -472,8 +471,7 @@ class VoiceConnectionState: |
|
|
# The new VoiceConnectionState object receives the voice_state_update event containing channel=None while still |
|
|
# The new VoiceConnectionState object receives the voice_state_update event containing channel=None while still |
|
|
# connecting leaving it in a bad state. Since there's no nice way to transfer state to the new one, we have to do this. |
|
|
# connecting leaving it in a bad state. Since there's no nice way to transfer state to the new one, we have to do this. |
|
|
try: |
|
|
try: |
|
|
async with atimeout(self.timeout): |
|
|
await asyncio.wait_for(self._disconnected.wait(), timeout=self.timeout) |
|
|
await self._disconnected.wait() |
|
|
|
|
|
except TimeoutError: |
|
|
except TimeoutError: |
|
|
_log.debug('Timed out waiting for voice disconnection confirmation') |
|
|
_log.debug('Timed out waiting for voice disconnection confirmation') |
|
|
except asyncio.CancelledError: |
|
|
except asyncio.CancelledError: |
|
|