Browse Source

Add upgraded Member to Message.mentions in case of no cache.

pull/2266/head
Rapptz 6 years ago
parent
commit
bbc50c92d0
  1. 11
      discord/member.py
  2. 14
      discord/message.py

11
discord/member.py

@ -192,6 +192,17 @@ class Member(discord.abc.Messageable, _BaseUser):
data['user'] = author._to_minimal_user_json()
return cls(data=data, guild=message.guild, state=message._state)
@classmethod
def _try_upgrade(cls, *, data, guild, state):
# A User object with a 'member' key
try:
member_data = data.pop('member')
except KeyError:
return state.store_user(member_data)
else:
member_data['user'] = data
return cls(data=member_data, guild=guild, state=state)
@classmethod
def _from_presence_update(cls, *, data, guild, state):
clone = cls(data=data, guild=guild, state=state)

14
discord/message.py

@ -412,16 +412,20 @@ class Message:
self.author = Member._from_message(message=self, data=member)
def _handle_mentions(self, mentions):
self.mentions = []
if self.guild is None:
self.mentions = [self._state.store_user(m) for m in mentions]
self.mentions = r = []
guild = self.guild
state = self._state
if guild is None:
self.mentions = [state.store_user(m) for m in mentions]
return
for mention in filter(None, mentions):
id_search = int(mention['id'])
member = self.guild.get_member(id_search)
member = guild.get_member(id_search)
if member is not None:
self.mentions.append(member)
r.append(member)
else:
r.append(Member._try_upgrade(data=mention, guild=guild, state=state))
def _handle_mention_roles(self, role_mentions):
self.role_mentions = []

Loading…
Cancel
Save