diff --git a/changes/1659.feature.md b/changes/1659.feature.md new file mode 100644 index 0000000000..11b107d0f5 --- /dev/null +++ b/changes/1659.feature.md @@ -0,0 +1 @@ +Add `approximate_member_count` and `approximate_presence_count` to `OwnGuild`. diff --git a/hikari/applications.py b/hikari/applications.py index c60ab6eee2..e6472e3fdd 100644 --- a/hikari/applications.py +++ b/hikari/applications.py @@ -308,6 +308,12 @@ class OwnGuild(guilds.PartialGuild): my_permissions: permissions_.Permissions = attrs.field(eq=False, hash=False, repr=False) """The guild-level permissions that apply to the current user or bot.""" + approximate_member_count: int = attrs.field(eq=False, hash=False, repr=True) + """The approximate amount of members in this guild.""" + + approximate_active_member_count: int = attrs.field(eq=False, hash=False, repr=True) + """The approximate amount of presences in this guild.""" + @attrs.define(hash=True, kw_only=True, weakref_slot=False) class OwnApplicationRoleConnection: diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index d636906337..0aee23fefd 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -589,6 +589,8 @@ def deserialize_own_guild(self, payload: data_binding.JSONObject) -> application features=[guild_models.GuildFeature(feature) for feature in payload["features"]], is_owner=bool(payload["owner"]), my_permissions=permission_models.Permissions(int(payload["permissions"])), + approximate_member_count=int(payload["approximate_member_count"]), + approximate_active_member_count=int(payload["approximate_presence_count"]), ) def deserialize_own_application_role_connection( diff --git a/hikari/impl/special_endpoints.py b/hikari/impl/special_endpoints.py index f760d7353c..c2a3eb99eb 100644 --- a/hikari/impl/special_endpoints.py +++ b/hikari/impl/special_endpoints.py @@ -598,6 +598,7 @@ def __init__( async def _next_chunk(self) -> typing.Optional[typing.Generator[applications.OwnGuild, typing.Any, None]]: query = data_binding.StringMapBuilder() + query.put("with_counts", True) query.put("before" if self._newest_first else "after", self._first_id) # We rely on Discord's default for the limit here since for this endpoint this has always scaled # along side the maximum page size limit to match the maximum amount of guilds a user can be in. diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 9ad10d4920..e4c22f4a12 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -895,16 +895,21 @@ def own_guild_payload(self): "owner": False, "permissions": "2147483647", "features": ["DISCOVERABLE", "FORCE_RELAY"], + "approximate_member_count": 3268, + "approximate_presence_count": 784, } def test_deserialize_own_guild(self, entity_factory_impl, mock_app, own_guild_payload): own_guild = entity_factory_impl.deserialize_own_guild(own_guild_payload) + assert own_guild.id == 152559372126519269 assert own_guild.name == "Isopropyl" assert own_guild.icon_hash == "d4a983885dsaa7691ce8bcaaf945a" assert own_guild.features == [guild_models.GuildFeature.DISCOVERABLE, "FORCE_RELAY"] assert own_guild.is_owner is False assert own_guild.my_permissions == permission_models.Permissions(2147483647) + assert own_guild.approximate_member_count == 3268 + assert own_guild.approximate_active_member_count == 784 def test_deserialize_own_guild_with_null_and_unset_fields(self, entity_factory_impl): own_guild = entity_factory_impl.deserialize_own_guild( @@ -915,6 +920,8 @@ def test_deserialize_own_guild_with_null_and_unset_fields(self, entity_factory_i "owner": False, "permissions": "2147483647", "features": ["DISCOVERABLE", "FORCE_RELAY"], + "approximate_member_count": 3268, + "approximate_presence_count": 784, } ) assert own_guild.icon_hash is None diff --git a/tests/hikari/impl/test_special_endpoints.py b/tests/hikari/impl/test_special_endpoints.py index 4eefd3bbee..836eb1fb75 100644 --- a/tests/hikari/impl/test_special_endpoints.py +++ b/tests/hikari/impl/test_special_endpoints.py @@ -100,9 +100,9 @@ async def test_aiter(self): ) mock_request.assert_has_awaits( [ - mock.call(compiled_route=expected_route, query={"after": "123321"}), - mock.call(compiled_route=expected_route, query={"after": "123321124123"}), - mock.call(compiled_route=expected_route, query={"after": "12332112432234"}), + mock.call(compiled_route=expected_route, query={"after": "123321", "with_counts": "true"}), + mock.call(compiled_route=expected_route, query={"after": "123321124123", "with_counts": "true"}), + mock.call(compiled_route=expected_route, query={"after": "12332112432234", "with_counts": "true"}), ] ) @@ -148,9 +148,9 @@ async def test_aiter_when_newest_first(self): ) mock_request.assert_has_awaits( [ - mock.call(compiled_route=expected_route, query={"before": "55555555555555555"}), - mock.call(compiled_route=expected_route, query={"before": "1213321124123"}), - mock.call(compiled_route=expected_route, query={"before": "1213321123123"}), + mock.call(compiled_route=expected_route, query={"before": "55555555555555555", "with_counts": "true"}), + mock.call(compiled_route=expected_route, query={"before": "1213321124123", "with_counts": "true"}), + mock.call(compiled_route=expected_route, query={"before": "1213321123123", "with_counts": "true"}), ] ) @@ -168,7 +168,8 @@ async def test_aiter_when_empty_chunk(self, newest_first: bool): assert result == [] mock_entity_factory.deserialize_own_guild.assert_not_called() - query = {"before" if newest_first else "after": "123321"} + order_key = "before" if newest_first else "after" + query = {order_key: "123321", "with_counts": "true"} mock_request.assert_awaited_once_with(compiled_route=expected_route, query=query)