Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect is_nsfw from threads #1386

Merged
merged 4 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes/1386.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove incorrect `is_nsfw` field from threads.
davfsa marked this conversation as resolved.
Show resolved Hide resolved
- The "NSFW" status is inherited from the parent object and not sent for threads.
11 changes: 3 additions & 8 deletions hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,14 +956,6 @@ class GuildChannel(PartialChannel):
guild_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True)
"""The ID of the guild the channel belongs to."""

is_nsfw: typing.Optional[bool] = attr.field(eq=False, hash=False, repr=False)
"""Whether the channel is marked as NSFW.

!!! warning
This will be `builtins.None` when received over the gateway in certain events
(e.g Guild Create).
"""

parent_id: typing.Optional[snowflakes.Snowflake] = attr.field(eq=False, hash=False, repr=True)
"""The ID of the parent channel the channel belongs to.

Expand Down Expand Up @@ -1147,6 +1139,9 @@ class PermissibleGuildChannel(GuildChannel):
Higher numbers appear further down the channel list.
"""

is_nsfw: bool = attr.field(eq=False, hash=False, repr=False)
"""Whether the channel is marked as NSFW."""

permission_overwrites: typing.Mapping[snowflakes.Snowflake, PermissionOverwrite] = attr.field(
eq=False, hash=False, repr=False
)
Expand Down
15 changes: 5 additions & 10 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class _GuildChannelFields:
name: typing.Optional[str] = attr.field()
type: typing.Union[channel_models.ChannelType, int] = attr.field()
guild_id: snowflakes.Snowflake = attr.field()
is_nsfw: typing.Optional[bool] = attr.field()
parent_id: typing.Optional[snowflakes.Snowflake] = attr.field()


Expand Down Expand Up @@ -930,7 +929,6 @@ def _set_guild_channel_attributes(
name=payload.get("name"),
type=channel_models.ChannelType(payload["type"]),
guild_id=guild_id,
is_nsfw=payload.get("nsfw"),
parent_id=parent_id,
)

Expand All @@ -952,7 +950,7 @@ def deserialize_guild_category(
type=channel_fields.type,
guild_id=channel_fields.guild_id,
permission_overwrites=permission_overwrites,
is_nsfw=channel_fields.is_nsfw,
is_nsfw=payload.get("nsfw", False),
parent_id=None,
position=int(payload["position"]),
)
Expand Down Expand Up @@ -987,7 +985,7 @@ def deserialize_guild_text_channel(
type=channel_fields.type,
guild_id=channel_fields.guild_id,
permission_overwrites=permission_overwrites,
is_nsfw=channel_fields.is_nsfw,
is_nsfw=payload.get("nsfw", False),
parent_id=channel_fields.parent_id,
topic=payload["topic"],
last_message_id=last_message_id,
Expand Down Expand Up @@ -1030,7 +1028,7 @@ def deserialize_guild_news_channel(
type=channel_fields.type,
guild_id=channel_fields.guild_id,
permission_overwrites=permission_overwrites,
is_nsfw=channel_fields.is_nsfw,
is_nsfw=payload.get("nsfw", False),
parent_id=channel_fields.parent_id,
topic=payload["topic"],
last_message_id=last_message_id,
Expand Down Expand Up @@ -1064,7 +1062,7 @@ def deserialize_guild_voice_channel(
type=channel_fields.type,
guild_id=channel_fields.guild_id,
permission_overwrites=permission_overwrites,
is_nsfw=channel_fields.is_nsfw,
is_nsfw=payload.get("nsfw", False),
parent_id=channel_fields.parent_id,
# There seems to be an edge case where rtc_region won't be included in gateway events (e.g. GUILD_CREATE)
# for a voice channel that just hasn't been touched since this was introduced (e.g. has been archived).
Expand Down Expand Up @@ -1094,7 +1092,7 @@ def deserialize_guild_stage_channel(
type=channel_fields.type,
guild_id=channel_fields.guild_id,
permission_overwrites=permission_overwrites,
is_nsfw=channel_fields.is_nsfw,
is_nsfw=payload.get("nsfw", False),
parent_id=channel_fields.parent_id,
region=payload["rtc_region"],
bitrate=int(payload["bitrate"]),
Expand Down Expand Up @@ -1164,7 +1162,6 @@ def deserialize_guild_news_thread(
name=channel_fields.name,
type=channel_fields.type,
guild_id=channel_fields.guild_id,
is_nsfw=channel_fields.is_nsfw,
parent_id=channel_fields.parent_id,
last_message_id=last_message_id,
last_pin_timestamp=last_pin_timestamp,
Expand Down Expand Up @@ -1213,7 +1210,6 @@ def deserialize_guild_public_thread(
name=channel_fields.name,
type=channel_fields.type,
guild_id=channel_fields.guild_id,
is_nsfw=channel_fields.is_nsfw,
parent_id=channel_fields.parent_id,
last_message_id=last_message_id,
last_pin_timestamp=last_pin_timestamp,
Expand Down Expand Up @@ -1262,7 +1258,6 @@ def deserialize_guild_private_thread(
name=channel_fields.name,
type=channel_fields.type,
guild_id=channel_fields.guild_id,
is_nsfw=channel_fields.is_nsfw,
parent_id=channel_fields.parent_id,
last_message_id=last_message_id,
last_pin_timestamp=last_pin_timestamp,
Expand Down
10 changes: 5 additions & 5 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ def test_deserialize_guild_category_with_unset_fields(self, entity_factory_impl,
}
)
assert guild_category.parent_id is None
assert guild_category.is_nsfw is None
assert guild_category.is_nsfw is False

def test_deserialize_guild_category_with_null_fields(self, entity_factory_impl, permission_overwrite_payload):
guild_category = entity_factory_impl.deserialize_guild_category(
Expand Down Expand Up @@ -1723,7 +1723,7 @@ def test_deserialize_guild_text_channel_with_unset_fields(self, entity_factory_i
"guild_id": "123123123",
}
)
assert guild_text_channel.is_nsfw is None
assert guild_text_channel.is_nsfw is False
assert guild_text_channel.rate_limit_per_user.total_seconds() == 0
assert guild_text_channel.last_pin_timestamp is None
assert guild_text_channel.parent_id is None
Expand Down Expand Up @@ -1787,7 +1787,7 @@ def test_deserialize_guild_news_channel_with_unset_fields(self, entity_factory_i
"guild_id": "4123",
}
)
assert news_channel.is_nsfw is None
assert news_channel.is_nsfw is False
assert news_channel.parent_id is None
assert news_channel.last_pin_timestamp is None
assert news_channel.last_message_id is None
Expand Down Expand Up @@ -1869,7 +1869,7 @@ def test_deserialize_guild_voice_channel_with_unset_fields(self, entity_factory_
)
assert voice_channel.video_quality_mode is channel_models.VideoQualityMode.AUTO
assert voice_channel.parent_id is None
assert voice_channel.is_nsfw is None
assert voice_channel.is_nsfw is False
assert voice_channel.region is None

@pytest.fixture()
Expand Down Expand Up @@ -1941,7 +1941,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 None
assert voice_channel.is_nsfw is False

def test_deserialize_thread_member(
self, entity_factory_impl: entity_factory.EntityFactoryImpl, thread_member_payload: typing.Dict[str, typing.Any]
Expand Down
1 change: 0 additions & 1 deletion tests/hikari/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ def model(self, mock_app):
name="foo1",
type=channels.ChannelType.GUILD_VOICE,
guild_id=snowflakes.Snowflake(123456789),
is_nsfw=True,
parent_id=None,
)

Expand Down