Skip to content

Commit

Permalink
make auto_chunk work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0Developer committed Aug 8, 2023
1 parent 509630d commit 4f2af84
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hikari/impl/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
):
Expand Down
30 changes: 30 additions & 0 deletions tests/hikari/impl/test_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f2af84

Please sign in to comment.