Add permission overwrites to GuildChannel.

This commit is contained in:
Rapptz
2016-12-31 00:27:12 -05:00
parent 6709979831
commit 633eacc982
2 changed files with 106 additions and 94 deletions

View File

@@ -1180,96 +1180,6 @@ class Client:
invite_id = self._resolve_invite(invite)
yield from self.http.delete_invite(invite_id)
@asyncio.coroutine
def edit_channel_permissions(self, channel, target, overwrite=None):
"""|coro|
Sets the channel specific permission overwrites for a target in the
specified :class:`Channel`.
The ``target`` parameter should either be a :class:`Member` or a
:class:`Role` that belongs to the channel's guild.
You must have the proper permissions to do this.
Examples
----------
Setting allow and deny: ::
overwrite = discord.PermissionOverwrite()
overwrite.read_messages = True
overwrite.ban_members = False
yield from client.edit_channel_permissions(message.channel, message.author, overwrite)
Parameters
-----------
channel : :class:`Channel`
The channel to give the specific permissions for.
target
The :class:`Member` or :class:`Role` to overwrite permissions for.
overwrite: :class:`PermissionOverwrite`
The permissions to allow and deny to the target.
Raises
-------
Forbidden
You do not have permissions to edit channel specific permissions.
NotFound
The channel specified was not found.
HTTPException
Editing channel specific permissions failed.
InvalidArgument
The overwrite parameter was not of type :class:`PermissionOverwrite`
or the target type was not :class:`Role` or :class:`Member`.
"""
overwrite = PermissionOverwrite() if overwrite is None else overwrite
if not isinstance(overwrite, PermissionOverwrite):
raise InvalidArgument('allow and deny parameters must be PermissionOverwrite')
allow, deny = overwrite.pair()
if isinstance(target, Member):
perm_type = 'member'
elif isinstance(target, Role):
perm_type = 'role'
else:
raise InvalidArgument('target parameter must be either Member or Role')
yield from self.http.edit_channel_permissions(channel.id, target.id, allow.value, deny.value, perm_type)
@asyncio.coroutine
def delete_channel_permissions(self, channel, target):
"""|coro|
Removes a channel specific permission overwrites for a target
in the specified :class:`Channel`.
The target parameter follows the same rules as :meth:`edit_channel_permissions`.
You must have the proper permissions to do this.
Parameters
----------
channel : :class:`Channel`
The channel to give the specific permissions for.
target
The :class:`Member` or :class:`Role` to overwrite permissions for.
Raises
------
Forbidden
You do not have permissions to delete channel specific permissions.
NotFound
The channel specified was not found.
HTTPException
Deleting channel specific permissions failed.
"""
yield from self.http.delete_channel_permissions(channel.id, target.id)
# Miscellaneous stuff
@asyncio.coroutine