mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-12 16:59:50 +00:00
Sort roles by hierarchy rather than by ID.
This commit is contained in:
parent
ae9d73474d
commit
e8d273cf8c
@ -155,19 +155,15 @@ class Member(User):
|
||||
There is an alias for this under ``color``.
|
||||
"""
|
||||
|
||||
default_colour = Colour.default()
|
||||
roles = self.roles[1:] # remove @everyone
|
||||
|
||||
# highest order of the colour is the one that gets rendered.
|
||||
# if the highest is the default colour then the next one with a colour
|
||||
# is chosen instead
|
||||
if self.roles:
|
||||
roles = sorted(self.roles, key=lambda r: r.position, reverse=True)
|
||||
for role in roles:
|
||||
if role.colour == default_colour:
|
||||
continue
|
||||
else:
|
||||
return role.colour
|
||||
|
||||
return default_colour
|
||||
for role in reversed(roles):
|
||||
if role.colour.value:
|
||||
return role.colour
|
||||
return Colour.default()
|
||||
|
||||
color = colour
|
||||
|
||||
@ -197,10 +193,7 @@ class Member(User):
|
||||
hierarchy chain.
|
||||
"""
|
||||
|
||||
if self.roles:
|
||||
roles = sorted(self.roles, reverse=True)
|
||||
return roles[0]
|
||||
return None
|
||||
return self.roles[-1]
|
||||
|
||||
@property
|
||||
def server_permissions(self):
|
||||
|
@ -410,7 +410,7 @@ class ConnectionState:
|
||||
if role is not None:
|
||||
roles.append(role)
|
||||
|
||||
data['roles'] = sorted(roles, key=lambda r: int(r.id))
|
||||
data['roles'] = sorted(roles)
|
||||
return Member(server=server, **data)
|
||||
|
||||
def parse_guild_member_add(self, data):
|
||||
@ -463,7 +463,7 @@ class ConnectionState:
|
||||
member.roles.append(role)
|
||||
|
||||
# sort the roles by ID since they can be "randomised"
|
||||
member.roles.sort(key=lambda r: int(r.id))
|
||||
member.roles.sort()
|
||||
self.dispatch('member_update', old_member, member)
|
||||
|
||||
def parse_guild_emojis_update(self, data):
|
||||
|
Loading…
x
Reference in New Issue
Block a user