diff options
| author | Rapptz <[email protected]> | 2016-06-01 21:06:04 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-06-01 21:06:04 -0400 |
| commit | c97e5a17e6947e3f171979a3e952572063583495 (patch) | |
| tree | a75e2c27d083945c6776bac1258aefb3c5fd06ee /discord/server.py | |
| parent | Clarify Role.position documentation. (diff) | |
| download | discord.py-c97e5a17e6947e3f171979a3e952572063583495.tar.xz discord.py-c97e5a17e6947e3f171979a3e952572063583495.zip | |
Update positions when a role is added or removed.
Diffstat (limited to 'discord/server.py')
| -rw-r--r-- | discord/server.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/discord/server.py b/discord/server.py index 62bd9ad6..30896ba9 100644 --- a/discord/server.py +++ b/discord/server.py @@ -136,6 +136,27 @@ class Server(Hashable): member._update_voice_state(voice_channel=channel, **data) return before, member + def _add_role(self, role): + # roles get added to the bottom (position 1, pos 0 is @everyone) + # so since self.roles has the @everyone role, we can't increment + # its position because it's stuck at position 0. Luckily x += False + # is equivalent to adding 0. So we cast the position to a bool and + # increment it. + for r in self.roles: + r.position += bool(r.position) + + self.roles.append(role) + + def _remove_role(self, role): + # this raises ValueError if it fails.. + self.roles.remove(role) + + # since it didn't, we can change the positions now + # basically the same as above except we only decrement + # the position if we're above the role we deleted. + for r in self.roles: + r.position -= r.position > role.position + def _from_data(self, guild): # according to Stan, this is always available even if the guild is unavailable # I don't have this guarantee when someone updates the server. |