Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add with_counts information for OwnGuilds #1659

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1659.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `approximate_member_count` and `approximate_presence_count` to `OwnGuild`.
6 changes: 6 additions & 0 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions hikari/impl/special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions tests/hikari/impl/test_special_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
]
)

Expand Down Expand Up @@ -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"}),
]
)

Expand All @@ -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)


Expand Down