Skip to content

Commit

Permalink
Change to how websocket processes data.
Browse files Browse the repository at this point in the history
Update version.
  • Loading branch information
EvieePy committed Jul 15, 2019
1 parent a54eeaa commit d9c99d0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
requirements.append('sphinxcontrib-websupport')
requirements.append('Pygments')

version = '0.2.06'
version = '0.2.08'

readme = ''
with open('README.rst') as f:
Expand Down
2 changes: 1 addition & 1 deletion wavelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__author__ = 'EvieePy'
__license__ = 'MIT'
__copyright__ = 'Copyright 2019 (c) EvieePy'
__version__ = '0.2.06a'
__version__ = '0.2.08a'

from .client import Client
from .errors import *
Expand Down
52 changes: 26 additions & 26 deletions wavelink/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,39 @@ async def _listen(self):
await asyncio.sleep(retry)
if not self.is_connected:
self.bot.loop.create_task(self._connect())
else:
self.bot.loop.create_task(self.process_data(data))

continue

if data:
data = json.loads(data)
async def process_data(self, data: str):
data = json.loads(data)

op = data.get('op', None)
if not op:
continue
op = data.get('op', None)
if not op:
return

if op == 'stats':
self._node.stats = Stats(self._node, data)
if op == 'event':
try:
data['player'] = self._node.players[int(data['guildId'])]
except KeyError:
continue
if op == 'stats':
self._node.stats = Stats(self._node, data)
if op == 'event':
try:
data['player'] = self._node.players[int(data['guildId'])]
except KeyError:
return

event = self._get_event(data['type'], data)
event = self._get_event(data['type'], data)

__log__.debug(f'WEBSOCKET | op: event:: {data}')
__log__.debug(f'WEBSOCKET | op: event:: {data}')

try:
await self._node.on_event(event)
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)
try:
await self._node.on_event(event)
except Exception as e:
traceback.print_exception(type(e), e, e.__traceback__, file=sys.stderr)

elif op == 'playerUpdate':
__log__.debug(f'WEBSOCKET | op: playerUpdate:: {data}')
try:
await self._node.players[int(data['guildId'])].update_state(data)
except KeyError:
pass
elif op == 'playerUpdate':
__log__.debug(f'WEBSOCKET | op: playerUpdate:: {data}')
try:
await self._node.players[int(data['guildId'])].update_state(data)
except KeyError:
pass

def _get_event(self, name: str, data) -> Union[TrackEnd, TrackException, TrackStuck]:
if name == 'TrackEndEvent':
Expand Down

0 comments on commit d9c99d0

Please sign in to comment.