aboutsummaryrefslogtreecommitdiff
path: root/discord/message.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-11-23 06:02:27 -0500
committerRapptz <[email protected]>2020-11-23 06:02:27 -0500
commitf174365d332793b2541cc55fb08dc3087956af2d (patch)
treed9478277053f4d65aea9be03830c0b4786959411 /discord/message.py
parentDon't store a user cache if there's no member intent or cache is off (diff)
downloaddiscord.py-f174365d332793b2541cc55fb08dc3087956af2d.tar.xz
discord.py-f174365d332793b2541cc55fb08dc3087956af2d.zip
Ensure member key is not overwritten by author key in MESSAGE_UPDATE
This also coerces the older message to take the member data from the newer message so the types are not incompatible. Fix #5999
Diffstat (limited to 'discord/message.py')
-rw-r--r--discord/message.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/discord/message.py b/discord/message.py
index e28bb8ae..7c255b91 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -243,11 +243,15 @@ class MessageReference:
def flatten_handlers(cls):
prefix = len('_handle_')
- cls._HANDLERS = {
- key[prefix:]: value
+ handlers = [
+ (key[prefix:], value)
for key, value in cls.__dict__.items()
- if key.startswith('_handle_')
- }
+ if key.startswith('_handle_') and key != '_handle_member'
+ ]
+
+ # store _handle_member last
+ handlers.append(('member', cls._handle_member))
+ cls._HANDLERS = handlers
cls._CACHED_SLOTS = [
attr for attr in cls.__slots__ if attr.startswith('_cs_')
]
@@ -452,10 +456,13 @@ class Message(Hashable):
return reaction
def _update(self, data):
- handlers = self._HANDLERS
- for key, value in data.items():
+ # In an update scheme, 'author' key has to be handled before 'member'
+ # otherwise they overwrite each other which is undesirable.
+ # Since there's no good way to do this we have to iterate over every
+ # handler rather than iterating over the keys which is a little slower
+ for key, handler in self._HANDLERS:
try:
- handler = handlers[key]
+ value = data[key]
except KeyError:
continue
else: