Skip to content

Commit

Permalink
Support text in stage channels (#1653)
Browse files Browse the repository at this point in the history
Signed-off-by: Nova <[email protected]>
Co-authored-by: davfsa <[email protected]>
  • Loading branch information
novanai and davfsa committed Jul 14, 2023
1 parent 8d165b9 commit 7055102
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/1653.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for text in stage channels
10 changes: 9 additions & 1 deletion hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +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(payload["last_message_id"]) if "last_message_id" in payload else None
return channel_models.GuildStageChannel(
app=self._app,
id=channel_fields.id,
Expand All @@ -1186,6 +1187,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(
Expand Down
5 changes: 5 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand All @@ -2034,10 +2036,12 @@ 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
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(
Expand All @@ -2055,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):
Expand Down

0 comments on commit 7055102

Please sign in to comment.