From 0b93fa3a82e8b1b1d9f637e7be0333efd0a232b2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 10 Aug 2020 06:28:36 -0400 Subject: Implement VoiceProtocol lower level hooks. This allows changing the connect flow and taking control of it without relying on internal events or tricks. --- discord/state.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'discord/state.py') diff --git a/discord/state.py b/discord/state.py index f0e93d35..fc297d03 100644 --- a/discord/state.py +++ b/discord/state.py @@ -63,6 +63,12 @@ Listener = namedtuple('Listener', ('type', 'future', 'predicate')) log = logging.getLogger(__name__) ReadyState = namedtuple('ReadyState', ('launch', 'guilds')) +async def logging_coroutine(coroutine, *, info): + try: + await coroutine + except Exception: + log.exception('Exception occurred during %s', info) + class ConnectionState: def __init__(self, *, dispatch, handlers, hooks, syncer, http, loop, **options): self.loop = loop @@ -939,9 +945,8 @@ class ConnectionState: if int(data['user_id']) == self.user.id: voice = self._get_voice_client(guild.id) if voice is not None: - ch = guild.get_channel(channel_id) - if ch is not None: - voice.channel = ch + coro = voice.on_voice_state_update(data) + asyncio.ensure_future(logging_coroutine(coro, info='Voice Protocol voice state update handler')) member, before, after = guild._update_voice_state(data, channel_id) if member is not None: @@ -962,7 +967,8 @@ class ConnectionState: vc = self._get_voice_client(key_id) if vc is not None: - asyncio.ensure_future(vc._create_socket(key_id, data)) + coro = vc.on_voice_server_update(data) + asyncio.ensure_future(logging_coroutine(coro, info='Voice Protocol voice server update handler')) def parse_typing_start(self, data): channel, guild = self._get_guild_channel(data) -- cgit v1.2.3