Skip to content

Commit

Permalink
Add audit log reason to channel deletion (#2058)
Browse files Browse the repository at this point in the history
Co-authored-by: davfsa <davfsa@gmail.com>
  • Loading branch information
lukasthaler and davfsa authored Sep 25, 2024
1 parent 615f49d commit 0e021b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changes/2058.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add the optional audit log `reason` argument to `hikari.api.rest.RESTClient.delete_channel` and
`hikari.impl.rest.RESTClientImpl.delete_channel`, the same way it already exists for e.g.
`edit_channel`
7 changes: 6 additions & 1 deletion hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ async def follow_channel(

@abc.abstractmethod
async def delete_channel(
self, channel: snowflakes.SnowflakeishOr[channels_.PartialChannel]
self,
channel: snowflakes.SnowflakeishOr[channels_.PartialChannel],
reason: undefined.UndefinedOr[str] = undefined.UNDEFINED,
) -> channels_.PartialChannel:
"""Delete a channel in a guild, or close a DM.
Expand All @@ -385,6 +387,9 @@ async def delete_channel(
channel
The channel to delete. This may be the object or the ID of an
existing channel.
reason
If provided, the reason that will be recorded in the audit logs.
Maximum of 512 characters.
Returns
-------
Expand Down
6 changes: 4 additions & 2 deletions hikari/impl/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,12 @@ async def follow_channel(
return self._entity_factory.deserialize_channel_follow(response)

async def delete_channel(
self, channel: snowflakes.SnowflakeishOr[channels_.PartialChannel]
self,
channel: snowflakes.SnowflakeishOr[channels_.PartialChannel],
reason: undefined.UndefinedOr[str] = undefined.UNDEFINED,
) -> channels_.PartialChannel:
route = routes.DELETE_CHANNEL.compile(channel=channel)
response = await self._request(route)
response = await self._request(route, reason=reason)
assert isinstance(response, dict)
return self._entity_factory.deserialize_channel(response)

Expand Down
12 changes: 11 additions & 1 deletion tests/hikari/impl/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2232,11 +2232,21 @@ async def test_delete_channel(self, rest_client):
expected_route = routes.DELETE_CHANNEL.compile(channel=123)
rest_client._request = mock.AsyncMock(return_value={"id": "NNNNN"})

result = await rest_client.delete_channel(StubModel(123), reason="some reason :)")

assert result is rest_client._entity_factory.deserialize_channel.return_value
rest_client._entity_factory.deserialize_channel.assert_called_once_with(rest_client._request.return_value)
rest_client._request.assert_awaited_once_with(expected_route, reason="some reason :)")

async def test_delete_channel_without_optionals(self, rest_client):
expected_route = routes.DELETE_CHANNEL.compile(channel=123)
rest_client._request = mock.AsyncMock(return_value={"id": "NNNNN"})

result = await rest_client.delete_channel(StubModel(123))

assert result is rest_client._entity_factory.deserialize_channel.return_value
rest_client._entity_factory.deserialize_channel.assert_called_once_with(rest_client._request.return_value)
rest_client._request.assert_awaited_once_with(expected_route)
rest_client._request.assert_awaited_once_with(expected_route, reason=undefined.UNDEFINED)

async def test_edit_my_voice_state_when_requesting_to_speak(self, rest_client):
rest_client._request = mock.AsyncMock()
Expand Down

0 comments on commit 0e021b2

Please sign in to comment.