From 167d796cb6efa53e5d3e5e23371a3087f7f6fbbf Mon Sep 17 00:00:00 2001 From: nulldomain Date: Sun, 6 Nov 2022 01:41:42 +0000 Subject: [PATCH] Support specifying `with_counts` and `with_expiration` in `RESTClient.fetch_invite` (#1330) --- changes/1330.doc.md | 1 + hikari/api/rest.py | 12 +++++++++++- hikari/impl/rest.py | 8 +++++--- tests/hikari/impl/test_rest.py | 5 ++--- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 changes/1330.doc.md diff --git a/changes/1330.doc.md b/changes/1330.doc.md new file mode 100644 index 0000000000..2a6313d56d --- /dev/null +++ b/changes/1330.doc.md @@ -0,0 +1 @@ +Support specifying `with_counts` and `with_expiration` in `RESTClient.fetch_invite` diff --git a/hikari/api/rest.py b/hikari/api/rest.py index 38e1597e59..fea1d4fbcb 100644 --- a/hikari/api/rest.py +++ b/hikari/api/rest.py @@ -2765,7 +2765,9 @@ async def fetch_gateway_bot_info(self) -> sessions.GatewayBotInfo: """ @abc.abstractmethod - async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> invites.Invite: + async def fetch_invite( + self, invite: typing.Union[invites.InviteCode, str], with_counts: bool = True, with_expiration: bool = True + ) -> invites.Invite: """Fetch an existing invite. Parameters @@ -2773,6 +2775,14 @@ async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> i invite : typing.Union[hikari.invites.InviteCode, builtins.str] The invite to fetch. This may be an invite object or the code of an existing invite. + with_counts : builtins.bool + Whether the invite should contain the approximate member counts. + + Defaults to `builtins.True`. + with_expiration: builtins.bool + Whether the invite should contain the expiration date. + + Defaults to `builtins.True`. Returns ------- diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py index 80f5160ed1..f965089259 100644 --- a/hikari/impl/rest.py +++ b/hikari/impl/rest.py @@ -1982,11 +1982,13 @@ async def fetch_gateway_bot_info(self) -> sessions.GatewayBotInfo: assert isinstance(response, dict) return self._entity_factory.deserialize_gateway_bot_info(response) - async def fetch_invite(self, invite: typing.Union[invites.InviteCode, str]) -> invites.Invite: + async def fetch_invite( + self, invite: typing.Union[invites.InviteCode, str], with_counts: bool = True, with_expiration: bool = True + ) -> invites.Invite: route = routes.GET_INVITE.compile(invite_code=invite if isinstance(invite, str) else invite.code) query = data_binding.StringMapBuilder() - query.put("with_counts", True) - query.put("with_expiration", True) + query.put("with_counts", with_counts) + query.put("with_expiration", with_expiration) response = await self._request(route, query=query) assert isinstance(response, dict) return self._entity_factory.deserialize_invite(response) diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py index ea94ca0fbe..c04e9964ed 100644 --- a/tests/hikari/impl/test_rest.py +++ b/tests/hikari/impl/test_rest.py @@ -3442,10 +3442,9 @@ async def test_fetch_invite(self, rest_client): rest_client._request = mock.AsyncMock(return_value={"code": "Jx4cNGG"}) rest_client._entity_factory.deserialize_invite = mock.Mock(return_value=return_invite) - assert await rest_client.fetch_invite(input_invite) == return_invite - + assert await rest_client.fetch_invite(input_invite, with_counts=True, with_expiration=False) == return_invite rest_client._request.assert_awaited_once_with( - expected_route, query={"with_counts": "true", "with_expiration": "true"} + expected_route, query={"with_counts": "true", "with_expiration": "false"} ) rest_client._entity_factory.deserialize_invite.assert_called_once_with({"code": "Jx4cNGG"})