diff options
| author | Rapptz <[email protected]> | 2017-07-07 17:53:38 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-07-07 17:53:38 -0400 |
| commit | c2544b910142c65d27bbb9c4973e8eafb42bb641 (patch) | |
| tree | f571371aa9758a14affb66a31ad37f59f1fbaab6 | |
| parent | Hide constructor for objects that shouldn't be created by users. (diff) | |
| download | discord.py-c2544b910142c65d27bbb9c4973e8eafb42bb641.tar.xz discord.py-c2544b910142c65d27bbb9c4973e8eafb42bb641.zip | |
Handle everyone role having top priority in permission resolution.
In Discord, if the @everyone role has an explicit allow but a later
role has an explicit deny, the permission is denied rather than allowed
despite the fact that on Discord, allows have a higher priority than
denies.
This is because the @everyone role is supposed to be the first role to
be applied, while the rest could be applied in an aggregate fashion.
Fixes #630.
| -rw-r--r-- | discord/abc.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/discord/abc.py b/discord/abc.py index 29bc65b3..785b81ff 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -380,12 +380,23 @@ class GuildChannel: if base.administrator: return Permissions.all() + # Apply @everyone allow/deny first since it's special + try: + maybe_everyone = self._overwrites[0] + if maybe_everyone.id == self.guild.id: + base.handle_overwrite(allow=maybe_everyone.allow, deny=maybe_everyone.deny) + remaining_overwrites = self._overwrites[1:] + else: + remaining_overwrites = self._overwrites + except IndexError: + remaining_overwrites = self._overwrites + member_role_ids = set(map(lambda r: r.id, member.roles)) denies = 0 allows = 0 # Apply channel specific role permission overwrites - for overwrite in self._overwrites: + for overwrite in remaining_overwrites: if overwrite.type == 'role' and overwrite.id in member_role_ids: denies |= overwrite.deny allows |= overwrite.allow @@ -393,7 +404,7 @@ class GuildChannel: base.handle_overwrite(allow=allows, deny=denies) # Apply member specific permission overwrites - for overwrite in self._overwrites: + for overwrite in remaining_overwrites: if overwrite.type == 'member' and overwrite.id == member.id: base.handle_overwrite(allow=overwrite.allow, deny=overwrite.deny) break |