mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Change Permissions constants to be class method factories instead.
This commit is contained in:
parent
8b8312608c
commit
b94dffaf87
@ -133,7 +133,7 @@ class Channel(object):
|
||||
# and then the allowed.
|
||||
|
||||
if member.id == self.server.owner.id:
|
||||
return Permissions.ALL
|
||||
return Permissions.all()
|
||||
|
||||
default = self.server.get_default_role()
|
||||
base = deepcopy(default.permissions)
|
||||
@ -144,7 +144,7 @@ class Channel(object):
|
||||
|
||||
# Server-wide Manage Roles -> True for everything
|
||||
if base.can_manage_roles:
|
||||
base = Permissions.ALL
|
||||
base = Permissions.all()
|
||||
|
||||
member_role_ids = set(map(lambda r: r.id, member.roles))
|
||||
|
||||
@ -160,7 +160,8 @@ class Channel(object):
|
||||
|
||||
if base.can_manage_roles:
|
||||
# This point is essentially Channel-specific Manage Roles.
|
||||
base.value |= Permissions.ALL_CHANNEL.value
|
||||
tmp = Permissions.all_channel()
|
||||
base.value |= tmp.value
|
||||
|
||||
if self.is_default_channel():
|
||||
base.can_read_messages = True
|
||||
|
@ -80,6 +80,49 @@ class Permissions(object):
|
||||
def __init__(self, permissions=0, **kwargs):
|
||||
self.value = permissions
|
||||
|
||||
@classmethod
|
||||
def none(cls):
|
||||
"""A factory method that creates a :class:`Permission` with all
|
||||
permissions set to False."""
|
||||
return cls(0)
|
||||
|
||||
@classmethod
|
||||
def all(cls):
|
||||
"""A factory method that creates a :class:`Permission` with all
|
||||
permissions set to True."""
|
||||
return cls(0b00000011111100111111110000111111)
|
||||
|
||||
@classmethod
|
||||
def all_channel(cls):
|
||||
"""A :class:`Permission` with all channel-specific permissions set to
|
||||
True and the server-specific ones set to False. The server-specific
|
||||
permissions are currently:
|
||||
|
||||
- can_manager_server
|
||||
- can_kick_members
|
||||
- can_ban_members
|
||||
"""
|
||||
return cls(0b00000011111100111111110000011001)
|
||||
|
||||
@classmethod
|
||||
def general(cls):
|
||||
"""A factory method that creates a :class:`Permission` with all
|
||||
"General" permissions set to True."""
|
||||
return cls(0b00000000000000000000000000111111)
|
||||
|
||||
@classmethod
|
||||
def text(cls):
|
||||
"""A factory method that creates a :class:`Permission` with all
|
||||
"Text" permissions set to True."""
|
||||
return cls(0b00000000000000111111110000000000)
|
||||
|
||||
@classmethod
|
||||
def voice(cls):
|
||||
"""A factory method that creates a :class:`Permission` with all
|
||||
"Voice" permissions set to True."""
|
||||
return cls(0b00000011111100000000000000000000)
|
||||
|
||||
|
||||
def _bit(self, index):
|
||||
return bool((self.value >> index) & 1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user