Browse Source

Make Client.edit_channel_permissions use PermissionOverwrite.

pull/245/merge
Rapptz 9 years ago
parent
commit
d7efc9778b
  1. 34
      discord/client.py

34
discord/client.py

@ -2288,7 +2288,7 @@ class Client:
return role return role
@asyncio.coroutine @asyncio.coroutine
def edit_channel_permissions(self, channel, target, *, allow=None, deny=None): def edit_channel_permissions(self, channel, target, overwrite=None):
"""|coro| """|coro|
Sets the channel specific permission overwrites for a target in the Sets the channel specific permission overwrites for a target in the
@ -2304,11 +2304,10 @@ class Client:
Setting allow and deny: :: Setting allow and deny: ::
allow = discord.Permissions.none() overwrite = discord.PermissionOverwrite()
deny = discord.Permissions.none() overwrite.read_messages = True
allow.mention_everyone = True overwrite.ban_members = False
deny.manage_messages = True yield from client.edit_channel_permissions(message.channel, message.author, overwrite)
yield from client.edit_channel_permissions(message.channel, message.author, allow=allow, deny=deny)
Parameters Parameters
----------- -----------
@ -2316,10 +2315,8 @@ class Client:
The channel to give the specific permissions for. The channel to give the specific permissions for.
target target
The :class:`Member` or :class:`Role` to overwrite permissions for. The :class:`Member` or :class:`Role` to overwrite permissions for.
allow : :class:`Permissions` overwrite: :class:`PermissionOverwrite`
The permissions to explicitly allow. (optional) The permissions to allow and deny to the target.
deny : :class:`Permissions`
The permissions to explicitly deny. (optional)
Raises Raises
------- -------
@ -2330,27 +2327,26 @@ class Client:
HTTPException HTTPException
Editing channel specific permissions failed. Editing channel specific permissions failed.
InvalidArgument InvalidArgument
The allow or deny arguments were not of type :class:`Permissions` The overwrite parameter was not of type :class:`PermissionOverwrite`
or the target type was not :class:`Role` or :class:`Member`. or the target type was not :class:`Role` or :class:`Member`.
""" """
allow = Permissions.none() if allow is None else allow overwrite = PermissionOverwrite() if overwrite is None else overwrite
deny = Permissions.none() if deny is None else deny
if not (isinstance(allow, Permissions) and isinstance(deny, Permissions)):
raise InvalidArgument('allow and deny parameters must be discord.Permissions')
deny = deny.value if not isinstance(overwrite, PermissionOverwrite):
allow = allow.value raise InvalidArgument('allow and deny parameters must be PermissionOverwrite')
allow, deny = overwrite.pair()
if isinstance(target, Member): if isinstance(target, Member):
perm_type = 'member' perm_type = 'member'
elif isinstance(target, Role): elif isinstance(target, Role):
perm_type = 'role' perm_type = 'role'
else: else:
raise InvalidArgument('target parameter must be either discord.Member or discord.Role') raise InvalidArgument('target parameter must be either Member or Role')
yield from self.http.edit_channel_permissions(channel.id, target.id, allow, deny, perm_type) yield from self.http.edit_channel_permissions(channel.id, target.id, allow.value, deny.value, perm_type)
@asyncio.coroutine @asyncio.coroutine
def delete_channel_permissions(self, channel, target): def delete_channel_permissions(self, channel, target):

Loading…
Cancel
Save