Browse Source

Extra bits I forgot

pull/177/head
Zwork101 5 years ago
parent
commit
94b1b1e0fb
No known key found for this signature in database GPG Key ID: 259D6C0D5A9CCF67
  1. 83
      disco/types/channel.py
  2. 5
      setup.py

83
disco/types/channel.py

@ -50,6 +50,8 @@ class PermissionOverwrite(ChannelSubType):
All allowed permissions. All allowed permissions.
deny : :class:`disco.types.permissions.PermissionValue` deny : :class:`disco.types.permissions.PermissionValue`
All denied permissions. All denied permissions.
compiled : :class:`disco.types.permissions.PermissionValue`
All permissions, both allowed and denied
""" """
id = Field(snowflake) id = Field(snowflake)
type = Field(enum(PermissionOverwriteType)) type = Field(enum(PermissionOverwriteType))
@ -60,6 +62,27 @@ class PermissionOverwrite(ChannelSubType):
@classmethod @classmethod
def create_for_channel(cls, channel, entity, allow=0, deny=0): def create_for_channel(cls, channel, entity, allow=0, deny=0):
""""
Creates a permission overwrite
Generates a permission overwrite for a channel given the entity and the permission bitsets provided.
Parameters
---------
channel : :class:`disco.types.channel.Channel`
Channel to apply permission overwrite too
entity : :class:`disco.types.guild.Role` or :class:`disco.types.guild.GuildMember`
The role or member to provide or deny permissions too
allow : :class:`disco.types.permissions.Permissions`, optional
Permissions to allow the role or user for the channel
deny : :class:`disco.types.permissions.Permissions` optional
Permissions to deny the role or user for the channel
Returns
-------
:class:`disco.types.channel.PermissionOverwrite`
An instance of the overwrite that was created
"""
from disco.types.guild import Role from disco.types.guild import Role
ptype = PermissionOverwriteType.ROLE if isinstance(entity, Role) else PermissionOverwriteType.MEMBER ptype = PermissionOverwriteType.ROLE if isinstance(entity, Role) else PermissionOverwriteType.MEMBER
@ -80,6 +103,22 @@ class PermissionOverwrite(ChannelSubType):
return value return value
def save(self, **kwargs): def save(self, **kwargs):
"""
Send discord this permission overwrite
This method is used if you created a permission overwrite without uploading it.
For most use cases, use the create_for_channel classmethod instead.
Parameters
----------
kwargs
Extra arguments to provide channels_permissions_modify
Returns
-------
:class:`disco.types.channel.PermissionOverwrite`
Returns itself, no changes made
"""
self.client.api.channels_permissions_modify(self.channel_id, self.client.api.channels_permissions_modify(self.channel_id,
self.id, self.id,
self.allow.value or 0, self.allow.value or 0,
@ -89,6 +128,17 @@ class PermissionOverwrite(ChannelSubType):
return self return self
def delete(self, **kwargs): def delete(self, **kwargs):
"""
Delete permission overwrite
Removes this permission overwrite instance from it's channel. You can reverse this change with the save method.
Parameters
----------
kwargs
Extra arguments to provide channels_permissions_delete
"""
self.client.api.channels_permissions_delete(self.channel_id, self.id, **kwargs) self.client.api.channels_permissions_delete(self.channel_id, self.id, **kwargs)
@ -100,7 +150,7 @@ class Channel(SlottedModel, Permissible):
---------- ----------
id : snowflake id : snowflake
The channel ID. The channel ID.
guild_id : Optional[snowflake] guild_id : snowflake, optional
The guild id this channel is part of. The guild id this channel is part of.
name : str name : str
The channel's name. The channel's name.
@ -118,6 +168,10 @@ class Channel(SlottedModel, Permissible):
The type of this channel. The type of this channel.
overwrites : dict(snowflake, :class:`disco.types.channel.PermissionOverwrite`) overwrites : dict(snowflake, :class:`disco.types.channel.PermissionOverwrite`)
Channel permissions overwrites. Channel permissions overwrites.
mention : str
The channel's mention
guild : :class:`disco.types.guild.Guild`, optional
Guild this channel belongs to (or None if not applicable).
""" """
id = Field(snowflake) id = Field(snowflake)
guild_id = Field(snowflake) guild_id = Field(snowflake)
@ -152,6 +206,15 @@ class Channel(SlottedModel, Permissible):
""" """
Get the permissions a user has in the channel. Get the permissions a user has in the channel.
This method will first apply the user's permissions based on their roles and / or if they're the owner.
It will then overwrite those permissions with the channel's permission overwrites.
If the channel is a DM, the user is considered an administrator.
Parameters
----------
user : :class:`disco.types.user.User` or :class:`disco.types.guild.GuildMember`
A user-like instance of the ID of a user to get the permissions for
Returns Returns
------- -------
:class:`disco.types.permissions.PermissionValue` :class:`disco.types.permissions.PermissionValue`
@ -238,9 +301,6 @@ class Channel(SlottedModel, Permissible):
@cached_property @cached_property
def guild(self): def guild(self):
"""
Guild this channel belongs to (or None if not applicable).
"""
return self.client.state.guilds.get(self.guild_id) return self.client.state.guilds.get(self.guild_id)
@cached_property @cached_property
@ -252,8 +312,15 @@ class Channel(SlottedModel, Permissible):
def messages_iter(self, **kwargs): def messages_iter(self, **kwargs):
""" """
Creates message iterator
Creates a new `MessageIterator` for the channel with the given keyword Creates a new `MessageIterator` for the channel with the given keyword
arguments. arguments.
Parameters
----------
kwargs
Extra arguments to be passed into :class:`disco.types.channel.MessageIterator`
""" """
return MessageIterator(self.client, self, **kwargs) return MessageIterator(self.client, self, **kwargs)
@ -262,6 +329,10 @@ class Channel(SlottedModel, Permissible):
Attempts to fetch and return a `Message` from the message object Attempts to fetch and return a `Message` from the message object
or id. or id.
Arguments
---------
message : `Message` or snowflake
Returns Returns
------- -------
`Message` `Message`
@ -293,6 +364,10 @@ class Channel(SlottedModel, Permissible):
def get_pins(self): def get_pins(self):
""" """
Get pinned messages
Messages that have been pinned to this channel if any are returned
Returns Returns
------- -------
list(`Message`) list(`Message`)

5
setup.py

@ -20,7 +20,10 @@ extras_require = {
'wsaccel==0.6.2', 'wsaccel==0.6.2',
], ],
'sharding': ['gipc==0.6.0'], 'sharding': ['gipc==0.6.0'],
'docs': ['biblio==0.0.4'], 'docs': [
'sphinx==2.4.4',
'groundwork-sphinx-theme==1.1.1'
],
} }
setup( setup(

Loading…
Cancel
Save