一键导入
gateway-cache-sync-keeper
// Maintain gateway event handlers — payload hydration, cache mutation, event return shapes, and handler registration. Use when touching WebSockets/Events, Handlers.php, or Event.php.
// Maintain gateway event handlers — payload hydration, cache mutation, event return shapes, and handler registration. Use when touching WebSockets/Events, Handlers.php, or Event.php.
Maintain test and documentation alignment — PHPUnit tests, async testing patterns, PHPDoc contracts, guide pages, and documentation workflow. Use when adding tests, updating docs, or changing public behavior.
Maintain Builder classes — outbound payload construction, validation, serialization, component handling, and fromPart symmetry. Use when changing Builders or outbound Discord API payloads.
Work with DiscordPHP's infrastructure utilities — CacheWrapper, CacheConfig, BigInt, Multipart, Endpoint::bind URL templates, Collection base class, and domain Exceptions. Use when changing cache behavior, REST endpoint routing, file uploads, big-integer ID math, or adding/modifying exceptions.
Maintain interaction flow — Interaction typing, resolved data caching, command routing, autocomplete, modal responses, and interaction builders. Use when touching Interactions or slash command handling.
Maintain the optional prefix-command layer — DiscordCommandClient, Command class, parsing, aliases, cooldowns, and help system. Use when touching message-based command handling.
Maintain Part domain models — fillable attributes, mutators, typed nested data, save/fetch behavior, permission checks, PHPDoc, and repository bindings. Use when adding or modifying any Discord Part class.
| name | gateway-cache-sync-keeper |
| description | Maintain gateway event handlers — payload hydration, cache mutation, event return shapes, and handler registration. Use when touching WebSockets/Events, Handlers.php, or Event.php. |
Use this skill when work touches:
src/Discord/WebSockets/Handlers.phpsrc/Discord/WebSockets/Event.phpsrc/Discord/WebSockets/Events/*This is event-to-cache coherence skill. Load it when changing gateway dispatch behavior, event return shapes, or cache mutation.
Keep gateway handling as real-time state sync layer:
src/Discord/WebSockets/Event.phpsrc/Discord/WebSockets/Handlers.phpsrc/Discord/WebSockets/Events/MessageCreate.phpsrc/Discord/WebSockets/Events/MessageUpdate.phpsrc/Discord/WebSockets/Events/GuildCreate.phpsrc/Discord/WebSockets/Events/GuildDelete.phpsrc/Discord/WebSockets/Events/InteractionCreate.phpsrc/Discord/WebSockets/Events/ThreadListSync.phpsrc/Discord/WebSockets/Events/GuildMemberAdd.phpEvent classes in this repo are not dumb payload forwarders. They:
TYPES mapslast_message_idIf handler only hydrates one object and ignores related caches, change is probably incomplete.
When adding or changing event family, inspect all three:
src/Discord/WebSockets/Event.php — constantsrc/Discord/WebSockets/Handlers.php — registrationsrc/Discord/WebSockets/Events/<Name>.php — implementationIf one changes and the others do not, make sure that is intentional.
cacheUser(object $userdata)Use when payload contains user data. Keeps top-level user cache current.
cacheMember(MemberRepository $members, array $memberdata)Use when payload contains guild member data. Keeps guild member cache current. Some event families override details for performance reasons, like InteractionCreate.
Do not manually duplicate user/member cache update logic unless event family has special latency or shape constraints.
Use factory plus subtype maps when payload family is polymorphic:
Channel::TYPESInteraction::TYPESTYPESDo not push raw stdClass payloads deep into caches when repo already has typed part model.
Preserve those shapes unless you have strong compatibility reason to change them.
These are easy to break because they carry many side effects:
last_message_id currentIf you change MessageCreate or MessageUpdate, inspect:
Guild events often do bulk cache work:
Do not treat guild create as "just one guild part". It is bootstrap event for several nested repositories.
Threads are child collections hanging off parent channels. Thread handlers usually must:
threads repoInteraction handlers are latency-sensitive. They still must:
Userland listens to emitted values. Keep return shapes stable and meaningful.
Common patterns already used:
MessageCreate returns new MessageMessageUpdate returns [newOrData, oldMessage]GuildDelete returns [$guildPartOrData, $unavailableFlag]Before changing a return shape, inspect:
When changing event behavior, walk this checklist:
If you cannot answer each, handler is not fully understood yet.
When adding new dispatch type:
Event.phpHandlers.phpGateway payloads are not always full objects.
Examples:
MESSAGE_CONTENT intentDo not blindly overwrite cached richer state with partial payload unless code already accounts for missing fields.
Stop if you see:
Gateway events are cache-synchronization code. Treat them like consistency-critical logic, not like thin adapters. One missed repository update can make the whole object graph lie.