Skip to content

Commit 046380a

Browse files
Voice Receiving (#532)
* Implementation Of Rapptz/discord.py#6507 Initial Unchanged Implementation from the discord.py pull * Implement Fix * Advances Docstrings in sink * Implement Fixes I formatted some of the Voice files since no-one is changing them else than me currently and added more versionadded's * Should Decrease Static By A Bit * Fixes & Docs * Fix * Fix Indents * Switch Example To Use MP3 * Adding PCM As Ignored * Fixes * Fix Static Error * Fix RecordingException Docs * Fix ValueErrors * Changing Version Added To 2.0 * Details * Fix My Visual Studio Setup * Typo * Better Filters Docstring * Fix * Fix Version Info * Fix * Redo Voice Example To Use Bot Instead of Client Co-Authored-By: Swas.py <[email protected]> * Fix Typo https://discord.com/channels/881207955029110855/881735314987708456/922020659394129940 * Replace `ClientException`s to `SinkException`s * Adding ``.pycord`` tempdir * revert tempdir Co-authored-by: Vincent <[email protected]> Co-authored-by: Swas.py <[email protected]>
1 parent 3d04a71 commit 046380a

File tree

9 files changed

+913
-169
lines changed

9 files changed

+913
-169
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ docs/crowdin.py
1010
*.mp3
1111
*.m4a
1212
*.wav
13+
*.pcm
1314
*.png
1415
*.jpg
1516
*.flac
@@ -18,6 +19,8 @@ docs/crowdin.py
1819
.DS_Store
1920
.python-version
2021
__pycache__
21-
.vs/slnx.sqlite
22+
.vs/*
23+
.vscode/*
2224
env/
2325
build/
26+
test.py

discord/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from .sticker import *
5858
from .stage_instance import *
5959
from .interactions import *
60+
from .sink import *
6061
from .components import *
6162
from .threads import *
6263
from .bot import *

discord/errors.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
'ExtensionNotLoaded',
6060
'NoEntryPointError',
6161
'ExtensionFailed',
62-
'ExtensionNotFound'
62+
'ExtensionNotFound',
63+
'RecordingException',
6364
)
6465

6566

@@ -269,6 +270,19 @@ def __init__(self, shard_id: Optional[int]):
269270
)
270271
super().__init__(msg % shard_id)
271272

273+
class RecordingException(ClientException):
274+
"""Exception that's thrown when there is an error while trying to record
275+
audio from a voice channel.
276+
277+
.. versionadded:: 2.0
278+
"""
279+
pass
280+
281+
class SinkException(ClientException):
282+
"""Raised when a Sink error occurs.
283+
284+
.. versionadded:: 2.0
285+
"""
272286

273287
class InteractionResponded(ClientException):
274288
"""Exception that's raised when sending another interaction response using

discord/gateway.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ def __init__(self, socket, loop, *, hook=None):
728728
self._keep_alive = None
729729
self._close_code = None
730730
self.secret_key = None
731+
self.ssrc_map = {}
731732
if hook:
732733
self._hook = hook
733734

@@ -839,6 +840,15 @@ async def received_message(self, msg):
839840
self._keep_alive = VoiceKeepAliveHandler(ws=self, interval=min(interval, 5.0))
840841
self._keep_alive.start()
841842

843+
elif op == self.SPEAKING:
844+
ssrc = data['ssrc']
845+
user = int(data['user_id'])
846+
speaking = data['speaking']
847+
if ssrc in self.ssrc_map:
848+
self.ssrc_map[ssrc]['speaking'] = speaking
849+
else:
850+
self.ssrc_map.update({ssrc: {'user_id': user, 'speaking': speaking}})
851+
842852
await self._hook(self, msg)
843853

844854
async def initial_connection(self, data):

0 commit comments

Comments
 (0)