From ac6ba7c87840162d7af807c7e9c95d1b3988ab53 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Tue, 27 Feb 2024 20:34:19 -0600 Subject: [PATCH 01/31] feat: implement coice channel statuses --- discord/channel.py | 40 ++++++++++++++++++++++++++++++++++++++++ discord/http.py | 6 ++++++ discord/permissions.py | 13 +++++++++++-- discord/state.py | 22 ++++++++++++++++++++++ discord/types/channel.py | 1 + 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index afa6780515..85ed7274bf 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1522,17 +1522,32 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel): .. versionadded:: 2.5 flags: :class:`ChannelFlags` Extra features of the channel. + status: Optional[:class:`str`] + The channel's status, if set. .. versionadded:: 2.0 """ + def __init__( + self, + *, + state: ConnectionState, + guild: Guild, + data: VoiceChannelPayload, + ): + self.status: str | None = None + super().__init__(state=state, guild=guild, data=data) + def _update(self, guild: Guild, data: VoiceChannelPayload): super()._update(guild, data) + if data.get("status"): + self.status = data.get("status") def __repr__(self) -> str: attrs = [ ("id", self.id), ("name", self.name), + ("status", self.status), ("rtc_region", self.rtc_region), ("position", self.position), ("bitrate", self.bitrate), @@ -1955,6 +1970,31 @@ async def create_activity_invite( **kwargs, ) + async def set_status(self, status: str | None, *, reason=None) -> None: + """|coro| + + Sets the status of the voice channel. + + You must have the :attr:`~Permissions.set_voice_channel_status` permission to use this. + + Parameters + ---------- + status: Union[:class:`str`, None] + The new status. + reason: Optional[:class:`str`] + The reason for setting the status. Shows up on the audit log. + + Raises + ------ + Forbidden + You do not have proper permissions to set the status. + HTTPException + Setting the status failed. + """ + await self._state.http.set_voice_channel_status( + self.id, {"status": status}, reason=reason + ) + class StageChannel(discord.abc.Messageable, VocalGuildChannel): """Represents a Discord guild stage channel. diff --git a/discord/http.py b/discord/http.py index b5eadc031d..8dd725ef4e 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2185,6 +2185,12 @@ def move_member( guild_id=guild_id, user_id=user_id, channel_id=channel_id, reason=reason ) + def set_voice_channel_status( + self, channel_id: Snowflake, payload: Any, *, reason: str | None = None + ) -> Response[None]: + r = Route("PUT", "/channels/{channel_id}/voice-status", channel_id=channel_id) + return self.request(r, json=payload, reason=reason) + # Stage instance management def get_stage_instance( diff --git a/discord/permissions.py b/discord/permissions.py index e94e6c2116..75b71d57cd 100644 --- a/discord/permissions.py +++ b/discord/permissions.py @@ -180,7 +180,7 @@ def all(cls: type[P]) -> P: """A factory method that creates a :class:`Permissions` with all permissions set to ``True``. """ - return cls(0b11111111111111111111111111111111111111111) + return cls(0b1111111111111111111111111111111111111111111111111) @classmethod def all_channel(cls: type[P]) -> P: @@ -250,7 +250,7 @@ def voice(cls: type[P]) -> P: """A factory method that creates a :class:`Permissions` with all "Voice" permissions from the official Discord UI set to ``True``. """ - return cls(0b00000011111100000000001100000000) + return cls(0b1000000001000000000000011111100000000001100000000) @classmethod def stage(cls: type[P]) -> P: @@ -618,6 +618,14 @@ def send_voice_messages(self) -> int: """ return 1 << 46 + @flag_value + def set_voice_channel_status(self) -> int: + """:class:`bool`: Returns ``True`` if a member can set voice channel status. + + .. versionadded:: 2.5 + """ + return 1 << 48 + PO = TypeVar("PO", bound="PermissionOverwrite") @@ -736,6 +744,7 @@ class PermissionOverwrite: start_embedded_activities: bool | None moderate_members: bool | None send_voice_messages: bool | None + set_voice_channel_status: bool | None def __init__(self, **kwargs: bool | None): self._values: dict[str, bool | None] = {} diff --git a/discord/state.py b/discord/state.py index 011dd0e142..0a1d14a2f8 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1785,6 +1785,28 @@ def parse_voice_server_update(self, data) -> None: ) ) + def parse_voice_channel_status_update(self, data) -> None: + guild = self._get_guild(int(data["guild_id"])) + channel_id = int(data["id"]) + if guild is not None: + channel = guild.get_channel(channel_id) + if channel is not None: + old_status = channel.status + channel.status = data.get("status", None) + self.dispatch( + "voice_channel_status_update", channel, old_status, channel.status + ) + else: + _log.debug( + "VOICE_CHANNEL_STATUS_UPDATE referencing an unknown channel ID: %s. Discarding.", + channel_id, + ) + else: + _log.debug( + "VOICE_CHANNEL_STATUS_UPDATE referencing unknown guild ID: %s. Discarding.", + data["guild_id"], + ) + def parse_typing_start(self, data) -> None: raw = RawTypingEvent(data) diff --git a/discord/types/channel.py b/discord/types/channel.py index 79e7b9ebbf..0f4c044aed 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -108,6 +108,7 @@ class NewsChannel(_BaseGuildChannel, _TextChannelOptional): class VoiceChannel(_BaseGuildChannel): rtc_region: NotRequired[str | None] video_quality_mode: NotRequired[VideoQualityMode] + status: NotRequired[str | None] type: Literal[2] bitrate: int user_limit: int From d4686fed3d99c2d25629a2ae4bbfe7acd385b50d Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Tue, 27 Feb 2024 20:45:27 -0600 Subject: [PATCH 02/31] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48609d7988..c0561e6308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,6 +93,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) +- Added support for voice channel statuses + ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed From fb6b6076d70c1edb4e43abcbe2eea11f1f2f57a6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 02:46:08 +0000 Subject: [PATCH 03/31] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0561e6308..1478b0eecd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) -- Added support for voice channel statuses +- Added support for voice channel statuses ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed From 106069323fc63a680a5c6cf969ff4ad2a99af92e Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Tue, 27 Feb 2024 20:45:27 -0600 Subject: [PATCH 04/31] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48609d7988..c0561e6308 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,6 +93,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) +- Added support for voice channel statuses + ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed From 3207c21491127b87a4c7b3f78d4f6ec69fb0be11 Mon Sep 17 00:00:00 2001 From: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:57:29 -0600 Subject: [PATCH 05/31] chore: Apply suggestions from code review Co-authored-by: plun1331 Signed-off-by: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> --- CHANGELOG.md | 2 +- discord/channel.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1478b0eecd..d55d7e948d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) -- Added support for voice channel statuses +- Added support for voice channel statuses. ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed diff --git a/discord/channel.py b/discord/channel.py index 85ed7274bf..aad0680994 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1970,7 +1970,7 @@ async def create_activity_invite( **kwargs, ) - async def set_status(self, status: str | None, *, reason=None) -> None: + async def set_status(self, status: str | None, *, reason: str | None = None) -> None: """|coro| Sets the status of the voice channel. From 65c8ef2addfe47dd8571ee41a92939de2a88433a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 02:57:49 +0000 Subject: [PATCH 06/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/channel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/discord/channel.py b/discord/channel.py index aad0680994..44dacbaaf8 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1970,7 +1970,9 @@ async def create_activity_invite( **kwargs, ) - async def set_status(self, status: str | None, *, reason: str | None = None) -> None: + async def set_status( + self, status: str | None, *, reason: str | None = None + ) -> None: """|coro| Sets the status of the voice channel. From 5e4fe99884f6b384fc133b313b7541df2a7e5700 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:16:38 +0100 Subject: [PATCH 07/31] fix: payload --- discord/channel.py | 2 +- discord/http.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 44dacbaaf8..9525fa0025 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1994,7 +1994,7 @@ async def set_status( Setting the status failed. """ await self._state.http.set_voice_channel_status( - self.id, {"status": status}, reason=reason + self.id, status, reason=reason ) diff --git a/discord/http.py b/discord/http.py index 8dd725ef4e..acf0807a3b 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2186,8 +2186,9 @@ def move_member( ) def set_voice_channel_status( - self, channel_id: Snowflake, payload: Any, *, reason: str | None = None + self, channel_id: Snowflake, status: str | None, *, reason: str | None = None ) -> Response[None]: + payload = {"status": status} r = Route("PUT", "/channels/{channel_id}/voice-status", channel_id=channel_id) return self.request(r, json=payload, reason=reason) From a09470d5babf618c51cf6894108dbf9fe56e6381 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 03:17:03 +0000 Subject: [PATCH 08/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/channel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 9525fa0025..332368a394 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1993,9 +1993,7 @@ async def set_status( HTTPException Setting the status failed. """ - await self._state.http.set_voice_channel_status( - self.id, status, reason=reason - ) + await self._state.http.set_voice_channel_status(self.id, status, reason=reason) class StageChannel(discord.abc.Messageable, VocalGuildChannel): From 3d88511f6561ef3aa6bfcc857b510ea56a98ebd4 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:34:46 +0100 Subject: [PATCH 09/31] feat: raw_voice_channel_status_update --- discord/raw_models.py | 32 ++++++++++++++++++++++++++++++++ discord/state.py | 2 ++ discord/types/raw_models.py | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/discord/raw_models.py b/discord/raw_models.py index 79c8091d98..3c0b316640 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -56,6 +56,7 @@ ThreadMembersUpdateEvent, ThreadUpdateEvent, TypingEvent, + VoiceChannelStatusUpdateEvent, ) @@ -75,6 +76,7 @@ "AutoModActionExecutionEvent", "RawThreadMembersUpdateEvent", "RawAuditLogEntryEvent", + "RawVoiceChannelStatusUpdateEvent", ) @@ -441,6 +443,36 @@ def __init__(self, data: ThreadDeleteEvent) -> None: self.data: ThreadDeleteEvent = data +class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): + """Represents the payload for a :func:`on_raw_voice_channel_status_update` event. + + Attributes + ---------- + id: :class:`int` + The channel ID where the voice channel status update originated from. + guild_id: :class:`int` + The guild ID where the voice channel status update originated from. + status: Optional[:class:`str`] + The new new voice channel status. + data: :class:`dict` + The raw data sent by the `gateway `_. + + .. versionadded:: 2.5 + """ + + __slots__ = ("id", "guild_id", "status", "data") + + def __init__(self, data: VoiceChannelStatusUpdateEvent) -> None: + self.id: int = int(data["id"]) + self.guild_id: int = int(data["guild_id"]) + + try: + self.status: str | None = data["status"] + except KeyError: + self.guild_id: int | None = None + self.data: VoiceChannelStatusUpdateEvent = data + + class RawTypingEvent(_RawReprMixin): """Represents the payload for a :func:`on_raw_typing` event. diff --git a/discord/state.py b/discord/state.py index 0a1d14a2f8..5b9aea0e35 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1786,6 +1786,8 @@ def parse_voice_server_update(self, data) -> None: ) def parse_voice_channel_status_update(self, data) -> None: + raw = RawVoiceChannelStatusUpdateEvent(data) + self.dispatch("raw_voice_channel_status_update", raw) guild = self._get_guild(int(data["guild_id"])) channel_id = int(data["id"]) if guild is not None: diff --git a/discord/types/raw_models.py b/discord/types/raw_models.py index db2f5dde5f..73611e0525 100644 --- a/discord/types/raw_models.py +++ b/discord/types/raw_models.py @@ -131,6 +131,12 @@ class MemberRemoveEvent(TypedDict): user: User +class VoiceChannelStatusUpdateEvent(TypedDict): + id: Snowflake, + guild_id: Snowflake, + status: NotRequired[str] + + class ThreadMembersUpdateEvent(TypedDict): id: Snowflake guild_id: Snowflake From 35ad8c8a08ca39d5fbce3668ae36bcaa7f6d5063 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 03:35:12 +0000 Subject: [PATCH 10/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/raw_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 3c0b316640..d68a83e7e0 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -456,7 +456,7 @@ class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): The new new voice channel status. data: :class:`dict` The raw data sent by the `gateway `_. - + .. versionadded:: 2.5 """ From fa87ec02e8241df1acbc5c22c804c0f7af6d17ad Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:37:34 +0100 Subject: [PATCH 11/31] fuck me --- discord/raw_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 3c0b316640..22f90cf168 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -469,7 +469,7 @@ def __init__(self, data: VoiceChannelStatusUpdateEvent) -> None: try: self.status: str | None = data["status"] except KeyError: - self.guild_id: int | None = None + self.status: str | None = None self.data: VoiceChannelStatusUpdateEvent = data From f3a4bf9b2784c50f85cb96d313811e9b11892c74 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:40:18 +0100 Subject: [PATCH 12/31] REEEEEEE --- discord/types/raw_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/types/raw_models.py b/discord/types/raw_models.py index 73611e0525..de2b3fbf2b 100644 --- a/discord/types/raw_models.py +++ b/discord/types/raw_models.py @@ -132,8 +132,8 @@ class MemberRemoveEvent(TypedDict): class VoiceChannelStatusUpdateEvent(TypedDict): - id: Snowflake, - guild_id: Snowflake, + id: Snowflake + guild_id: Snowflake status: NotRequired[str] From 2f438e2fc2bd9da40ce60960f4b16a156597fcc4 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Tue, 27 Feb 2024 20:34:19 -0600 Subject: [PATCH 13/31] feat: implement coice channel statuses --- discord/channel.py | 40 ++++++++++++++++++++++++++++++++++++++++ discord/http.py | 6 ++++++ discord/permissions.py | 13 +++++++++++-- discord/state.py | 22 ++++++++++++++++++++++ discord/types/channel.py | 1 + 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index afa6780515..85ed7274bf 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1522,17 +1522,32 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel): .. versionadded:: 2.5 flags: :class:`ChannelFlags` Extra features of the channel. + status: Optional[:class:`str`] + The channel's status, if set. .. versionadded:: 2.0 """ + def __init__( + self, + *, + state: ConnectionState, + guild: Guild, + data: VoiceChannelPayload, + ): + self.status: str | None = None + super().__init__(state=state, guild=guild, data=data) + def _update(self, guild: Guild, data: VoiceChannelPayload): super()._update(guild, data) + if data.get("status"): + self.status = data.get("status") def __repr__(self) -> str: attrs = [ ("id", self.id), ("name", self.name), + ("status", self.status), ("rtc_region", self.rtc_region), ("position", self.position), ("bitrate", self.bitrate), @@ -1955,6 +1970,31 @@ async def create_activity_invite( **kwargs, ) + async def set_status(self, status: str | None, *, reason=None) -> None: + """|coro| + + Sets the status of the voice channel. + + You must have the :attr:`~Permissions.set_voice_channel_status` permission to use this. + + Parameters + ---------- + status: Union[:class:`str`, None] + The new status. + reason: Optional[:class:`str`] + The reason for setting the status. Shows up on the audit log. + + Raises + ------ + Forbidden + You do not have proper permissions to set the status. + HTTPException + Setting the status failed. + """ + await self._state.http.set_voice_channel_status( + self.id, {"status": status}, reason=reason + ) + class StageChannel(discord.abc.Messageable, VocalGuildChannel): """Represents a Discord guild stage channel. diff --git a/discord/http.py b/discord/http.py index b5eadc031d..8dd725ef4e 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2185,6 +2185,12 @@ def move_member( guild_id=guild_id, user_id=user_id, channel_id=channel_id, reason=reason ) + def set_voice_channel_status( + self, channel_id: Snowflake, payload: Any, *, reason: str | None = None + ) -> Response[None]: + r = Route("PUT", "/channels/{channel_id}/voice-status", channel_id=channel_id) + return self.request(r, json=payload, reason=reason) + # Stage instance management def get_stage_instance( diff --git a/discord/permissions.py b/discord/permissions.py index e94e6c2116..75b71d57cd 100644 --- a/discord/permissions.py +++ b/discord/permissions.py @@ -180,7 +180,7 @@ def all(cls: type[P]) -> P: """A factory method that creates a :class:`Permissions` with all permissions set to ``True``. """ - return cls(0b11111111111111111111111111111111111111111) + return cls(0b1111111111111111111111111111111111111111111111111) @classmethod def all_channel(cls: type[P]) -> P: @@ -250,7 +250,7 @@ def voice(cls: type[P]) -> P: """A factory method that creates a :class:`Permissions` with all "Voice" permissions from the official Discord UI set to ``True``. """ - return cls(0b00000011111100000000001100000000) + return cls(0b1000000001000000000000011111100000000001100000000) @classmethod def stage(cls: type[P]) -> P: @@ -618,6 +618,14 @@ def send_voice_messages(self) -> int: """ return 1 << 46 + @flag_value + def set_voice_channel_status(self) -> int: + """:class:`bool`: Returns ``True`` if a member can set voice channel status. + + .. versionadded:: 2.5 + """ + return 1 << 48 + PO = TypeVar("PO", bound="PermissionOverwrite") @@ -736,6 +744,7 @@ class PermissionOverwrite: start_embedded_activities: bool | None moderate_members: bool | None send_voice_messages: bool | None + set_voice_channel_status: bool | None def __init__(self, **kwargs: bool | None): self._values: dict[str, bool | None] = {} diff --git a/discord/state.py b/discord/state.py index 011dd0e142..0a1d14a2f8 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1785,6 +1785,28 @@ def parse_voice_server_update(self, data) -> None: ) ) + def parse_voice_channel_status_update(self, data) -> None: + guild = self._get_guild(int(data["guild_id"])) + channel_id = int(data["id"]) + if guild is not None: + channel = guild.get_channel(channel_id) + if channel is not None: + old_status = channel.status + channel.status = data.get("status", None) + self.dispatch( + "voice_channel_status_update", channel, old_status, channel.status + ) + else: + _log.debug( + "VOICE_CHANNEL_STATUS_UPDATE referencing an unknown channel ID: %s. Discarding.", + channel_id, + ) + else: + _log.debug( + "VOICE_CHANNEL_STATUS_UPDATE referencing unknown guild ID: %s. Discarding.", + data["guild_id"], + ) + def parse_typing_start(self, data) -> None: raw = RawTypingEvent(data) diff --git a/discord/types/channel.py b/discord/types/channel.py index 79e7b9ebbf..0f4c044aed 100644 --- a/discord/types/channel.py +++ b/discord/types/channel.py @@ -108,6 +108,7 @@ class NewsChannel(_BaseGuildChannel, _TextChannelOptional): class VoiceChannel(_BaseGuildChannel): rtc_region: NotRequired[str | None] video_quality_mode: NotRequired[VideoQualityMode] + status: NotRequired[str | None] type: Literal[2] bitrate: int user_limit: int From 786d8616e8f8f66fac0af230d2f360c67a8db783 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Tue, 27 Feb 2024 20:45:27 -0600 Subject: [PATCH 14/31] chore: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bfbc36a62..e9476de54d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,6 +93,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) +- Added support for voice channel statuses + ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed From b5ba2b9a522eed9fee8e22a69210bda7471c5990 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 02:46:08 +0000 Subject: [PATCH 15/31] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9476de54d..b777d47f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) -- Added support for voice channel statuses +- Added support for voice channel statuses ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed From 549fa56e27ead8f2b55818915f93cc07640b61d7 Mon Sep 17 00:00:00 2001 From: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:57:29 -0600 Subject: [PATCH 16/31] chore: Apply suggestions from code review Co-authored-by: plun1331 Signed-off-by: Icebluewolf <44532864+Icebluewolf@users.noreply.github.com> --- CHANGELOG.md | 2 +- discord/channel.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b777d47f12..d0923c07b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,7 +93,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2342](https://github.com/Pycord-Development/pycord/pull/2342)) - Added `invitable` and `slowmode_delay` to `Thread` creation methods. ([#2350](https://github.com/Pycord-Development/pycord/pull/2350)) -- Added support for voice channel statuses +- Added support for voice channel statuses. ([#2368](https://github.com/Pycord-Development/pycord/pull/2368)) ### Changed diff --git a/discord/channel.py b/discord/channel.py index 85ed7274bf..aad0680994 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1970,7 +1970,7 @@ async def create_activity_invite( **kwargs, ) - async def set_status(self, status: str | None, *, reason=None) -> None: + async def set_status(self, status: str | None, *, reason: str | None = None) -> None: """|coro| Sets the status of the voice channel. From 8d86cb648b865dd4cfa72fbd083c977e6844e242 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 02:57:49 +0000 Subject: [PATCH 17/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/channel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/discord/channel.py b/discord/channel.py index aad0680994..44dacbaaf8 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1970,7 +1970,9 @@ async def create_activity_invite( **kwargs, ) - async def set_status(self, status: str | None, *, reason: str | None = None) -> None: + async def set_status( + self, status: str | None, *, reason: str | None = None + ) -> None: """|coro| Sets the status of the voice channel. From fa7894f044f59df39d56e076ae5409ade7954a99 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:16:38 +0100 Subject: [PATCH 18/31] fix: payload --- discord/channel.py | 2 +- discord/http.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 44dacbaaf8..9525fa0025 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1994,7 +1994,7 @@ async def set_status( Setting the status failed. """ await self._state.http.set_voice_channel_status( - self.id, {"status": status}, reason=reason + self.id, status, reason=reason ) diff --git a/discord/http.py b/discord/http.py index 8dd725ef4e..acf0807a3b 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2186,8 +2186,9 @@ def move_member( ) def set_voice_channel_status( - self, channel_id: Snowflake, payload: Any, *, reason: str | None = None + self, channel_id: Snowflake, status: str | None, *, reason: str | None = None ) -> Response[None]: + payload = {"status": status} r = Route("PUT", "/channels/{channel_id}/voice-status", channel_id=channel_id) return self.request(r, json=payload, reason=reason) From 7972c8efd6b58cdfbd6e707a9df785311b628e25 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 03:17:03 +0000 Subject: [PATCH 19/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/channel.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 9525fa0025..332368a394 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1993,9 +1993,7 @@ async def set_status( HTTPException Setting the status failed. """ - await self._state.http.set_voice_channel_status( - self.id, status, reason=reason - ) + await self._state.http.set_voice_channel_status(self.id, status, reason=reason) class StageChannel(discord.abc.Messageable, VocalGuildChannel): From 5c85b07bd000c398c2f4460dfea7fdc21511d466 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:34:46 +0100 Subject: [PATCH 20/31] feat: raw_voice_channel_status_update --- discord/raw_models.py | 32 ++++++++++++++++++++++++++++++++ discord/state.py | 2 ++ discord/types/raw_models.py | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/discord/raw_models.py b/discord/raw_models.py index 79c8091d98..3c0b316640 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -56,6 +56,7 @@ ThreadMembersUpdateEvent, ThreadUpdateEvent, TypingEvent, + VoiceChannelStatusUpdateEvent, ) @@ -75,6 +76,7 @@ "AutoModActionExecutionEvent", "RawThreadMembersUpdateEvent", "RawAuditLogEntryEvent", + "RawVoiceChannelStatusUpdateEvent", ) @@ -441,6 +443,36 @@ def __init__(self, data: ThreadDeleteEvent) -> None: self.data: ThreadDeleteEvent = data +class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): + """Represents the payload for a :func:`on_raw_voice_channel_status_update` event. + + Attributes + ---------- + id: :class:`int` + The channel ID where the voice channel status update originated from. + guild_id: :class:`int` + The guild ID where the voice channel status update originated from. + status: Optional[:class:`str`] + The new new voice channel status. + data: :class:`dict` + The raw data sent by the `gateway `_. + + .. versionadded:: 2.5 + """ + + __slots__ = ("id", "guild_id", "status", "data") + + def __init__(self, data: VoiceChannelStatusUpdateEvent) -> None: + self.id: int = int(data["id"]) + self.guild_id: int = int(data["guild_id"]) + + try: + self.status: str | None = data["status"] + except KeyError: + self.guild_id: int | None = None + self.data: VoiceChannelStatusUpdateEvent = data + + class RawTypingEvent(_RawReprMixin): """Represents the payload for a :func:`on_raw_typing` event. diff --git a/discord/state.py b/discord/state.py index 0a1d14a2f8..5b9aea0e35 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1786,6 +1786,8 @@ def parse_voice_server_update(self, data) -> None: ) def parse_voice_channel_status_update(self, data) -> None: + raw = RawVoiceChannelStatusUpdateEvent(data) + self.dispatch("raw_voice_channel_status_update", raw) guild = self._get_guild(int(data["guild_id"])) channel_id = int(data["id"]) if guild is not None: diff --git a/discord/types/raw_models.py b/discord/types/raw_models.py index db2f5dde5f..73611e0525 100644 --- a/discord/types/raw_models.py +++ b/discord/types/raw_models.py @@ -131,6 +131,12 @@ class MemberRemoveEvent(TypedDict): user: User +class VoiceChannelStatusUpdateEvent(TypedDict): + id: Snowflake, + guild_id: Snowflake, + status: NotRequired[str] + + class ThreadMembersUpdateEvent(TypedDict): id: Snowflake guild_id: Snowflake From 225185510602a98ba3a2980f339414c3fd0ee8a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 03:35:12 +0000 Subject: [PATCH 21/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/raw_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 3c0b316640..d68a83e7e0 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -456,7 +456,7 @@ class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): The new new voice channel status. data: :class:`dict` The raw data sent by the `gateway `_. - + .. versionadded:: 2.5 """ From 07ba832615c046260e19bd821d9d4c5b524b0d66 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:37:34 +0100 Subject: [PATCH 22/31] fuck me --- discord/raw_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index d68a83e7e0..14d37fadae 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -469,7 +469,7 @@ def __init__(self, data: VoiceChannelStatusUpdateEvent) -> None: try: self.status: str | None = data["status"] except KeyError: - self.guild_id: int | None = None + self.status: str | None = None self.data: VoiceChannelStatusUpdateEvent = data From 17ae14b9a64dc3e042d35df3a1b468ea27b01a0b Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:40:18 +0100 Subject: [PATCH 23/31] REEEEEEE --- discord/types/raw_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/types/raw_models.py b/discord/types/raw_models.py index 73611e0525..de2b3fbf2b 100644 --- a/discord/types/raw_models.py +++ b/discord/types/raw_models.py @@ -132,8 +132,8 @@ class MemberRemoveEvent(TypedDict): class VoiceChannelStatusUpdateEvent(TypedDict): - id: Snowflake, - guild_id: Snowflake, + id: Snowflake + guild_id: Snowflake status: NotRequired[str] From c165c808be62f46b96d90695dbb81ec3f5a825da Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 04:58:26 +0100 Subject: [PATCH 24/31] intent for this is unknown atm --- docs/api/events.rst | 21 +++++++++++++++++++++ docs/api/models.rst | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/docs/api/events.rst b/docs/api/events.rst index 8a0b76d13b..bd0cc01b2e 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -1299,3 +1299,24 @@ Typing :param payload: The raw typing payload. :type payload: :class:`RawTypingEvent` + + +Voice Channel Status Update +--------------------------- +.. function:: on_voice_channel_status_update(channel, old_status, status) + + Called when someone updates a voice channel status. + + :param channel: The channel where the voice channel status update originated from. + :type channel: :class:`GuildChannel` + :param old_status: The old voice channel status. + :type old_status: Optional[:class:`str`] + :param status: The new voice channel status. + :type status: Optional[:class:`str`] + +.. function:: on_raw_voice_channel_status_update(payload) + + Called when someone updates a voice channels status. + + :param payload: The raw voice channel status update payload. + :type payload: :class:`RawVoiceChannelStatusUpdateEvent` diff --git a/docs/api/models.rst b/docs/api/models.rst index 4fce609baf..5fec2f0dd0 100644 --- a/docs/api/models.rst +++ b/docs/api/models.rst @@ -556,6 +556,11 @@ Events .. autoclass:: RawAuditLogEntryEvent() :members: +.. attributetable:: RawVoiceChannelStatusUpdateEvent + +.. autoclass:: RawVoiceChannelStatusUpdateEvent() + :members: + Webhooks From 0bed18d6652411397aa386a2c39e611dc8ce0e65 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 05:04:58 +0100 Subject: [PATCH 25/31] fix: abc.GuildChannel --- docs/api/events.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/events.rst b/docs/api/events.rst index bd0cc01b2e..fe84f009db 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -1308,7 +1308,7 @@ Voice Channel Status Update Called when someone updates a voice channel status. :param channel: The channel where the voice channel status update originated from. - :type channel: :class:`GuildChannel` + :type channel: :class:`abc.GuildChannel` :param old_status: The old voice channel status. :type old_status: Optional[:class:`str`] :param status: The new voice channel status. From e3943a6102df5283edbcbb7835f10c25561af6aa Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 05:07:11 +0100 Subject: [PATCH 26/31] fix: versionadded --- discord/raw_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 14d37fadae..13d1e09174 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -445,6 +445,8 @@ def __init__(self, data: ThreadDeleteEvent) -> None: class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): """Represents the payload for a :func:`on_raw_voice_channel_status_update` event. + + .. versionadded:: 2.5 Attributes ---------- @@ -456,8 +458,6 @@ class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): The new new voice channel status. data: :class:`dict` The raw data sent by the `gateway `_. - - .. versionadded:: 2.5 """ __slots__ = ("id", "guild_id", "status", "data") From 14c304b4c295e816b40ae276766bf5953718d0a0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 28 Feb 2024 04:07:36 +0000 Subject: [PATCH 27/31] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/raw_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 13d1e09174..0f7db4fb0e 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -445,7 +445,7 @@ def __init__(self, data: ThreadDeleteEvent) -> None: class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): """Represents the payload for a :func:`on_raw_voice_channel_status_update` event. - + .. versionadded:: 2.5 Attributes From 41bb87becc9adfe40f21049c759eee43aeb15d35 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 28 Feb 2024 05:14:32 +0100 Subject: [PATCH 28/31] bleh --- discord/raw_models.py | 2 +- docs/api/events.rst | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/discord/raw_models.py b/discord/raw_models.py index 0f7db4fb0e..873c1fe0bd 100644 --- a/discord/raw_models.py +++ b/discord/raw_models.py @@ -444,7 +444,7 @@ def __init__(self, data: ThreadDeleteEvent) -> None: class RawVoiceChannelStatusUpdateEvent(_RawReprMixin): - """Represents the payload for a :func:`on_raw_voice_channel_status_update` event. + """Represents the payload for an :func:`on_raw_voice_channel_status_update` event. .. versionadded:: 2.5 diff --git a/docs/api/events.rst b/docs/api/events.rst index fe84f009db..ba4cbbd4be 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -1307,6 +1307,8 @@ Voice Channel Status Update Called when someone updates a voice channel status. + .. versionadded:: 2.5 + :param channel: The channel where the voice channel status update originated from. :type channel: :class:`abc.GuildChannel` :param old_status: The old voice channel status. @@ -1318,5 +1320,7 @@ Voice Channel Status Update Called when someone updates a voice channels status. + .. versionadded:: 2.5 + :param payload: The raw voice channel status update payload. :type payload: :class:`RawVoiceChannelStatusUpdateEvent` From 48584249694d78ea6c60e58615c09dd512176f2f Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Wed, 28 Feb 2024 08:15:29 +0300 Subject: [PATCH 29/31] docs: update docstring --- discord/channel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 332368a394..2586e3eed7 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -1520,11 +1520,13 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel): :attr:`~Permissions.manage_messages` bypass slowmode. .. versionadded:: 2.5 - flags: :class:`ChannelFlags` - Extra features of the channel. status: Optional[:class:`str`] The channel's status, if set. + .. versionadded:: 2.5 + flags: :class:`ChannelFlags` + Extra features of the channel. + .. versionadded:: 2.0 """ From 8a3d10b333170dec993895f53c82889df474e0e5 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Wed, 28 Feb 2024 07:22:44 -0600 Subject: [PATCH 30/31] docs: Use conventional event args --- docs/api/events.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/events.rst b/docs/api/events.rst index ba4cbbd4be..b85ec87bfb 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -1311,10 +1311,10 @@ Voice Channel Status Update :param channel: The channel where the voice channel status update originated from. :type channel: :class:`abc.GuildChannel` - :param old_status: The old voice channel status. - :type old_status: Optional[:class:`str`] - :param status: The new voice channel status. - :type status: Optional[:class:`str`] + :param before: The old voice channel status. + :type before: Optional[:class:`str`] + :param after: The new voice channel status. + :type after: Optional[:class:`str`] .. function:: on_raw_voice_channel_status_update(payload) From 23bddc8b5535931ce58e35de37d9fef8cfb4bc39 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Wed, 28 Feb 2024 07:28:29 -0600 Subject: [PATCH 31/31] docs: Use conventional event args again --- docs/api/events.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/events.rst b/docs/api/events.rst index b85ec87bfb..25edc139b0 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -1303,7 +1303,7 @@ Typing Voice Channel Status Update --------------------------- -.. function:: on_voice_channel_status_update(channel, old_status, status) +.. function:: on_voice_channel_status_update(channel, before, after) Called when someone updates a voice channel status.