Add Permissions.all convenience (#107)
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled

This commit is contained in:
Slipstream 2025-06-15 18:49:43 -06:00 committed by GitHub
parent 3f7c286322
commit a222dec661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 0 deletions

View File

@ -57,6 +57,15 @@ class Permissions(IntFlag):
USE_EXTERNAL_SOUNDS = 1 << 45 USE_EXTERNAL_SOUNDS = 1 << 45
SEND_VOICE_MESSAGES = 1 << 46 SEND_VOICE_MESSAGES = 1 << 46
@classmethod
def all(cls) -> "Permissions":
"""Return a ``Permissions`` object with every permission bit enabled."""
value = 0
for perm in cls:
value |= perm.value
return cls(value)
def permissions_value(*perms: Permissions | int | Iterable[Permissions | int]) -> int: def permissions_value(*perms: Permissions | int | Iterable[Permissions | int]) -> int:
"""Return a combined integer value for multiple permissions.""" """Return a combined integer value for multiple permissions."""

View File

@ -15,6 +15,12 @@ from disagreement import Permissions
value = Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES value = Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES
``` ```
You can also get a bitmask containing **every** permission:
```python
all_perms = Permissions.all()
```
## Helper Functions ## Helper Functions
### ``permissions_value`` ### ``permissions_value``

View File

@ -32,3 +32,11 @@ def test_missing_permissions():
current, Permissions.SEND_MESSAGES, Permissions.MANAGE_MESSAGES current, Permissions.SEND_MESSAGES, Permissions.MANAGE_MESSAGES
) )
assert missing == [Permissions.MANAGE_MESSAGES] assert missing == [Permissions.MANAGE_MESSAGES]
def test_permissions_all():
all_value = Permissions.all()
union = Permissions(0)
for perm in Permissions:
union |= perm
assert all_value == union