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
This commit is contained in:
parent
7a3a571e0a
commit
f174365d33
@ -243,11 +243,15 @@ class MessageReference:
|
|||||||
|
|
||||||
def flatten_handlers(cls):
|
def flatten_handlers(cls):
|
||||||
prefix = len('_handle_')
|
prefix = len('_handle_')
|
||||||
cls._HANDLERS = {
|
handlers = [
|
||||||
key[prefix:]: value
|
(key[prefix:], value)
|
||||||
for key, value in cls.__dict__.items()
|
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 = [
|
cls._CACHED_SLOTS = [
|
||||||
attr for attr in cls.__slots__ if attr.startswith('_cs_')
|
attr for attr in cls.__slots__ if attr.startswith('_cs_')
|
||||||
]
|
]
|
||||||
@ -452,10 +456,13 @@ class Message(Hashable):
|
|||||||
return reaction
|
return reaction
|
||||||
|
|
||||||
def _update(self, data):
|
def _update(self, data):
|
||||||
handlers = self._HANDLERS
|
# In an update scheme, 'author' key has to be handled before 'member'
|
||||||
for key, value in data.items():
|
# 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:
|
try:
|
||||||
handler = handlers[key]
|
value = data[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -526,6 +526,9 @@ class ConnectionState:
|
|||||||
raw.cached_message = older_message
|
raw.cached_message = older_message
|
||||||
self.dispatch('raw_message_edit', raw)
|
self.dispatch('raw_message_edit', raw)
|
||||||
message._update(data)
|
message._update(data)
|
||||||
|
# Coerce the `after` parameter to take the new updated Member
|
||||||
|
# ref: #5999
|
||||||
|
older_message.author = message.author
|
||||||
self.dispatch('message_edit', older_message, message)
|
self.dispatch('message_edit', older_message, message)
|
||||||
else:
|
else:
|
||||||
self.dispatch('raw_message_edit', raw)
|
self.dispatch('raw_message_edit', raw)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user