diff options
| author | Rapptz <[email protected]> | 2016-12-17 14:00:34 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-12-17 14:00:34 -0500 |
| commit | c7946606f453feea7b52f2d68ab5b5c45271ef5c (patch) | |
| tree | 3a06aa9a9fb9d676b8ba111acc6337df6b2c2866 | |
| parent | Add support for partnered servers. Fixes #387. (diff) | |
| download | discord.py-c7946606f453feea7b52f2d68ab5b5c45271ef5c.tar.xz discord.py-c7946606f453feea7b52f2d68ab5b5c45271ef5c.zip | |
Add Channel.overwrites to get a channel's permission overwrites.
Fixes #414.
| -rw-r--r-- | discord/channel.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/discord/channel.py b/discord/channel.py index 54d90d44..95aaaea8 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -191,6 +191,34 @@ class Channel(Hashable): return PermissionOverwrite() + @property + def overwrites(self): + """Returns all of the channel's overwrites. + + This is returned as a list of two-element tuples containing the target, + which can be either a :class:`Role` or a :class:`Member` and the overwrite + as the second element as a :class:`PermissionOverwrite`. + + Returns + -------- + List[Tuple[Union[:class:`Role`, :class:`Member`], :class:`PermissionOverwrite`]]: + The channel's permission overwrites. + """ + ret = [] + for ow in self._permission_overwrites: + allow = Permissions(ow.allow) + deny = Permissions(ow.deny) + overwrite = PermissionOverwrite.from_pair(allow, deny) + + if ow.type == 'role': + # accidentally quadratic + target = utils.find(lambda r: r.id == ow.id, self.server.roles) + elif ow.type == 'member': + target = self.server.get_member(ow.id) + + ret.append((target, overwrite)) + return ret + def permissions_for(self, member): """Handles permission resolution for the current :class:`Member`. |