Skip to content

Commit

Permalink
Added support for comparing PermissionOverwrites
Browse files Browse the repository at this point in the history
When trying to check if a specific permission overwrite is already set on a channel, it can be done by fetching the already existing overwrite and comparing it with a one you want to set. Comparing them directly wasn't possible before, and this small change allows for that.
Could be expanded for other comparison operators, not sure how it would work though.
  • Loading branch information
DevilXD authored and Rapptz committed Jan 29, 2019
1 parent ed76151 commit 9d92939
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions discord/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ class PermissionOverwrite:
+-----------+------------------------------------------+
| Operation | Description |
+===========+==========================================+
| x == y | Checks if two overwrites are equal. |
+-----------+------------------------------------------+
| x != y | Checks if two overwrites are not equal. |
+-----------+------------------------------------------+
| iter(x) | Returns an iterator of (perm, value) |
| | pairs. This allows this class to be used |
| | as an iterable in e.g. set/list/dict |
Expand All @@ -549,6 +553,9 @@ def __init__(self, **kwargs):

setattr(self, key, value)

def __eq__(self, other):
return self._values == other._values

def _set(self, key, value):
if value not in (True, None, False):
raise TypeError('Expected bool or NoneType, received {0.__class__.__name__}'.format(value))
Expand Down

0 comments on commit 9d92939

Please sign in to comment.