Skip to content

Commit

Permalink
Add thread arguments to GuildChannel.edit + applied tags to edit_cann…
Browse files Browse the repository at this point in the history
…el (#1474)

Signed-off-by: Zechariah Zimmerman <[email protected]>
Co-authored-by: GoogleGenius <[email protected]>
Co-authored-by: davfsa <[email protected]>
  • Loading branch information
3 people authored Feb 5, 2023
1 parent 2ffe710 commit 36073a1
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 12 deletions.
1 change: 1 addition & 0 deletions changes/1474.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing fields to `GuildChannel.edit`.
1 change: 1 addition & 0 deletions changes/1474.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update `RESTClient.edit_channnel` to support setting `applied_tags` on forum threads.
29 changes: 18 additions & 11 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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.
Expand All @@ -234,7 +235,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 `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]
Expand Down Expand Up @@ -283,21 +286,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.
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`.
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.
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.
reason : hikari.undefined.UndefinedOr[str]
If provided, the reason that will be recorded in the audit logs.
Maximum of 512 characters.
Expand Down
40 changes: 39 additions & 1 deletion hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,14 @@ 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,
# 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.
Expand Down Expand Up @@ -1029,8 +1037,32 @@ 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.
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.
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.
Expand Down Expand Up @@ -1070,6 +1102,12 @@ async def edit(
permission_overwrites=permission_overwrites,
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,
)

Expand Down
2 changes: 2 additions & 0 deletions hikari/impl/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,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):
Expand Down Expand Up @@ -1095,6 +1096,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)
Expand Down
4 changes: 4 additions & 0 deletions tests/hikari/impl/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,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(
Expand Down Expand Up @@ -2262,6 +2264,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
Expand Down
12 changes: 12 additions & 0 deletions tests/hikari/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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
Expand All @@ -381,6 +387,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",
)

Expand Down

0 comments on commit 36073a1

Please sign in to comment.