Browse Source

various changes; prepare for scheduled event support

pull/10109/head
dolfies 3 years ago
parent
commit
332e408658
  1. 6
      discord/audit_logs.py
  2. 14
      discord/channel.py
  3. 19
      discord/enums.py
  4. 37
      discord/flags.py
  5. 5
      discord/guild.py
  6. 2
      discord/role.py
  7. 14
      discord/stage_instance.py
  8. 5
      discord/threads.py

6
discord/audit_logs.py

@ -146,7 +146,7 @@ def _enum_transformer(enum: Type[T]) -> Callable[[AuditLogEntry, int], T]:
return _transform return _transform
def _transform_type(entry: AuditLogEntry, data: Union[int]) -> Union[enums.ChannelType, enums.StickerType]: def _transform_type(entry: AuditLogEntry, data: int) -> Union[enums.ChannelType, enums.StickerType]:
if entry.action.name.startswith('sticker_'): if entry.action.name.startswith('sticker_'):
return enums.try_enum(enums.StickerType, data) return enums.try_enum(enums.StickerType, data)
else: else:
@ -206,7 +206,7 @@ class AuditLogChanges:
'region': (None, _enum_transformer(enums.VoiceRegion)), 'region': (None, _enum_transformer(enums.VoiceRegion)),
'rtc_region': (None, _enum_transformer(enums.VoiceRegion)), 'rtc_region': (None, _enum_transformer(enums.VoiceRegion)),
'video_quality_mode': (None, _enum_transformer(enums.VideoQualityMode)), 'video_quality_mode': (None, _enum_transformer(enums.VideoQualityMode)),
'privacy_level': (None, _enum_transformer(enums.StagePrivacyLevel)), 'privacy_level': (None, _enum_transformer(enums.PrivacyLevel)),
'format_type': (None, _enum_transformer(enums.StickerFormatType)), 'format_type': (None, _enum_transformer(enums.StickerFormatType)),
'type': (None, _transform_type), 'type': (None, _transform_type),
} }
@ -257,7 +257,7 @@ class AuditLogChanges:
setattr(self.after, attr, after) setattr(self.after, attr, after)
# Add an alias # Add aliases
if hasattr(self.after, 'colour'): if hasattr(self.after, 'colour'):
self.after.color = self.after.colour self.after.color = self.after.colour
self.before.color = self.before.colour self.before.color = self.before.colour

14
discord/channel.py

@ -44,7 +44,7 @@ import datetime
import discord.abc import discord.abc
from .calls import PrivateCall, GroupCall from .calls import PrivateCall, GroupCall
from .permissions import PermissionOverwrite, Permissions from .permissions import PermissionOverwrite, Permissions
from .enums import ChannelType, StagePrivacyLevel, try_enum, VoiceRegion, VideoQualityMode from .enums import ChannelType, PrivacyLevel, try_enum, VoiceRegion, VideoQualityMode
from .mixins import Hashable from .mixins import Hashable
from .object import Object from .object import Object
from . import utils from . import utils
@ -657,7 +657,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
The type of thread to create. If a ``message`` is passed then this parameter The type of thread to create. If a ``message`` is passed then this parameter
is ignored, as a thread created with a message is always a public thread. is ignored, as a thread created with a message is always a public thread.
By default this creates a private thread if this is ``None``. By default this creates a private thread if this is ``None``.
reason: :class:`str` reason: Optional[:class:`str`]
The reason for creating a new thread. Shows up on the audit log. The reason for creating a new thread. Shows up on the audit log.
Raises Raises
@ -1115,7 +1115,7 @@ class StageChannel(VocalGuildChannel):
return utils.get(self.guild.stage_instances, channel_id=self.id) return utils.get(self.guild.stage_instances, channel_id=self.id)
async def create_instance( async def create_instance(
self, *, topic: str, privacy_level: StagePrivacyLevel = MISSING, reason: Optional[str] = None self, *, topic: str, privacy_level: PrivacyLevel = MISSING, reason: Optional[str] = None
) -> StageInstance: ) -> StageInstance:
"""|coro| """|coro|
@ -1130,9 +1130,9 @@ class StageChannel(VocalGuildChannel):
----------- -----------
topic: :class:`str` topic: :class:`str`
The stage instance's topic. The stage instance's topic.
privacy_level: :class:`StagePrivacyLevel` privacy_level: :class:`PrivacyLevel`
The stage instance's privacy level. Defaults to :attr:`StagePrivacyLevel.guild_only`. The stage instance's privacy level. Defaults to :attr:`PrivacyLevel.guild_only`.
reason: :class:`str` reason: Optional[:class:`str`]
The reason the stage instance was created. Shows up on the audit log. The reason the stage instance was created. Shows up on the audit log.
Raises Raises
@ -1153,7 +1153,7 @@ class StageChannel(VocalGuildChannel):
payload: Dict[str, Any] = {'channel_id': self.id, 'topic': topic} payload: Dict[str, Any] = {'channel_id': self.id, 'topic': topic}
if privacy_level is not MISSING: if privacy_level is not MISSING:
if not isinstance(privacy_level, StagePrivacyLevel): if not isinstance(privacy_level, PrivacyLevel):
raise InvalidArgument('privacy_level field must be of type PrivacyLevel') raise InvalidArgument('privacy_level field must be of type PrivacyLevel')
payload['privacy_level'] = privacy_level.value payload['privacy_level'] = privacy_level.value

19
discord/enums.py

@ -51,7 +51,7 @@ __all__ = (
'VideoQualityMode', 'VideoQualityMode',
'ComponentType', 'ComponentType',
'ButtonStyle', 'ButtonStyle',
'StagePrivacyLevel', 'PrivacyLevel',
'InteractionType', 'InteractionType',
'NSFWLevel', 'NSFWLevel',
'RelationshipType', 'RelationshipType',
@ -72,6 +72,8 @@ __all__ = (
'StoreApplicationState', 'StoreApplicationState',
'RPCApplicationState', 'RPCApplicationState',
'InviteType', 'InviteType',
'ScheduledEventStatus',
'ScheduledEventEntityType',
) )
@ -748,12 +750,25 @@ class ButtonStyle(Enum):
return self.value return self.value
class StagePrivacyLevel(Enum): class PrivacyLevel(Enum):
public = 1 public = 1
closed = 2 closed = 2
guild_only = 2 guild_only = 2
class ScheduledEventEntityType(Enum):
stage_instance = 1
voice = 2
external = 3
class ScheduledEventStatus(Enum):
scheduled = 1
active = 2
completed = 3
canceled = 4
class NSFWLevel(Enum, comparable=True): class NSFWLevel(Enum, comparable=True):
default = 0 default = 0
explicit = 1 explicit = 1

37
discord/flags.py

@ -281,7 +281,7 @@ class MessageFlags(BaseFlags):
@flag_value @flag_value
def urgent(self): def urgent(self):
""":class:`bool`: Returns ``True`` if the source message is an urgent message. """:class:`bool`: Returns ``True`` if the message is an urgent message.
An urgent message is one sent by Discord Trust and Safety. An urgent message is one sent by Discord Trust and Safety.
""" """
@ -289,7 +289,7 @@ class MessageFlags(BaseFlags):
@flag_value @flag_value
def has_thread(self): def has_thread(self):
""":class:`bool`: Returns ``True`` if the source message is associated with a thread. """:class:`bool`: Returns ``True`` if the message is associated with a thread.
.. versionadded:: 2.0 .. versionadded:: 2.0
""" """
@ -297,12 +297,43 @@ class MessageFlags(BaseFlags):
@flag_value @flag_value
def ephemeral(self): def ephemeral(self):
""":class:`bool`: Returns ``True`` if the source message is ephemeral. """:class:`bool`: Returns ``True`` if the message is ephemeral.
.. versionadded:: 2.0 .. versionadded:: 2.0
""" """
return 64 return 64
@flag_value
def loading(self):
""":class:`bool`: Returns ``True`` if the message is a deferred
interaction response and has a "bot is thinking" response.
.. versionadded:: 2.0
"""
return 128
@flag_value
def failed_to_mention_some_roles_in_thread(self):
""":class:`bool`: Returns ``True`` if Discord failed to add some
mentioned members to the thread.
There is an alias for this called :attr:`failed_to_mention_roles`.
.. versionadded:: 2.0
"""
return 256
@alias_flag_value
def failed_to_mention_roles(self):
""":class:`bool`: Returns ``True`` if the source message failed to
mention some roles and add their members to the thread.
This is an alias of :attr:`failed_to_mention_some_roles_in_thread`.
.. versionadded:: 2.0
"""
return 256
@fill_with_flags() @fill_with_flags()
class PublicUserFlags(BaseFlags): class PublicUserFlags(BaseFlags):

5
discord/guild.py

@ -1379,7 +1379,6 @@ class Guild(Hashable):
splash: Optional[bytes] = MISSING, splash: Optional[bytes] = MISSING,
discovery_splash: Optional[bytes] = MISSING, discovery_splash: Optional[bytes] = MISSING,
community: bool = MISSING, community: bool = MISSING,
region: Optional[Union[str, VoiceRegion]] = MISSING,
afk_channel: Optional[VoiceChannel] = MISSING, afk_channel: Optional[VoiceChannel] = MISSING,
owner: Snowflake = MISSING, owner: Snowflake = MISSING,
afk_timeout: int = MISSING, afk_timeout: int = MISSING,
@ -2200,11 +2199,9 @@ class Guild(Hashable):
""" """
payload = { payload = {
'name': name, 'name': name,
'description': description or '',
} }
if description:
payload['description'] = description
try: try:
emoji = unicodedata.name(emoji) emoji = unicodedata.name(emoji)
except TypeError: except TypeError:

2
discord/role.py

@ -311,6 +311,8 @@ class Role(Hashable):
@property @property
def mention(self) -> str: def mention(self) -> str:
""":class:`str`: Returns a string that allows you to mention a role.""" """:class:`str`: Returns a string that allows you to mention a role."""
if self.id == self.guild.id:
return '@everyone'
return f'<@&{self.id}>' return f'<@&{self.id}>'
@property @property

14
discord/stage_instance.py

@ -29,7 +29,7 @@ from typing import Optional, TYPE_CHECKING
from .utils import MISSING, cached_slot_property from .utils import MISSING, cached_slot_property
from .mixins import Hashable from .mixins import Hashable
from .errors import InvalidArgument from .errors import InvalidArgument
from .enums import StagePrivacyLevel, try_enum from .enums import PrivacyLevel, try_enum
__all__ = ( __all__ = (
'StageInstance', 'StageInstance',
@ -71,7 +71,7 @@ class StageInstance(Hashable):
The ID of the channel that the stage instance is running in. The ID of the channel that the stage instance is running in.
topic: :class:`str` topic: :class:`str`
The topic of the stage instance. The topic of the stage instance.
privacy_level: :class:`StagePrivacyLevel` privacy_level: :class:`PrivacyLevel`
The privacy level of the stage instance. The privacy level of the stage instance.
discoverable_disabled: :class:`bool` discoverable_disabled: :class:`bool`
Whether discoverability for the stage instance is disabled. Whether discoverability for the stage instance is disabled.
@ -97,7 +97,7 @@ class StageInstance(Hashable):
self.id: int = int(data['id']) self.id: int = int(data['id'])
self.channel_id: int = int(data['channel_id']) self.channel_id: int = int(data['channel_id'])
self.topic: str = data['topic'] self.topic: str = data['topic']
self.privacy_level: StagePrivacyLevel = try_enum(StagePrivacyLevel, data['privacy_level']) self.privacy_level: PrivacyLevel = try_enum(PrivacyLevel, data.get('privacy_level', 2))
self.discoverable_disabled: bool = data.get('discoverable_disabled', False) self.discoverable_disabled: bool = data.get('discoverable_disabled', False)
def __repr__(self) -> str: def __repr__(self) -> str:
@ -115,9 +115,9 @@ class StageInstance(Hashable):
return self._state.get_channel(self.channel_id) # type: ignore return self._state.get_channel(self.channel_id) # type: ignore
def is_public(self) -> bool: def is_public(self) -> bool:
return self.privacy_level is StagePrivacyLevel.public return self.privacy_level is PrivacyLevel.public
async def edit(self, *, topic: str = MISSING, privacy_level: StagePrivacyLevel = MISSING, reason: Optional[str] = None) -> None: async def edit(self, *, topic: str = MISSING, privacy_level: PrivacyLevel = MISSING, reason: Optional[str] = None) -> None:
"""|coro| """|coro|
Edits the stage instance. Edits the stage instance.
@ -129,7 +129,7 @@ class StageInstance(Hashable):
----------- -----------
topic: :class:`str` topic: :class:`str`
The stage instance's new topic. The stage instance's new topic.
privacy_level: :class:`StagePrivacyLevel` privacy_level: :class:`PrivacyLevel`
The stage instance's new privacy level. The stage instance's new privacy level.
reason: :class:`str` reason: :class:`str`
The reason the stage instance was edited. Shows up on the audit log. The reason the stage instance was edited. Shows up on the audit log.
@ -149,7 +149,7 @@ class StageInstance(Hashable):
payload['topic'] = topic payload['topic'] = topic
if privacy_level is not MISSING: if privacy_level is not MISSING:
if not isinstance(privacy_level, StagePrivacyLevel): if not isinstance(privacy_level, PrivacyLevel):
raise InvalidArgument('privacy_level field must be of type PrivacyLevel') raise InvalidArgument('privacy_level field must be of type PrivacyLevel')
payload['privacy_level'] = privacy_level.value payload['privacy_level'] = privacy_level.value

5
discord/threads.py

@ -505,6 +505,7 @@ class Thread(Messageable, Hashable):
invitable: bool = MISSING, invitable: bool = MISSING,
slowmode_delay: int = MISSING, slowmode_delay: int = MISSING,
auto_archive_duration: ThreadArchiveDuration = MISSING, auto_archive_duration: ThreadArchiveDuration = MISSING,
reason: Optional[str] = None,
) -> Thread: ) -> Thread:
"""|coro| """|coro|
@ -534,6 +535,8 @@ class Thread(Messageable, Hashable):
slowmode_delay: :class:`int` slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this thread, in seconds. Specifies the slowmode rate limit for user in this thread, in seconds.
A value of ``0`` disables slowmode. The maximum value possible is ``21600``. A value of ``0`` disables slowmode. The maximum value possible is ``21600``.
reason: Optional[:class:`str`]
The reason for editing the thread. Shows up on the audit log.
Raises Raises
------- -------
@ -628,7 +631,7 @@ class Thread(Messageable, Hashable):
Parameters Parameters
----------- -----------
user: :class:`abc.Snowflake` user: :class:`abc.Snowflake`
The user to add to the thread. The user to remove from the thread.
Raises Raises
------- -------

Loading…
Cancel
Save