From 4f2af84f13c41947e18e7d8503bc9b79cbe7ec2a Mon Sep 17 00:00:00 2001 From: Leo Developer Date: Tue, 8 Aug 2023 13:43:09 +0200 Subject: [PATCH] make auto_chunk work as expected --- hikari/impl/event_manager.py | 6 +++-- tests/hikari/impl/test_event_manager.py | 30 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/hikari/impl/event_manager.py b/hikari/impl/event_manager.py index 9074983a81..2b1a8cfe7c 100644 --- a/hikari/impl/event_manager.py +++ b/hikari/impl/event_manager.py @@ -375,9 +375,11 @@ async def on_guild_create( # noqa: C901, CFQ001 - Function too complex and too self._auto_chunk_members and self._intents & intents_.Intents.GUILD_MEMBERS and (payload.get("large") or not presences_declared) - and (self._cache is None or not self._cache.settings.only_my_member) and ( - self._cache_enabled_for(config.CacheComponents.MEMBERS) + ( + self._cache_enabled_for(config.CacheComponents.MEMBERS) + and (self._cache is None or not self._cache.settings.only_my_member) + ) or self._enabled_for_event(shard_events.MemberChunkEvent) ) ): diff --git a/tests/hikari/impl/test_event_manager.py b/tests/hikari/impl/test_event_manager.py index 8332bead44..51af536357 100644 --- a/tests/hikari/impl/test_event_manager.py +++ b/tests/hikari/impl/test_event_manager.py @@ -660,6 +660,36 @@ async def test_on_guild_create_when_members_declared_and_member_cache_enabled( mock_request_guild_members.return_value, name="123:456 guild create members request" ) + @pytest.mark.asyncio() + async def test_on_guild_create_when_members_declared_and_member_cache_but_only_my_member_enabled( + self, event_manager_impl, shard, event_factory, entity_factory + ): + shard.id = 123 + event_manager_impl._intents = intents.Intents.GUILD_MEMBERS + event_manager_impl._cache_enabled_for = mock.Mock(return_value=True) + event_manager_impl._enabled_for_event = mock.Mock(return_value=False) + event_manager_impl._cache.settings.only_my_member = True + shard.get_user_id.return_value = 1 + gateway_guild = entity_factory.deserialize_gateway_guild.return_value + gateway_guild.channels.return_value = {1: "channel1", 2: "channel2"} + gateway_guild.emojis.return_value = {1: "emoji1", 2: "emoji2"} + gateway_guild.roles.return_value = {1: "role1", 2: "role2"} + gateway_guild.voice_states.return_value = {1: "voice1", 2: "voice2"} + gateway_guild.presences.return_value = {1: "presence1", 2: "presence2"} + gateway_guild.members.return_value = {1: "member1", 2: "member2"} + gateway_guild.stickers.return_value = {1: "sticker1", 2: "sticker2"} + gateway_guild.threads.return_value = {1: "thread1", 2: "thread2"} + + mock_request_guild_members = mock.Mock() + + with mock.patch.object(asyncio, "create_task") as create_task: + with mock.patch.object(event_manager, "_fixed_size_nonce", return_value="abc"): + with mock.patch.object(event_manager, "_request_guild_members", new=mock_request_guild_members): + await event_manager_impl.on_guild_create(shard, {"id": 456, "large": False}) + + mock_request_guild_members.assert_not_called() + create_task.assert_not_called() + @pytest.mark.asyncio() async def test_on_guild_create_when_members_declared_and_enabled_for_member_chunk_event( self, stateless_event_manager_impl, shard, event_factory, entity_factory