Browse Source

Change permissions to remove the can_ prefix.

pull/74/head
Rapptz 9 years ago
parent
commit
5a1d7a2d94
  1. 20
      discord/channel.py
  2. 4
      discord/client.py
  3. 126
      discord/permissions.py
  4. 3
      docs/migrating.rst

20
discord/channel.py

@ -172,7 +172,7 @@ class Channel(Hashable):
base.value |= role.permissions.value
# Server-wide Manage Roles -> True for everything
if base.can_manage_roles:
if base.manage_roles:
base = Permissions.all()
member_role_ids = set(map(lambda r: r.id, member.roles))
@ -188,13 +188,13 @@ class Channel(Hashable):
if overwrite.type == 'member' and overwrite.id == member.id:
base.handle_overwrite(allow=overwrite.allow, deny=overwrite.deny)
if base.can_manage_roles:
if base.manage_roles:
# This point is essentially Channel-specific Manage Roles.
tmp = Permissions.all_channel()
base.value |= tmp.value
if self.is_default:
base.can_read_messages = True
base.read_messages = True
return base
@ -244,9 +244,9 @@ class PrivateChannel(Hashable):
This returns all the Text related permissions set to true except:
- can_send_tts_messages: You cannot send TTS messages in a PM.
- can_manage_messages: You cannot delete others messages in a PM.
- can_mention_everyone: There is no one to mention in a PM.
- send_tts_messages: You cannot send TTS messages in a PM.
- manage_messages: You cannot delete others messages in a PM.
- mention_everyone: There is no one to mention in a PM.
Parameters
-----------
@ -259,10 +259,10 @@ class PrivateChannel(Hashable):
The resolved permissions for the user.
"""
base = Permissions.TEXT
base.can_send_tts_messages = False
base.can_manage_messages = False
base.can_mention_everyone = False
base = Permissions.text()
base.send_tts_messages = False
base.manage_messages = False
base.mention_everyone = False
return base

4
discord/client.py

@ -2200,8 +2200,8 @@ class Client:
allow = discord.Permissions.none()
deny = discord.Permissions.none()
allow.can_mention_everyone = True
deny.can_manage_messages = True
allow.mention_everyone = True
deny.manage_messages = True
yield from client.edit_channel_permissions(message.channel, message.author, allow=allow, deny=deny)
Parameters

126
discord/permissions.py

@ -81,9 +81,9 @@ class Permissions:
True and the server-specific ones set to False. The server-specific
permissions are currently:
- can_manager_server
- can_kick_members
- can_ban_members
- manager_server
- kick_members
- ban_members
"""
return cls(0b00000011111100111111110000011001)
@ -133,187 +133,187 @@ class Permissions:
self.value = (self.value & ~deny) | allow
@property
def can_create_instant_invite(self):
def create_instant_invite(self):
"""Returns True if the user can create instant invites."""
return self._bit(0)
@can_create_instant_invite.setter
def can_create_instant_invite(self, value):
@create_instant_invite.setter
def create_instant_invite(self, value):
self._set(0, value)
@property
def can_kick_members(self):
def kick_members(self):
"""Returns True if the user can kick users from the server."""
return self._bit(1)
@can_kick_members.setter
def can_kick_members(self, value):
@kick_members.setter
def kick_members(self, value):
self._set(1, value)
@property
def can_ban_members(self):
def ban_members(self):
"""Returns True if a user can ban users from the server."""
return self._bit(2)
@can_ban_members.setter
def can_ban_members(self, value):
@ban_members.setter
def ban_members(self, value):
self._set(2, value)
@property
def can_manage_roles(self):
def manage_roles(self):
"""Returns True if a user can manage server roles. This role overrides all other permissions."""
return self._bit(3)
@can_manage_roles.setter
def can_manage_roles(self, value):
@manage_roles.setter
def manage_roles(self, value):
self._set(3, value)
@property
def can_manage_channels(self):
def manage_channels(self):
"""Returns True if a user can edit, delete, or create channels in the server."""
return self._bit(4)
@can_manage_channels.setter
def can_manage_channels(self, value):
@manage_channels.setter
def manage_channels(self, value):
self._set(4, value)
@property
def can_manage_server(self):
def manage_server(self):
"""Returns True if a user can edit server properties."""
return self._bit(5)
@can_manage_server.setter
def can_manage_server(self, value):
@manage_server.setter
def manage_server(self, value):
self._set(5, value)
# 4 unused
@property
def can_read_messages(self):
def read_messages(self):
"""Returns True if a user can read messages from all or specific text channels."""
return self._bit(10)
@can_read_messages.setter
def can_read_messages(self, value):
@read_messages.setter
def read_messages(self, value):
self._set(10, value)
@property
def can_send_messages(self):
def send_messages(self):
"""Returns True if a user can send messages from all or specific text channels."""
return self._bit(11)
@can_send_messages.setter
def can_send_messages(self, value):
@send_messages.setter
def send_messages(self, value):
self._set(11, value)
@property
def can_send_tts_messages(self):
def send_tts_messages(self):
"""Returns True if a user can send TTS messages from all or specific text channels."""
return self._bit(12)
@can_send_tts_messages.setter
def can_send_tts_messages(self, value):
@send_tts_messages.setter
def send_tts_messages(self, value):
self._set(12, value)
@property
def can_manage_messages(self):
def manage_messages(self):
"""Returns True if a user can delete messages from a text channel. Note that there are currently no ways to edit other people's messages."""
return self._bit(13)
@can_manage_messages.setter
def can_manage_messages(self, value):
@manage_messages.setter
def manage_messages(self, value):
self._set(13, value)
@property
def can_embed_links(self):
def embed_links(self):
"""Returns True if a user's messages will automatically be embedded by Discord."""
return self._bit(14)
@can_embed_links.setter
def can_embed_links(self, value):
@embed_links.setter
def embed_links(self, value):
self._set(14, value)
@property
def can_attach_files(self):
def attach_files(self):
"""Returns True if a user can send files in their messages."""
return self._bit(15)
@can_attach_files.setter
def can_attach_files(self, value):
@attach_files.setter
def attach_files(self, value):
self._set(15, value)
@property
def can_read_message_history(self):
def read_message_history(self):
"""Returns True if a user can read a text channel's previous messages."""
return self._bit(16)
@can_read_message_history.setter
def can_read_message_history(self, value):
@read_message_history.setter
def read_message_history(self, value):
self._set(16, value)
@property
def can_mention_everyone(self):
def mention_everyone(self):
"""Returns True if a user's @everyone will mention everyone in the text channel."""
return self._bit(17)
@can_mention_everyone.setter
def can_mention_everyone(self, value):
@mention_everyone.setter
def mention_everyone(self, value):
self._set(17, value)
# 2 unused
@property
def can_connect(self):
def connect(self):
"""Returns True if a user can connect to a voice channel."""
return self._bit(20)
@can_connect.setter
def can_connect(self, value):
@connect.setter
def connect(self, value):
self._set(20, value)
@property
def can_speak(self):
def speak(self):
"""Returns True if a user can speak in a voice channel."""
return self._bit(21)
@can_speak.setter
def can_speak(self, value):
@speak.setter
def speak(self, value):
self._set(21, value)
@property
def can_mute_members(self):
def mute_members(self):
"""Returns True if a user can mute other users."""
return self._bit(22)
@can_mute_members.setter
def can_mute_members(self, value):
@mute_members.setter
def mute_members(self, value):
self._set(22, value)
@property
def can_deafen_members(self):
def deafen_members(self):
"""Returns True if a user can deafen other users."""
return self._bit(23)
@can_deafen_members.setter
def can_deafen_members(self, value):
@deafen_members.setter
def deafen_members(self, value):
self._set(23, value)
@property
def can_move_members(self):
def move_members(self):
"""Returns True if a user can move users between other voice channels."""
return self._bit(24)
@can_move_members.setter
def can_move_members(self, value):
@move_members.setter
def move_members(self, value):
self._set(24, value)
@property
def can_use_voice_activation(self):
def use_voice_activation(self):
"""Returns True if a user can use voice activation in voice channels."""
return self._bit(25)
@can_use_voice_activation.setter
def can_use_voice_activation(self, value):
@use_voice_activation.setter
def use_voice_activation(self, value):
self._set(25, value)
# 6 unused

3
docs/migrating.rst

@ -213,6 +213,9 @@ Functions have been renamed.
| ``Client.set_channel_permissions`` | :meth:`Client.edit_channel_permissions` |
+------------------------------------+-------------------------------------------+
All the :class:`Permission` related attributes have been renamed and the `can_` prefix has been
dropped. So for example, ``can_manage_messages`` has become ``manage_messages``.
.. _migrating-kwargs:
Forced Keyword Arguments

Loading…
Cancel
Save