aboutsummaryrefslogtreecommitdiff
path: root/discord/server.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-06-01 21:06:04 -0400
committerRapptz <[email protected]>2016-06-01 21:06:04 -0400
commitc97e5a17e6947e3f171979a3e952572063583495 (patch)
treea75e2c27d083945c6776bac1258aefb3c5fd06ee /discord/server.py
parentClarify Role.position documentation. (diff)
downloaddiscord.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.py21
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.