From 169499ee14abea4c97745c19be4218a9ba14a52a Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 20:12:40 -0500 Subject: [PATCH 01/19] Support for applied tags in client channel edit --- hikari/api/rest.py | 5 +++++ hikari/impl/rest.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index 2b787e3959..d7c14f11cb 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -227,6 +227,7 @@ async def edit_channel( locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + applied_tags: undefined.UndefinedOr[typing.Sequence[channels_.ForumTag]] = undefined.UNDEFINED, reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, ) -> channels_.PartialChannel: """Edit a channel. @@ -306,6 +307,10 @@ async def edit_channel( This should be either 60, 1440, 4320 or 10080 seconds and, as of writing, ignores the parent channel's set default_auto_archive_duration when passed as `hikari.undefined.UNDEFINED`. + applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[hikari.channels.ForumTag]] + If provided, the new tags applied to the thread. + + This only applies to threads in a forum channel. reason : hikari.undefined.UndefinedOr[str] If provided, the reason that will be recorded in the audit logs. Maximum of 512 characters. diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index d563f5977b..b242930f9e 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1003,6 +1003,7 @@ async def edit_channel( locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + applied_tags: undefined.UndefinedOr[typing.Sequence[channels_.ForumTag]] = undefined.UNDEFINED, reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, ) -> channels_.PartialChannel: if isinstance(auto_archive_duration, datetime.timedelta): @@ -1054,6 +1055,7 @@ async def edit_channel( body.put("auto_archive_duration", auto_archive_duration, conversion=time.timespan_to_int) body.put("locked", locked) body.put("invitable", invitable) + body.put_array("applied_tags", applied_tags, conversion=self._entity_factory.serialize_forum_tag) response = await self._request(route, json=body, reason=reason) assert isinstance(response, dict) From e3b6b43d45b9e6f29692728638a435ad51367c3d Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 20:24:00 -0500 Subject: [PATCH 02/19] Implement GuildThreadChannel.edit --- hikari/channels.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/hikari/channels.py b/hikari/channels.py index a222a1602f..d0f6aba6dd 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1696,6 +1696,91 @@ class GuildThreadChannel(TextableGuildChannel): Will be `None` for threads created before 2020-01-09. """ + async def edit( + self, + *, + name: undefined.UndefinedOr[str] = undefined.UNDEFINED, + archived: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + rate_limit_per_user: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + flags: undefined.UndefinedOr[int] = undefined.UNDEFINED, + applied_tags: undefined.UndefinedOr[typing.Sequence[snowflakes.Snowflake[ForumTag]]] = undefined.UNDEFINED, + reason: hikari.undefined.UndefinedOr[str] = undefined.UNDEFINED, + **_ + ) -> PartialChannel: + """Edit the guild thread. + + Other Parameters + ---------------- + name : hikari.undefined.UndefinedOr[str] + If provided, the new name for the thread. + archived : hikari.undefined.UndefinedOr[bool] + If provided, the new archived state for the thread. + auto_archive_duration : hikari.undefined.UndefinedOr[time.Intervalish] + If provided, the new auto archive duration for this thread. + + This should be either 60, 1440, 4320 or 10080 seconds and, as of + writing. + locked : hikari.undefined.UndefinedOr[bool] + If provided, the new locked state for the thread. + invitable : hikari.undefined.UndefinedOr[bool] + If provided, the new setting for whether non-moderators can invite + new members to a private thread. + rate_limit_per_user : hikari.undefined.UndefinedOr[hikari.internal.time.Intervalish] + If provided, the new rate limit per user in the thread. + flags : hikari.undefined.UndefinedOr[int] + If provided, the new channel flags to use for the thread. PINNED can + only be used on threads in forum channels. + applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[snowflakes.Snowflake[ForumTag]]] + If provided, the new tags to use for the thread in a forum channel. + reason : hikari.undefined.UndefinedOr[str] + If provided, the reason that will be recorded in the audit logs. + Maximum of 512 characters. + + Returns + ------- + hikari.channels.PartialChannel + The edited thread. + + Raises + ------ + hikari.errors.BadRequestError + If any of the fields that are passed have an invalid value. + hikari.errors.UnauthorizedError + If you are unauthorized to make the request (invalid/missing token). + hikari.errors.ForbiddenError + If you are missing permissions to edit the channel. + hikari.errors.NotFoundError + If the thread is not found. + hikari.errors.RateLimitTooLongError + Raised in the event that a rate limit occurs that is + longer than `max_rate_limit` when making a request. + hikari.errors.RateLimitedError + Usually, Hikari will handle and retry on hitting + rate-limits automatically. This includes most bucket-specific + rate-limits and global rate-limits. In some rare edge cases, + however, Discord implements other undocumented rules for + rate-limiting, such as limits per attribute. These cannot be + detected or handled normally by Hikari due to their undocumented + nature, and will trigger this exception if they occur. + hikari.errors.InternalServerError + If an internal error occurs on Discord while handling the request. + """ + return await self.app.rest.edit_channel( + self.id, + name=name, + archived=archived, + auto_archive_duration=auto_archive_duration, + locked=locked, + invitable=invitable, + rate_limit_per_user=rate_limit_per_user, + flags=flags, + applied_tags=applied_tags, + reason=reason, + ) + class GuildNewsThread(GuildThreadChannel): """Represents a guild news channel public thread.""" From 61ed7971a963718706cbbeab2af98b2291a65d53 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 20:36:49 -0500 Subject: [PATCH 03/19] Adjust type annotations --- hikari/channels.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hikari/channels.py b/hikari/channels.py index d0f6aba6dd..074c1e6d10 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1705,10 +1705,10 @@ async def edit( locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, rate_limit_per_user: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, - flags: undefined.UndefinedOr[int] = undefined.UNDEFINED, - applied_tags: undefined.UndefinedOr[typing.Sequence[snowflakes.Snowflake[ForumTag]]] = undefined.UNDEFINED, - reason: hikari.undefined.UndefinedOr[str] = undefined.UNDEFINED, - **_ + flags: undefined.UndefinedOr[ChannelFlag] = undefined.UNDEFINED, + applied_tags: undefined.UndefinedOr[typing.Sequence[ForumTag]] = undefined.UNDEFINED, + reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, + **_, ) -> PartialChannel: """Edit the guild thread. @@ -1730,10 +1730,10 @@ async def edit( new members to a private thread. rate_limit_per_user : hikari.undefined.UndefinedOr[hikari.internal.time.Intervalish] If provided, the new rate limit per user in the thread. - flags : hikari.undefined.UndefinedOr[int] + flags : hikari.undefined.UndefinedOr[ChannelFlag] If provided, the new channel flags to use for the thread. PINNED can only be used on threads in forum channels. - applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[snowflakes.Snowflake[ForumTag]]] + applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[ForumTag]] If provided, the new tags to use for the thread in a forum channel. reason : hikari.undefined.UndefinedOr[str] If provided, the reason that will be recorded in the audit logs. From 7a403b0798924b870fdafb6df069e6321ac10e87 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 21:11:55 -0500 Subject: [PATCH 04/19] Remove kwargs --- hikari/channels.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hikari/channels.py b/hikari/channels.py index 074c1e6d10..b600f6e819 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1708,7 +1708,6 @@ async def edit( flags: undefined.UndefinedOr[ChannelFlag] = undefined.UNDEFINED, applied_tags: undefined.UndefinedOr[typing.Sequence[ForumTag]] = undefined.UNDEFINED, reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, - **_, ) -> PartialChannel: """Edit the guild thread. From ce769a694050d669ddd3b3746bfce3be8ead5294 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 21:12:10 -0500 Subject: [PATCH 05/19] Add test for the thread edit method --- tests/hikari/test_channels.py | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/hikari/test_channels.py b/tests/hikari/test_channels.py index 388286d98e..fd43c647a1 100644 --- a/tests/hikari/test_channels.py +++ b/tests/hikari/test_channels.py @@ -383,6 +383,61 @@ async def test_edit(self, model): ) +class TestGuildThreadChannel: + @pytest.fixture() + def model(self, mock_app): + return hikari_test_helpers.mock_class_namespace(channels.GuildThreadChannel)( + app=mock_app, + id=snowflakes.Snowflake(69420), + name="foo2", + type=channels.ChannelType.GUILD_PUBLIC_THREAD, + guild_id=snowflakes.Snowflake(123456789), + parent_id=snowflakes.Snowflake(987654321), + is_archived=False, + auto_archive_duration=679, + is_locked=False, + owner_id=snowflakes.Snowflake(123039302), + thread_created_at=234, + last_message_id=snowflakes.Snowflake(2345342), + last_pin_timestamp=4457867, + rate_limit_per_user=60, + approximate_message_count=10, + approximate_member_count=2, + archive_timestamp=0, + member=None + ) + + @pytest.mark.asyncio() + async def test_thread_edit(self, model): + model.app.rest.edit_channel = mock.AsyncMock() + + result = await model.edit( + name="Supa fast boike", + locked=True, + archived=True, + auto_archive_duration=2345, + invitable=True, + flags=123, + applied_tags=[100001, 100002], + rate_limit_per_user=54123123, + reason="Foo", + ) + + assert result is model.app.rest.edit_channel.return_value + model.app.rest.edit_channel.assert_awaited_once_with( + 69420, + name="Supa fast boike", + locked=True, + archived=True, + auto_archive_duration=2345, + invitable=True, + flags=123, + applied_tags=[100001, 100002], + rate_limit_per_user=54123123, + reason="Foo", + ) + + class TestPermissibleGuildChannel: @pytest.fixture() def model(self, mock_app): From 542d6a9c2f7c00ea2c02f7123f357c48b0de11c0 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sat, 14 Jan 2023 21:20:59 -0500 Subject: [PATCH 06/19] Add changes --- changes/1474.bugfix.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/1474.bugfix.md diff --git a/changes/1474.bugfix.md b/changes/1474.bugfix.md new file mode 100644 index 0000000000..d51a5d186b --- /dev/null +++ b/changes/1474.bugfix.md @@ -0,0 +1,2 @@ +- Implement `GuildThreadChannel.edit` +- Update `RESTClient.edit_channnel` to support applied tags on forum threads From 7497ec23360539f35d627803c3b94ff0f0e620c8 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 09:27:54 -0500 Subject: [PATCH 07/19] Change it from bug fix to feature --- changes/{1474.bugfix.md => 1474.feature.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes/{1474.bugfix.md => 1474.feature.md} (100%) diff --git a/changes/1474.bugfix.md b/changes/1474.feature.md similarity index 100% rename from changes/1474.bugfix.md rename to changes/1474.feature.md From 44ad8e22180c9aad987e641b6d1330d5041c03a8 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:00:00 -0500 Subject: [PATCH 08/19] Add flags support to GuildChannel.edit --- hikari/channels.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hikari/channels.py b/hikari/channels.py index b600f6e819..8bce20202f 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1050,6 +1050,8 @@ async def edit( permission_overwrites: undefined.UndefinedOr[typing.Sequence[PermissionOverwrite]] = undefined.UNDEFINED, parent_category: undefined.UndefinedOr[snowflakes.SnowflakeishOr[GuildCategory]] = undefined.UNDEFINED, default_auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + # Forum & Thread-only fields + flags: undefined.UndefinedOr[ChannelFlag] = undefined.UNDEFINED, reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, ) -> PartialChannel: """Edit the text channel. @@ -1086,6 +1088,10 @@ async def edit( should default to when creating threads in this channel. This should be either 60, 1440, 4320 or 10080 seconds and, as of + flags : hikari.undefined.UndefinedOr[ChannelFlag] + If provided, the new channel flags to use for the channel. This can + only be used on a forum channel to apply ChannelFlag.REQUIRE_TAG, or + on a forum thread to apply ChannelFlag.PINNED. writing. reason : hikari.undefined.UndefinedOr[str] If provided, the reason that will be recorded in the audit logs. @@ -1134,6 +1140,7 @@ async def edit( permission_overwrites=permission_overwrites, parent_category=parent_category, default_auto_archive_duration=default_auto_archive_duration, + flags=flags, reason=reason, ) From c0fa0f983ac63b50393ceecc3fa845699b415f0f Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:00:24 -0500 Subject: [PATCH 09/19] Add missing thread parameters to GuildChannel.edit --- hikari/channels.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/hikari/channels.py b/hikari/channels.py index 8bce20202f..0cd6b6381b 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1052,6 +1052,12 @@ async def edit( default_auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, # Forum & Thread-only fields flags: undefined.UndefinedOr[ChannelFlag] = undefined.UNDEFINED, + # Thread-only fields + archived: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, + locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, + applied_tags: undefined.UndefinedOr[typing.Sequence[ForumTag]] = undefined.UNDEFINED, reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, ) -> PartialChannel: """Edit the text channel. @@ -1087,12 +1093,30 @@ async def edit( If provided, the auto archive duration Discord's end user client should default to when creating threads in this channel. - This should be either 60, 1440, 4320 or 10080 seconds and, as of + This should be either 60, 1440, 4320 or 10080 seconds, as of + writing. flags : hikari.undefined.UndefinedOr[ChannelFlag] If provided, the new channel flags to use for the channel. This can only be used on a forum channel to apply ChannelFlag.REQUIRE_TAG, or on a forum thread to apply ChannelFlag.PINNED. + archived : hikari.undefined.UndefinedOr[bool] + If provided, the new archived state for the thread. This only + applies to threads. + auto_archive_duration : hikari.undefined.UndefinedOr[time.Intervalish] + If provided, the new auto archive duration for this thread. This + only applies to threads. + + This should be either 60, 1440, 4320 or 10080 seconds, as of writing. + locked : hikari.undefined.UndefinedOr[bool] + If provided, the new locked state for the thread. This only applies + to threads. + invitable : hikari.undefined.UndefinedOr[bool] + If provided, the new setting for whether non-moderators can invite + new members to a private thread. This only applies to threads. + applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[ForumTag]] + If provided, the new tags to apply to the thread. This only applies + to threads in a forum channel. reason : hikari.undefined.UndefinedOr[str] If provided, the reason that will be recorded in the audit logs. Maximum of 512 characters. @@ -1141,6 +1165,11 @@ async def edit( parent_category=parent_category, default_auto_archive_duration=default_auto_archive_duration, flags=flags, + archived=archived, + auto_archive_duration=auto_archive_duration, + locked=locked, + invitable=invitable, + applied_tags=applied_tags, reason=reason, ) From 35b113dc0647a7df55503a8903324b589c0d186f Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:00:36 -0500 Subject: [PATCH 10/19] Update changes --- changes/1474.feature.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changes/1474.feature.md b/changes/1474.feature.md index d51a5d186b..f32c8c385b 100644 --- a/changes/1474.feature.md +++ b/changes/1474.feature.md @@ -1,2 +1,3 @@ -- Implement `GuildThreadChannel.edit` +- Update `GuildChannel.edit` to support threads +- Update `GuildChannel.edit` to support flags on forum channels - Update `RESTClient.edit_channnel` to support applied tags on forum threads From 91298e26b4e95d6a682952637e86f038d09497ed Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:01:47 -0500 Subject: [PATCH 11/19] Remove GuildThreadChannel.edit, merged into GuildChannel --- hikari/channels.py | 84 ---------------------------------------------- 1 file changed, 84 deletions(-) diff --git a/hikari/channels.py b/hikari/channels.py index 0cd6b6381b..5d57a84653 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1732,90 +1732,6 @@ class GuildThreadChannel(TextableGuildChannel): Will be `None` for threads created before 2020-01-09. """ - async def edit( - self, - *, - name: undefined.UndefinedOr[str] = undefined.UNDEFINED, - archived: undefined.UndefinedOr[bool] = undefined.UNDEFINED, - auto_archive_duration: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, - locked: undefined.UndefinedOr[bool] = undefined.UNDEFINED, - invitable: undefined.UndefinedOr[bool] = undefined.UNDEFINED, - rate_limit_per_user: undefined.UndefinedOr[time.Intervalish] = undefined.UNDEFINED, - flags: undefined.UndefinedOr[ChannelFlag] = undefined.UNDEFINED, - applied_tags: undefined.UndefinedOr[typing.Sequence[ForumTag]] = undefined.UNDEFINED, - reason: undefined.UndefinedOr[str] = undefined.UNDEFINED, - ) -> PartialChannel: - """Edit the guild thread. - - Other Parameters - ---------------- - name : hikari.undefined.UndefinedOr[str] - If provided, the new name for the thread. - archived : hikari.undefined.UndefinedOr[bool] - If provided, the new archived state for the thread. - auto_archive_duration : hikari.undefined.UndefinedOr[time.Intervalish] - If provided, the new auto archive duration for this thread. - - This should be either 60, 1440, 4320 or 10080 seconds and, as of - writing. - locked : hikari.undefined.UndefinedOr[bool] - If provided, the new locked state for the thread. - invitable : hikari.undefined.UndefinedOr[bool] - If provided, the new setting for whether non-moderators can invite - new members to a private thread. - rate_limit_per_user : hikari.undefined.UndefinedOr[hikari.internal.time.Intervalish] - If provided, the new rate limit per user in the thread. - flags : hikari.undefined.UndefinedOr[ChannelFlag] - If provided, the new channel flags to use for the thread. PINNED can - only be used on threads in forum channels. - applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[ForumTag]] - If provided, the new tags to use for the thread in a forum channel. - reason : hikari.undefined.UndefinedOr[str] - If provided, the reason that will be recorded in the audit logs. - Maximum of 512 characters. - - Returns - ------- - hikari.channels.PartialChannel - The edited thread. - - Raises - ------ - hikari.errors.BadRequestError - If any of the fields that are passed have an invalid value. - hikari.errors.UnauthorizedError - If you are unauthorized to make the request (invalid/missing token). - hikari.errors.ForbiddenError - If you are missing permissions to edit the channel. - hikari.errors.NotFoundError - If the thread is not found. - hikari.errors.RateLimitTooLongError - Raised in the event that a rate limit occurs that is - longer than `max_rate_limit` when making a request. - hikari.errors.RateLimitedError - Usually, Hikari will handle and retry on hitting - rate-limits automatically. This includes most bucket-specific - rate-limits and global rate-limits. In some rare edge cases, - however, Discord implements other undocumented rules for - rate-limiting, such as limits per attribute. These cannot be - detected or handled normally by Hikari due to their undocumented - nature, and will trigger this exception if they occur. - hikari.errors.InternalServerError - If an internal error occurs on Discord while handling the request. - """ - return await self.app.rest.edit_channel( - self.id, - name=name, - archived=archived, - auto_archive_duration=auto_archive_duration, - locked=locked, - invitable=invitable, - rate_limit_per_user=rate_limit_per_user, - flags=flags, - applied_tags=applied_tags, - reason=reason, - ) - class GuildNewsThread(GuildThreadChannel): """Represents a guild news channel public thread.""" From 443a031d4c2ac4fd77fec9fe42967e83b7b360da Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:02:08 -0500 Subject: [PATCH 12/19] Remove the GuildThreadChannel.edit tests --- tests/hikari/test_channels.py | 55 ----------------------------------- 1 file changed, 55 deletions(-) diff --git a/tests/hikari/test_channels.py b/tests/hikari/test_channels.py index fd43c647a1..388286d98e 100644 --- a/tests/hikari/test_channels.py +++ b/tests/hikari/test_channels.py @@ -383,61 +383,6 @@ async def test_edit(self, model): ) -class TestGuildThreadChannel: - @pytest.fixture() - def model(self, mock_app): - return hikari_test_helpers.mock_class_namespace(channels.GuildThreadChannel)( - app=mock_app, - id=snowflakes.Snowflake(69420), - name="foo2", - type=channels.ChannelType.GUILD_PUBLIC_THREAD, - guild_id=snowflakes.Snowflake(123456789), - parent_id=snowflakes.Snowflake(987654321), - is_archived=False, - auto_archive_duration=679, - is_locked=False, - owner_id=snowflakes.Snowflake(123039302), - thread_created_at=234, - last_message_id=snowflakes.Snowflake(2345342), - last_pin_timestamp=4457867, - rate_limit_per_user=60, - approximate_message_count=10, - approximate_member_count=2, - archive_timestamp=0, - member=None - ) - - @pytest.mark.asyncio() - async def test_thread_edit(self, model): - model.app.rest.edit_channel = mock.AsyncMock() - - result = await model.edit( - name="Supa fast boike", - locked=True, - archived=True, - auto_archive_duration=2345, - invitable=True, - flags=123, - applied_tags=[100001, 100002], - rate_limit_per_user=54123123, - reason="Foo", - ) - - assert result is model.app.rest.edit_channel.return_value - model.app.rest.edit_channel.assert_awaited_once_with( - 69420, - name="Supa fast boike", - locked=True, - archived=True, - auto_archive_duration=2345, - invitable=True, - flags=123, - applied_tags=[100001, 100002], - rate_limit_per_user=54123123, - reason="Foo", - ) - - class TestPermissibleGuildChannel: @pytest.fixture() def model(self, mock_app): From edba88ab33ace3337c448f93a517d97ac23bffee Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:05:17 -0500 Subject: [PATCH 13/19] Update TestGuildChannel.test_edit to cover new thread & forum parameters --- tests/hikari/test_channels.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/hikari/test_channels.py b/tests/hikari/test_channels.py index 388286d98e..c5281a1760 100644 --- a/tests/hikari/test_channels.py +++ b/tests/hikari/test_channels.py @@ -362,6 +362,12 @@ async def test_edit(self, model): region="us-west", parent_category=341123123123, permission_overwrites={123: "123"}, + flags=12, + archived=True, + auto_archive_duration=1234, + locked=True, + invitable=True, + applied_tags=[12345, 54321], ) assert result is model.app.rest.edit_channel.return_value @@ -379,6 +385,12 @@ async def test_edit(self, model): permission_overwrites={123: "123"}, parent_category=341123123123, default_auto_archive_duration=123312, + flags=12, + archived=True, + auto_archive_duration=1234, + locked=True, + invitable=True, + applied_tags=[12345, 54321], reason="left right", ) From b2c6f306eee98c9bc4ad0fd3eec9bde33915cd20 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 10:31:59 -0500 Subject: [PATCH 14/19] Test new fields on RESTClient.edit_channel --- tests/hikari/impl/test_rest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py index 9b2aae7474..d3189dfb18 100644 --- a/tests/hikari/impl/test_rest.py +++ b/tests/hikari/impl/test_rest.py @@ -2169,6 +2169,7 @@ async def test_edit_channel( ): expected_route = routes.PATCH_CHANNEL.compile(channel=123) mock_object = mock.Mock() + forum_tag = channels.ForumTag(id=snowflakes.Snowflake(123), name="test", moderated=True, emoji=None) rest_client._entity_factory.deserialize_channel = mock.Mock(return_value=mock_object) rest_client._request = mock.AsyncMock(return_value={"payload": "GO"}) rest_client._entity_factory.serialize_permission_overwrite = mock.Mock( @@ -2202,6 +2203,8 @@ async def test_edit_channel( "locked": False, "invitable": True, "auto_archive_duration": 12322, + "flags": 12, + "applied_tags": [{"id": 0, "name": "testing", "moderated": True, "emoji_id": None, "emoji_name": None}], } result = await rest_client.edit_channel( @@ -2235,6 +2238,8 @@ async def test_edit_channel( locked=False, invitable=True, auto_archive_duration=auto_archive_duration, + flags=12, + applied_tags=[channels.ForumTag(name="testing", moderated=True)], ) assert result == mock_object From 965532c0c8923b1566131d503802266f8dcbb9aa Mon Sep 17 00:00:00 2001 From: Zechariah Zimmerman Date: Sun, 15 Jan 2023 15:51:16 -0500 Subject: [PATCH 15/19] Update hikari/api/rest.py Co-authored-by: GoogleGenius <81032623+GoogleGenius@users.noreply.github.com> Signed-off-by: Zechariah Zimmerman --- hikari/api/rest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index d7c14f11cb..b37aeec809 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -308,7 +308,7 @@ async def edit_channel( writing, ignores the parent channel's set default_auto_archive_duration when passed as `hikari.undefined.UNDEFINED`. applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[hikari.channels.ForumTag]] - If provided, the new tags applied to the thread. + If provided, the new tags to apply to the thread. This only applies to threads in a forum channel. reason : hikari.undefined.UndefinedOr[str] From 97c6a9885ea8d4b8274d742f3d834082c0bba503 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 16:20:11 -0500 Subject: [PATCH 16/19] Make docs more consistent --- hikari/api/rest.py | 28 +++++++++++++++------------- hikari/channels.py | 2 ++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index b37aeec809..de93e89c74 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -243,7 +243,9 @@ async def edit_channel( name : hikari.undefined.UndefinedOr[str] If provided, the new name for the channel. flags : hikari.undefined.UndefinedOr[hikari.channels.ChannelFlag] - If provided, the new flags for the channel + If provided, the new channel flags to use for the channel. This can + only be used on a forum channel to apply ChannelFlag.REQUIRE_TAG, or + on a forum thread to apply ChannelFlag.PINNED. position : hikari.undefined.UndefinedOr[int] If provided, the new position for the channel. topic : hikari.undefined.UndefinedOr[str] @@ -292,25 +294,25 @@ async def edit_channel( This only applies to forum channels. archived : hikari.undefined.UndefinedOr[bool] - If provided, whether to archive or unarchive this thread channel. + If provided, the new archived state for the thread. This only + applies to threads. locked : hikari.undefined.UndefinedOr[bool] - If provided, whether to lock or unlock this thread channel. + If provided, the new locked state for the thread. This only applies + to threads. If it's locked then only people with `MANAGE_THREADS` can unarchive it. invitable : undefined.UndefinedOr[bool] - If provided, whether non-moderators should be able to add other non-moderators to the thread. - - This only applies to private threads. + If provided, the new setting for whether non-moderators can invite + new members to a private thread. This only applies to threads. auto_archive_duration : hikari.undefined.UndefinedOr[hikari.internal.time.Intervalish] - If provided, how long the thread should remain inactive until it's archived. + If provided, the new auto archive duration for this thread. This + only applies to threads. - This should be either 60, 1440, 4320 or 10080 seconds and, as of - writing, ignores the parent channel's set default_auto_archive_duration - when passed as `hikari.undefined.UNDEFINED`. + This should be either 60, 1440, 4320 or 10080 seconds, as of + writing. applied_tags : hikari.undefined.UndefinedOr[typing.Sequence[hikari.channels.ForumTag]] - If provided, the new tags to apply to the thread. - - This only applies to threads in a forum channel. + If provided, the new tags to apply to the thread. This only applies + to threads in a forum channel. reason : hikari.undefined.UndefinedOr[str] If provided, the reason that will be recorded in the audit logs. Maximum of 512 characters. diff --git a/hikari/channels.py b/hikari/channels.py index 5d57a84653..2a9b7652a9 100644 --- a/hikari/channels.py +++ b/hikari/channels.py @@ -1111,6 +1111,8 @@ async def edit( locked : hikari.undefined.UndefinedOr[bool] If provided, the new locked state for the thread. This only applies to threads. + + If it's locked then only people with `MANAGE_THREADS` can unarchive it. invitable : hikari.undefined.UndefinedOr[bool] If provided, the new setting for whether non-moderators can invite new members to a private thread. This only applies to threads. From 967428bf33e660152e575bae2d074bbf99dba381 Mon Sep 17 00:00:00 2001 From: Zech Zimmerman Date: Sun, 15 Jan 2023 16:27:12 -0500 Subject: [PATCH 17/19] Remove unused variable --- tests/hikari/impl/test_rest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py index d3189dfb18..386113ef69 100644 --- a/tests/hikari/impl/test_rest.py +++ b/tests/hikari/impl/test_rest.py @@ -2169,7 +2169,6 @@ async def test_edit_channel( ): expected_route = routes.PATCH_CHANNEL.compile(channel=123) mock_object = mock.Mock() - forum_tag = channels.ForumTag(id=snowflakes.Snowflake(123), name="test", moderated=True, emoji=None) rest_client._entity_factory.deserialize_channel = mock.Mock(return_value=mock_object) rest_client._request = mock.AsyncMock(return_value={"payload": "GO"}) rest_client._entity_factory.serialize_permission_overwrite = mock.Mock( From e4d96453e535150ed5a25221af567cffbd764b71 Mon Sep 17 00:00:00 2001 From: davfsa Date: Tue, 17 Jan 2023 23:17:04 +0100 Subject: [PATCH 18/19] Improve changelog fragments --- changes/1474.bugfix.md | 1 + changes/1474.feature.md | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 changes/1474.bugfix.md diff --git a/changes/1474.bugfix.md b/changes/1474.bugfix.md new file mode 100644 index 0000000000..26f99e7db1 --- /dev/null +++ b/changes/1474.bugfix.md @@ -0,0 +1 @@ +Add missing fields to `GuildChannel.edit`. diff --git a/changes/1474.feature.md b/changes/1474.feature.md index f32c8c385b..fc150802e0 100644 --- a/changes/1474.feature.md +++ b/changes/1474.feature.md @@ -1,3 +1 @@ -- Update `GuildChannel.edit` to support threads -- Update `GuildChannel.edit` to support flags on forum channels -- Update `RESTClient.edit_channnel` to support applied tags on forum threads +Update `RESTClient.edit_channnel` to support setting `applied_tags` on forum threads. From 5e256248fa1c4fe7f6754224767fea3bcdde5e92 Mon Sep 17 00:00:00 2001 From: Zechariah Zimmerman Date: Thu, 19 Jan 2023 17:38:21 -0500 Subject: [PATCH 19/19] Update hikari/api/rest.py Co-authored-by: davfsa Signed-off-by: Zechariah Zimmerman --- hikari/api/rest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hikari/api/rest.py b/hikari/api/rest.py index de93e89c74..74bbf75ae1 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -244,8 +244,8 @@ async def edit_channel( If provided, the new name for the channel. flags : hikari.undefined.UndefinedOr[hikari.channels.ChannelFlag] If provided, the new channel flags to use for the channel. This can - only be used on a forum channel to apply ChannelFlag.REQUIRE_TAG, or - on a forum thread to apply ChannelFlag.PINNED. + only be used on a forum channel to apply `REQUIRE_TAG`, or + on a forum thread to apply `PINNED`. position : hikari.undefined.UndefinedOr[int] If provided, the new position for the channel. topic : hikari.undefined.UndefinedOr[str]