diff options
| author | Imayhaveborkedit <[email protected]> | 2019-01-16 01:35:31 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-01-28 22:22:52 -0500 |
| commit | 9c5259afd7bf8a71574ef13ae130009c3755662f (patch) | |
| tree | 6de2a9f860f484ac0e3243e8eac4d8d4e89a1f27 /discord/player.py | |
| parent | Fix accidental regression of 9bc48b2 in fa46b07 (diff) | |
| download | discord.py-9c5259afd7bf8a71574ef13ae130009c3755662f.tar.xz discord.py-9c5259afd7bf8a71574ef13ae130009c3755662f.zip | |
Update voice code to vws V4
- Update internals to be compatible with v4
- Adds multiple encryption mode support. Previously only `xsalsa20_poly1305` was supported. Now `xsalsa20_poly1305_suffix` is also supported.
Note: There is no (nice) way to manually select a mode. The user needn't worry about this however.
- Fixed speaking state bug. When you disconnected from a voice channel while a bot was playing, upon reconnect you would be unable to hear the bot. This was caused by bots not sending their speaking state while transmitting. Bots will now set their speaking state properly when transmitting.
Note: This does not account for sending actual silence, the speaking indicator will still be active.
Diffstat (limited to 'discord/player.py')
| -rw-r--r-- | discord/player.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/discord/player.py b/discord/player.py index 74cd073f..8ee3bd13 100644 --- a/discord/player.py +++ b/discord/player.py @@ -27,6 +27,7 @@ DEALINGS IN THE SOFTWARE. import threading import subprocess import audioop +import asyncio import logging import shlex import time @@ -261,6 +262,7 @@ class AudioPlayer(threading.Thread): # getattr lookup speed ups play_audio = self.client.send_audio_packet + self._speak(True) while not self._end.is_set(): # are we paused? @@ -309,14 +311,19 @@ class AudioPlayer(threading.Thread): def stop(self): self._end.set() self._resumed.set() + self._speak(False) - def pause(self): + def pause(self, *, update_speaking=True): self._resumed.clear() + if update_speaking: + self._speak(False) - def resume(self): + def resume(self, *, update_speaking=True): self.loops = 0 self._start = time.time() self._resumed.set() + if update_speaking: + self._speak(True) def is_playing(self): return self._resumed.is_set() and not self._end.is_set() @@ -326,6 +333,12 @@ class AudioPlayer(threading.Thread): def _set_source(self, source): with self._lock: - self.pause() + self.pause(update_speaking=False) self.source = source - self.resume() + self.resume(update_speaking=False) + + def _speak(self, speaking): + try: + asyncio.run_coroutine_threadsafe(self.client.ws.speak(speaking), self.client.loop) + except Exception as e: + log.info("Speaking call in player failed: %s", e) |