Browse Source

Implement Messageable for StageChannel

Fix #9248
pull/9264/head
Rapptz 2 years ago
parent
commit
da4651c97c
  1. 14
      discord/abc.py
  2. 205
      discord/channel.py
  3. 3
      discord/message.py

14
discord/abc.py

@ -83,7 +83,15 @@ if TYPE_CHECKING:
from .channel import CategoryChannel from .channel import CategoryChannel
from .embeds import Embed from .embeds import Embed
from .message import Message, MessageReference, PartialMessage from .message import Message, MessageReference, PartialMessage
from .channel import TextChannel, DMChannel, GroupChannel, PartialMessageable, VoiceChannel from .channel import (
TextChannel,
DMChannel,
GroupChannel,
PartialMessageable,
VocalGuildChannel,
VoiceChannel,
StageChannel,
)
from .threads import Thread from .threads import Thread
from .enums import InviteTarget from .enums import InviteTarget
from .ui.view import View from .ui.view import View
@ -97,7 +105,7 @@ if TYPE_CHECKING:
SnowflakeList, SnowflakeList,
) )
PartialMessageableChannel = Union[TextChannel, VoiceChannel, Thread, DMChannel, PartialMessageable] PartialMessageableChannel = Union[TextChannel, VoiceChannel, StageChannel, Thread, DMChannel, PartialMessageable]
MessageableChannel = Union[PartialMessageableChannel, GroupChannel] MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
SnowflakeTime = Union["Snowflake", datetime] SnowflakeTime = Union["Snowflake", datetime]
@ -118,7 +126,7 @@ async def _single_delete_strategy(messages: Iterable[Message], *, reason: Option
async def _purge_helper( async def _purge_helper(
channel: Union[Thread, TextChannel, VoiceChannel], channel: Union[Thread, TextChannel, VocalGuildChannel],
*, *,
limit: Optional[int] = 100, limit: Optional[int] = 100,
check: Callable[[Message], bool] = MISSING, check: Callable[[Message], bool] = MISSING,

205
discord/channel.py

@ -878,7 +878,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
before_timestamp = update_before(threads[-1]) before_timestamp = update_before(threads[-1])
class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable): class VocalGuildChannel(discord.abc.Messageable, discord.abc.Connectable, discord.abc.GuildChannel, Hashable):
__slots__ = ( __slots__ = (
'name', 'name',
'id', 'id',
@ -901,6 +901,9 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
self.id: int = int(data['id']) self.id: int = int(data['id'])
self._update(guild, data) self._update(guild, data)
async def _get_channel(self) -> Self:
return self
def _get_voice_client_key(self) -> Tuple[int, str]: def _get_voice_client_key(self) -> Tuple[int, str]:
return self.guild.id, 'guild_id' return self.guild.id, 'guild_id'
@ -988,103 +991,6 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
base.value &= ~denied.value base.value &= ~denied.value
return base return base
class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
"""Represents a Discord guild voice channel.
.. container:: operations
.. describe:: x == y
Checks if two channels are equal.
.. describe:: x != y
Checks if two channels are not equal.
.. describe:: hash(x)
Returns the channel's hash.
.. describe:: str(x)
Returns the channel's name.
Attributes
-----------
name: :class:`str`
The channel name.
guild: :class:`Guild`
The guild the channel belongs to.
id: :class:`int`
The channel ID.
nsfw: :class:`bool`
If the channel is marked as "not safe for work" or "age restricted".
.. versionadded:: 2.0
category_id: Optional[:class:`int`]
The category channel ID this channel belongs to, if applicable.
position: :class:`int`
The position in the channel list. This is a number that starts at 0. e.g. the
top channel is position 0.
bitrate: :class:`int`
The channel's preferred audio bitrate in bits per second.
user_limit: :class:`int`
The channel's limit for number of members that can be in a voice channel.
rtc_region: Optional[:class:`str`]
The region for the voice channel's voice communication.
A value of ``None`` indicates automatic voice region detection.
.. versionadded:: 1.7
.. versionchanged:: 2.0
The type of this attribute has changed to :class:`str`.
video_quality_mode: :class:`VideoQualityMode`
The camera video quality for the voice channel's participants.
.. versionadded:: 2.0
last_message_id: Optional[:class:`int`]
The last message ID of the message sent to this channel. It may
*not* point to an existing or valid message.
.. versionadded:: 2.0
slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages
in this channel. A value of ``0`` denotes that it is disabled.
Bots and users with :attr:`~Permissions.manage_channels` or
:attr:`~Permissions.manage_messages` bypass slowmode.
.. versionadded:: 2.2
"""
__slots__ = ()
def __repr__(self) -> str:
attrs = [
('id', self.id),
('name', self.name),
('rtc_region', self.rtc_region),
('position', self.position),
('bitrate', self.bitrate),
('video_quality_mode', self.video_quality_mode),
('user_limit', self.user_limit),
('category_id', self.category_id),
]
joined = ' '.join('%s=%r' % t for t in attrs)
return f'<{self.__class__.__name__} {joined}>'
async def _get_channel(self) -> Self:
return self
@property
def _scheduled_event_entity_type(self) -> Optional[EntityType]:
return EntityType.voice
@property
def type(self) -> Literal[ChannelType.voice]:
""":class:`ChannelType`: The channel's Discord type."""
return ChannelType.voice
@property @property
def last_message(self) -> Optional[Message]: def last_message(self) -> Optional[Message]:
"""Retrieves the last message from this channel in cache. """Retrieves the last message from this channel in cache.
@ -1129,7 +1035,7 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
from .message import PartialMessage from .message import PartialMessage
return PartialMessage(channel=self, id=message_id) return PartialMessage(channel=self, id=message_id) # type: ignore # VocalGuildChannel is an impl detail
async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None: async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None:
"""|coro| """|coro|
@ -1332,6 +1238,100 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar, reason=reason) data = await self._state.http.create_webhook(self.id, name=str(name), avatar=avatar, reason=reason)
return Webhook.from_state(data, state=self._state) return Webhook.from_state(data, state=self._state)
class VoiceChannel(VocalGuildChannel):
"""Represents a Discord guild voice channel.
.. container:: operations
.. describe:: x == y
Checks if two channels are equal.
.. describe:: x != y
Checks if two channels are not equal.
.. describe:: hash(x)
Returns the channel's hash.
.. describe:: str(x)
Returns the channel's name.
Attributes
-----------
name: :class:`str`
The channel name.
guild: :class:`Guild`
The guild the channel belongs to.
id: :class:`int`
The channel ID.
nsfw: :class:`bool`
If the channel is marked as "not safe for work" or "age restricted".
.. versionadded:: 2.0
category_id: Optional[:class:`int`]
The category channel ID this channel belongs to, if applicable.
position: :class:`int`
The position in the channel list. This is a number that starts at 0. e.g. the
top channel is position 0.
bitrate: :class:`int`
The channel's preferred audio bitrate in bits per second.
user_limit: :class:`int`
The channel's limit for number of members that can be in a voice channel.
rtc_region: Optional[:class:`str`]
The region for the voice channel's voice communication.
A value of ``None`` indicates automatic voice region detection.
.. versionadded:: 1.7
.. versionchanged:: 2.0
The type of this attribute has changed to :class:`str`.
video_quality_mode: :class:`VideoQualityMode`
The camera video quality for the voice channel's participants.
.. versionadded:: 2.0
last_message_id: Optional[:class:`int`]
The last message ID of the message sent to this channel. It may
*not* point to an existing or valid message.
.. versionadded:: 2.0
slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages
in this channel. A value of ``0`` denotes that it is disabled.
Bots and users with :attr:`~Permissions.manage_channels` or
:attr:`~Permissions.manage_messages` bypass slowmode.
.. versionadded:: 2.2
"""
__slots__ = ()
def __repr__(self) -> str:
attrs = [
('id', self.id),
('name', self.name),
('rtc_region', self.rtc_region),
('position', self.position),
('bitrate', self.bitrate),
('video_quality_mode', self.video_quality_mode),
('user_limit', self.user_limit),
('category_id', self.category_id),
]
joined = ' '.join('%s=%r' % t for t in attrs)
return f'<{self.__class__.__name__} {joined}>'
@property
def _scheduled_event_entity_type(self) -> Optional[EntityType]:
return EntityType.voice
@property
def type(self) -> Literal[ChannelType.voice]:
""":class:`ChannelType`: The channel's Discord type."""
return ChannelType.voice
@utils.copy_doc(discord.abc.GuildChannel.clone) @utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> VoiceChannel: async def clone(self, *, name: Optional[str] = None, reason: Optional[str] = None) -> VoiceChannel:
return await self._clone_impl({'bitrate': self.bitrate, 'user_limit': self.user_limit}, name=name, reason=reason) return await self._clone_impl({'bitrate': self.bitrate, 'user_limit': self.user_limit}, name=name, reason=reason)
@ -1358,6 +1358,7 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ..., overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
rtc_region: Optional[str] = ..., rtc_region: Optional[str] = ...,
video_quality_mode: VideoQualityMode = ..., video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
reason: Optional[str] = ..., reason: Optional[str] = ...,
) -> VoiceChannel: ) -> VoiceChannel:
... ...
@ -1492,6 +1493,11 @@ class StageChannel(VocalGuildChannel):
The camera video quality for the stage channel's participants. The camera video quality for the stage channel's participants.
.. versionadded:: 2.0 .. versionadded:: 2.0
last_message_id: Optional[:class:`int`]
The last message ID of the message sent to this channel. It may
*not* point to an existing or valid message.
.. versionadded:: 2.2
slowmode_delay: :class:`int` slowmode_delay: :class:`int`
The number of seconds a member must wait between sending messages The number of seconds a member must wait between sending messages
in this channel. A value of ``0`` denotes that it is disabled. in this channel. A value of ``0`` denotes that it is disabled.
@ -1665,6 +1671,7 @@ class StageChannel(VocalGuildChannel):
overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ..., overwrites: Mapping[OverwriteKeyT, PermissionOverwrite] = ...,
rtc_region: Optional[str] = ..., rtc_region: Optional[str] = ...,
video_quality_mode: VideoQualityMode = ..., video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
reason: Optional[str] = ..., reason: Optional[str] = ...,
) -> StageChannel: ) -> StageChannel:
... ...

3
discord/message.py

@ -737,6 +737,7 @@ class PartialMessage(Hashable):
if not isinstance(channel, PartialMessageable) and channel.type not in ( if not isinstance(channel, PartialMessageable) and channel.type not in (
ChannelType.text, ChannelType.text,
ChannelType.voice, ChannelType.voice,
ChannelType.stage_voice,
ChannelType.news, ChannelType.news,
ChannelType.private, ChannelType.private,
ChannelType.news_thread, ChannelType.news_thread,
@ -744,7 +745,7 @@ class PartialMessage(Hashable):
ChannelType.private_thread, ChannelType.private_thread,
): ):
raise TypeError( raise TypeError(
f'expected PartialMessageable, TextChannel, VoiceChannel, DMChannel or Thread not {type(channel)!r}' f'expected PartialMessageable, TextChannel, StageChannel, VoiceChannel, DMChannel or Thread not {type(channel)!r}'
) )
self.channel: MessageableChannel = channel self.channel: MessageableChannel = channel

Loading…
Cancel
Save