Chunk Tracker#
The chunk tracker in yuyo.chunk_tracker dispatches custom chunk request tracking events. This can be a useful way to work out when the cache will be reliable for a guild or globally (when combined with checking the intent and cache config).
yuyo.chunk_tracker.ChunkTracker.from_gateway_bot(bot)
While this is easy to setup, there are some things you need to account for. This will only track chunk requests (including startup chunk requests) as long if have a set nonce (luckily Hikari's startup requests include nonces). ChunkTracker.request_guild_members ensures that a nonce is always set.
The chunk tracker can be configured to automatically send chunk requests (with nonces) on guild join itself using ChunkTracker.set_auto_chunk_members. This can be useful if you need auto chunking in scenarios where it otherwise would be disabled (e.g. when using a separate async cache instead of Hikari's builtin cache).
Events#
Chunk Request Finished Event#
ChunkRequestFinishedEvent is dispatched when a specific chunk request has finished.
@bot.listen()
async def on_chunk_request_finished(event: yuyo.chunk_tracker.ChunkRequestFinishedEvent) -> None:
event.app
event.shard # type: hikari.api.GatewayShard
event.chunk_count # type: int
event.first_received_at # type: datetime.datetime
event.guild_id # type: hikari.Snowflake
event.last_received_at # type: datetime.datetime
event.missed_chunks # type: collections.abc.Collection[int]
event.not_found_ids # type: collections.abc.Collection[hikari.Snowflake]
This is only dispatch for chunk requests where a nonce
has been set.
Finished Chunking Event#
FinishedChunkingEvent is dispatched when the startup chunking has finished for the bot to indicate that the member and presence caches should be complete (if enabled).
@bot.listen()
async def on_finished_chunking(event: yuyo.chunk_tracker.FinishedChunkingEvent) -> None:
event.app
This is only dispatched once per-bot lifetime.
Shard Finished Chunking Event#
ShardFinishedChunkingEvent is dispatched when the startup chunking has finished for a specific shard to indicate that the member and presence caches should be complete for the guilds covered by this shard.
@bot.listen()
async def on_shard_finished_chunking(event: yuyo.chunk_tracker.ShardFinishedChunkingEvent) -> None:
event.app
event.shard # type: hikari.api.GatewayShard
event.incomplete_guild_ids # collections.abc.Sequence[hikari.Snowflake]
event.missed_guild_ids # collections.abc.Sequence[hikari.Snowflake]