|
|
@ -153,11 +153,14 @@ class PrivateChannel(Snowflake, Protocol): |
|
|
|
class _Overwrites: |
|
|
|
__slots__ = ('id', 'allow', 'deny', 'type') |
|
|
|
|
|
|
|
ROLE = 0 |
|
|
|
MEMBER = 1 |
|
|
|
|
|
|
|
def __init__(self, **kwargs): |
|
|
|
self.id = kwargs.pop('id') |
|
|
|
self.allow = int(kwargs.pop('allow_new', 0)) |
|
|
|
self.deny = int(kwargs.pop('deny_new', 0)) |
|
|
|
self.type = sys.intern(kwargs.pop('type')) |
|
|
|
self.allow = int(kwargs.pop('allow', 0)) |
|
|
|
self.deny = int(kwargs.pop('deny', 0)) |
|
|
|
self.type = kwargs.pop('type') |
|
|
|
|
|
|
|
def _asdict(self): |
|
|
|
return { |
|
|
@ -167,6 +170,12 @@ class _Overwrites: |
|
|
|
'type': self.type, |
|
|
|
} |
|
|
|
|
|
|
|
def is_role(self) -> bool: |
|
|
|
return self.type == 0 |
|
|
|
|
|
|
|
def is_member(self) -> bool: |
|
|
|
return self.type == 1 |
|
|
|
|
|
|
|
|
|
|
|
class GuildChannel(Protocol): |
|
|
|
"""An ABC that details the common operations on a Discord guild channel. |
|
|
@ -289,9 +298,9 @@ class GuildChannel(Protocol): |
|
|
|
} |
|
|
|
|
|
|
|
if isinstance(target, Role): |
|
|
|
payload['type'] = 'role' |
|
|
|
payload['type'] = _Overwrites.ROLE |
|
|
|
else: |
|
|
|
payload['type'] = 'member' |
|
|
|
payload['type'] = _Overwrites.MEMBER |
|
|
|
|
|
|
|
perms.append(payload) |
|
|
|
options['permission_overwrites'] = perms |
|
|
@ -318,7 +327,7 @@ class GuildChannel(Protocol): |
|
|
|
overridden_id = int(overridden.pop('id')) |
|
|
|
self._overwrites.append(_Overwrites(id=overridden_id, **overridden)) |
|
|
|
|
|
|
|
if overridden['type'] == 'member': |
|
|
|
if overridden['type'] == _Overwrites.MEMBER: |
|
|
|
continue |
|
|
|
|
|
|
|
if overridden_id == everyone_id: |
|
|
@ -340,7 +349,7 @@ class GuildChannel(Protocol): |
|
|
|
their default values in the :attr:`~discord.Guild.roles` attribute.""" |
|
|
|
ret = [] |
|
|
|
g = self.guild |
|
|
|
for overwrite in filter(lambda o: o.type == 'role', self._overwrites): |
|
|
|
for overwrite in filter(lambda o: o.is_role(), self._overwrites): |
|
|
|
role = g.get_role(overwrite.id) |
|
|
|
if role is None: |
|
|
|
continue |
|
|
@ -376,9 +385,9 @@ class GuildChannel(Protocol): |
|
|
|
""" |
|
|
|
|
|
|
|
if isinstance(obj, User): |
|
|
|
predicate = lambda p: p.type == 'member' |
|
|
|
predicate = lambda p: p.is_member() |
|
|
|
elif isinstance(obj, Role): |
|
|
|
predicate = lambda p: p.type == 'role' |
|
|
|
predicate = lambda p: p.is_role() |
|
|
|
else: |
|
|
|
predicate = lambda p: True |
|
|
|
|
|
|
@ -409,9 +418,9 @@ class GuildChannel(Protocol): |
|
|
|
deny = Permissions(ow.deny) |
|
|
|
overwrite = PermissionOverwrite.from_pair(allow, deny) |
|
|
|
|
|
|
|
if ow.type == 'role': |
|
|
|
if ow.is_role(): |
|
|
|
target = self.guild.get_role(ow.id) |
|
|
|
elif ow.type == 'member': |
|
|
|
elif ow.is_member(): |
|
|
|
target = self.guild.get_member(ow.id) |
|
|
|
|
|
|
|
# TODO: There is potential data loss here in the non-chunked |
|
|
@ -513,7 +522,7 @@ class GuildChannel(Protocol): |
|
|
|
|
|
|
|
# Apply channel specific role permission overwrites |
|
|
|
for overwrite in remaining_overwrites: |
|
|
|
if overwrite.type == 'role' and roles.has(overwrite.id): |
|
|
|
if overwrite.is_role() and roles.has(overwrite.id): |
|
|
|
denies |= overwrite.deny |
|
|
|
allows |= overwrite.allow |
|
|
|
|
|
|
@ -521,7 +530,7 @@ class GuildChannel(Protocol): |
|
|
|
|
|
|
|
# Apply member specific permission overwrites |
|
|
|
for overwrite in remaining_overwrites: |
|
|
|
if overwrite.type == 'member' and overwrite.id == member.id: |
|
|
|
if overwrite.is_member() and overwrite.id == member.id: |
|
|
|
base.handle_overwrite(allow=overwrite.allow, deny=overwrite.deny) |
|
|
|
break |
|
|
|
|
|
|
@ -632,9 +641,9 @@ class GuildChannel(Protocol): |
|
|
|
http = self._state.http |
|
|
|
|
|
|
|
if isinstance(target, User): |
|
|
|
perm_type = 'member' |
|
|
|
perm_type = _Overwrites.MEMBER |
|
|
|
elif isinstance(target, Role): |
|
|
|
perm_type = 'role' |
|
|
|
perm_type = _Overwrites.ROLE |
|
|
|
else: |
|
|
|
raise InvalidArgument('target parameter must be either Member or Role') |
|
|
|
|
|
|
|