diff --git a/disco/types/permissions.py b/disco/types/permissions.py index 2554b5c..6246fbe 100644 --- a/disco/types/permissions.py +++ b/disco/types/permissions.py @@ -40,6 +40,9 @@ class PermissionValue(object): __slots__ = ['value'] def __init__(self, value=0): + if isinstance(value, PermissionValue): + value = value.value + self.value = value def can(self, *perms): diff --git a/tests/types/permissions.py b/tests/types/permissions.py index 4e83743..e5be66f 100644 --- a/tests/types/permissions.py +++ b/tests/types/permissions.py @@ -26,3 +26,17 @@ def test_permission_value_mutation(): no_perms.send_messages = True assert no_perms.can(Permissions.SEND_MESSAGES) + + +def test_permission_value_accepts_permission_value(): + perms = PermissionValue(Permissions.ADMINISTRATOR) + + new_perms = PermissionValue(perms) + assert new_perms.administrator + + assert not new_perms.manage_channels + new_perms.add(PermissionValue(Permissions.MANAGE_CHANNELS)) + assert new_perms.manage_channels + + new_perms.sub(PermissionValue(Permissions.MANAGE_CHANNELS)) + assert not new_perms.manage_channels