aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/gateway.py7
-rw-r--r--discord/shard.py1
-rw-r--r--discord/state.py6
3 files changed, 10 insertions, 4 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index bf51377f..aa2c02ee 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -227,6 +227,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
# dynamically add attributes needed
ws.token = client.http.token
ws._connection = client._connection
+ ws._discord_parsers = client._connection.parsers
ws._dispatch = client.dispatch
ws.gateway = gateway
ws.shard_id = shard_id
@@ -414,11 +415,9 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
log.info('Shard ID %s has successfully RESUMED session %s under trace %s.',
self.shard_id, self.session_id, ', '.join(trace))
- parser = 'parse_' + event.lower()
-
try:
- func = getattr(self._connection, parser)
- except AttributeError:
+ func = self._discord_parsers[event]
+ except KeyError:
log.warning('Unknown event %s.', event)
else:
func(data)
diff --git a/discord/shard.py b/discord/shard.py
index a5f5f541..331d174b 100644
--- a/discord/shard.py
+++ b/discord/shard.py
@@ -221,6 +221,7 @@ class AutoShardedClient(Client):
ws.token = self.http.token
ws._connection = self._connection
+ ws._discord_parsers = self._connection.parsers
ws._dispatch = self.dispatch
ws.gateway = gateway
ws.shard_id = shard_id
diff --git a/discord/state.py b/discord/state.py
index f04d6ee7..d56b9e75 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -33,6 +33,7 @@ import itertools
import logging
import math
import weakref
+import inspect
from .guild import Guild
from .activity import _ActivityTag
@@ -88,6 +89,11 @@ class ConnectionState:
self._activity = activity
self._status = status
+ self.parsers = parsers = {}
+ for attr, func in inspect.getmembers(self):
+ if attr.startswith('parse_'):
+ parsers[attr[6:].upper()] = func
+
self.clear()
def clear(self):