From e5f0576ef938869d05dfbe3d3002d2ce4c479e24 Mon Sep 17 00:00:00 2001 From: Nova <110734810+novanai@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:25:31 +0100 Subject: [PATCH 1/5] support text in stage channels --- hikari/channels.py | 10 +++++++++- hikari/impl/entity_factory.py | 4 ++++ tests/hikari/impl/test_entity_factory.py | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hikari/channels.py b/hikari/channels.py index 75d3cde6b6..7c7519d6a0 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1367,7 +1367,7 @@ class GuildVoiceChannel(PermissibleGuildChannel, TextableGuildChannel): @attrs.define(hash=True, kw_only=True, weakref_slot=False) -class GuildStageChannel(PermissibleGuildChannel): +class GuildStageChannel(PermissibleGuildChannel, TextableGuildChannel): """Represents a stage channel.""" bitrate: int = attrs.field(eq=False, hash=False, repr=True) @@ -1387,6 +1387,14 @@ class GuildStageChannel(PermissibleGuildChannel): If this is `0`, then assume no limit. """ + last_message_id: typing.Optional[snowflakes.Snowflake] = attrs.field(eq=False, hash=False, repr=False) + """The ID of the last message sent in this channel. + + .. warning:: + This might point to an invalid or deleted message. Do not assume that + this will always be valid. + """ + @typing.final class ForumSortOrderType(int, enums.Enum): diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index 031cfe1146..d939ca4e55 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -1173,6 +1173,9 @@ def deserialize_guild_stage_channel( snowflakes.Snowflake(overwrite["id"]): self.deserialize_permission_overwrite(overwrite) for overwrite in payload["permission_overwrites"] } + last_message_id = ( + snowflakes.Snowflake(msg_id) if (msg_id := payload.get("last_message_id")) is not None else None + ) return channel_models.GuildStageChannel( app=self._app, id=channel_fields.id, @@ -1186,6 +1189,7 @@ def deserialize_guild_stage_channel( bitrate=int(payload["bitrate"]), user_limit=int(payload["user_limit"]), position=int(payload["position"]), + last_message_id=last_message_id, ) def deserialize_guild_forum_channel( diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 1706e82006..894e3a6322 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -1999,6 +1999,7 @@ def guild_stage_channel_payload(self, permission_overwrite_payload): "user_limit": 3, "rtc_region": "euoo", "parent_id": "543", + "last_message_id": "1000101", } def test_deserialize_guild_stage_channel( @@ -2018,6 +2019,7 @@ def test_deserialize_guild_stage_channel( assert voice_channel.region == "euoo" assert voice_channel.bitrate == 64000 assert voice_channel.user_limit == 3 + assert voice_channel.last_message_id == 1000101 assert isinstance(voice_channel, channel_models.GuildStageChannel) def test_deserialize_guild_stage_channel_with_null_fields(self, entity_factory_impl): @@ -2034,6 +2036,7 @@ def test_deserialize_guild_stage_channel_with_null_fields(self, entity_factory_i "user_limit": 3, "rtc_region": None, "type": 6, + "last_message_id": None, } ) assert voice_channel.parent_id is None From c51533b51e7fd1e4e5c3c035cacec9cbda1dda85 Mon Sep 17 00:00:00 2001 From: Nova <110734810+novanai@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:30:41 +0100 Subject: [PATCH 2/5] Add changelog --- changes/1653.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1653.bugfix.md diff --git a/changes/1653.bugfix.md b/changes/1653.bugfix.md new file mode 100644 index 0000000000..071fa106e7 --- /dev/null +++ b/changes/1653.bugfix.md @@ -0,0 +1 @@ +Add support for text in stage channels \ No newline at end of file From f107644807b848b88b2253056dc3f4f1a11dcd12 Mon Sep 17 00:00:00 2001 From: Nova <110734810+novanai@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:36:03 +0100 Subject: [PATCH 3/5] fix failing reformat-code session --- changes/1653.bugfix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/1653.bugfix.md b/changes/1653.bugfix.md index 071fa106e7..67d9e11546 100644 --- a/changes/1653.bugfix.md +++ b/changes/1653.bugfix.md @@ -1 +1 @@ -Add support for text in stage channels \ No newline at end of file +Add support for text in stage channels From 0afcf9694dda2297a0b4c0cc07acf0aac0ab34f2 Mon Sep 17 00:00:00 2001 From: Nova <110734810+novanai@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:53:03 +0100 Subject: [PATCH 4/5] update tests --- tests/hikari/impl/test_entity_factory.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 894e3a6322..9ad10d4920 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -2041,6 +2041,7 @@ def test_deserialize_guild_stage_channel_with_null_fields(self, entity_factory_i ) assert voice_channel.parent_id is None assert voice_channel.region is None + assert voice_channel.last_message_id is None def test_deserialize_guild_stage_channel_with_unset_fields(self, entity_factory_impl): voice_channel = entity_factory_impl.deserialize_guild_stage_channel( @@ -2058,6 +2059,7 @@ def test_deserialize_guild_stage_channel_with_unset_fields(self, entity_factory_ ) assert voice_channel.parent_id is None assert voice_channel.is_nsfw is False + assert voice_channel.last_message_id is None @pytest.fixture() def guild_forum_channel_payload(self, permission_overwrite_payload): From f9663d466104671341547554ec09323dc72e3f8f Mon Sep 17 00:00:00 2001 From: Nova <110734810+novanai@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:59:31 +0100 Subject: [PATCH 5/5] Update hikari/impl/entity_factory.py Co-authored-by: davfsa Signed-off-by: Nova <110734810+novanai@users.noreply.github.com> --- hikari/impl/entity_factory.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index d939ca4e55..d636906337 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -1173,9 +1173,7 @@ def deserialize_guild_stage_channel( snowflakes.Snowflake(overwrite["id"]): self.deserialize_permission_overwrite(overwrite) for overwrite in payload["permission_overwrites"] } - last_message_id = ( - snowflakes.Snowflake(msg_id) if (msg_id := payload.get("last_message_id")) is not None else None - ) + last_message_id = snowflakes.Snowflake(payload["last_message_id"]) if "last_message_id" in payload else None return channel_models.GuildStageChannel( app=self._app, id=channel_fields.id,