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``.
|
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.
|
# 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
|
# if the highest is the default colour then the next one with a colour
|
||||||
# is chosen instead
|
# is chosen instead
|
||||||
if self.roles:
|
for role in reversed(roles):
|
||||||
roles = sorted(self.roles, key=lambda r: r.position, reverse=True)
|
if role.colour.value:
|
||||||
for role in roles:
|
return role.colour
|
||||||
if role.colour == default_colour:
|
return Colour.default()
|
||||||
continue
|
|
||||||
else:
|
|
||||||
return role.colour
|
|
||||||
|
|
||||||
return default_colour
|
|
||||||
|
|
||||||
color = colour
|
color = colour
|
||||||
|
|
||||||
@ -197,10 +193,7 @@ class Member(User):
|
|||||||
hierarchy chain.
|
hierarchy chain.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.roles:
|
return self.roles[-1]
|
||||||
roles = sorted(self.roles, reverse=True)
|
|
||||||
return roles[0]
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def server_permissions(self):
|
def server_permissions(self):
|
||||||
|
@ -410,7 +410,7 @@ class ConnectionState:
|
|||||||
if role is not None:
|
if role is not None:
|
||||||
roles.append(role)
|
roles.append(role)
|
||||||
|
|
||||||
data['roles'] = sorted(roles, key=lambda r: int(r.id))
|
data['roles'] = sorted(roles)
|
||||||
return Member(server=server, **data)
|
return Member(server=server, **data)
|
||||||
|
|
||||||
def parse_guild_member_add(self, data):
|
def parse_guild_member_add(self, data):
|
||||||
@ -463,7 +463,7 @@ class ConnectionState:
|
|||||||
member.roles.append(role)
|
member.roles.append(role)
|
||||||
|
|
||||||
# sort the roles by ID since they can be "randomised"
|
# 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)
|
self.dispatch('member_update', old_member, member)
|
||||||
|
|
||||||
def parse_guild_emojis_update(self, data):
|
def parse_guild_emojis_update(self, data):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user