Skip to content

Commit

Permalink
Voice Receiving (Pycord-Development#532)
Browse files Browse the repository at this point in the history
* 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 <61446939+CodeWithSwastik@users.noreply.github.com>

* Fix Typo

https://discord.com/channels/881207955029110855/881735314987708456/922020659394129940

* Replace `ClientException`s to `SinkException`s

* Adding ``.pycord`` tempdir

* revert tempdir

Co-authored-by: Vincent <82736662+RPSMain@users.noreply.github.com>
Co-authored-by: Swas.py <61446939+CodeWithSwastik@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 20, 2021
1 parent 3d04a71 commit 046380a
Show file tree
Hide file tree
Showing 9 changed files with 913 additions and 169 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ docs/crowdin.py
*.mp3
*.m4a
*.wav
*.pcm
*.png
*.jpg
*.flac
Expand All @@ -18,6 +19,8 @@ docs/crowdin.py
.DS_Store
.python-version
__pycache__
.vs/slnx.sqlite
.vs/*
.vscode/*
env/
build/
test.py
1 change: 1 addition & 0 deletions discord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .sticker import *
from .stage_instance import *
from .interactions import *
from .sink import *
from .components import *
from .threads import *
from .bot import *
Expand Down
16 changes: 15 additions & 1 deletion discord/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
'ExtensionNotLoaded',
'NoEntryPointError',
'ExtensionFailed',
'ExtensionNotFound'
'ExtensionNotFound',
'RecordingException',
)


Expand Down Expand Up @@ -269,6 +270,19 @@ def __init__(self, shard_id: Optional[int]):
)
super().__init__(msg % shard_id)

class RecordingException(ClientException):
"""Exception that's thrown when there is an error while trying to record
audio from a voice channel.
.. versionadded:: 2.0
"""
pass

class SinkException(ClientException):
"""Raised when a Sink error occurs.
.. versionadded:: 2.0
"""

class InteractionResponded(ClientException):
"""Exception that's raised when sending another interaction response using
Expand Down
10 changes: 10 additions & 0 deletions discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ def __init__(self, socket, loop, *, hook=None):
self._keep_alive = None
self._close_code = None
self.secret_key = None
self.ssrc_map = {}
if hook:
self._hook = hook

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

elif op == self.SPEAKING:
ssrc = data['ssrc']
user = int(data['user_id'])
speaking = data['speaking']
if ssrc in self.ssrc_map:
self.ssrc_map[ssrc]['speaking'] = speaking
else:
self.ssrc_map.update({ssrc: {'user_id': user, 'speaking': speaking}})

await self._hook(self, msg)

async def initial_connection(self, data):
Expand Down
Loading

0 comments on commit 046380a

Please sign in to comment.