Repository navigation
feat: count reactions and poll votes in the cache and emit their gateway events - #104
Conversation
◈ PR LensPR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z. |
There was a problem hiding this comment.
Important
One gap in the documented count: null contract for messageReactionRemove — see inline comment.
Reviewed changes
Reviewed the full diff (12 files, 1 commit) that makes reactions and poll votes update the cached message and emits the corresponding gateway events.
updatecache operation: a newCacheOperationvariant (operations.ts) that reads, transforms, and writes a cached value, no-op when the key isn't cached — used to apply reaction/poll-vote deltas to a cachedAPIMessage.CacheOperationContext:createCacheOperations/applyGatewayDispatchnow take an optional{ clientUserId }, needed because reaction/poll-vote dispatches only carry the voter's ID, not the bot's — used to computeme/me_burst/me_voted.- Pure reaction/poll math (
lib/reactions.ts):addReaction,removeReaction,removeReactionEmoji,countPollVotemutate a cached message'sreactions/poll.resultsimmutably. - Guild reaction member upsert:
MESSAGE_REACTION_ADDin a guild upserts the reacting member/user, mirroring the existingMESSAGE_CREATEauthor-upsert pattern. - Six new gateway events (
plugin-gateway):messageReactionAdd/Remove/RemoveAll/RemoveEmoji,messagePollVoteAdd/Remove, built from the cache after the dispatch has been counted in so they carry fresh counts, withbeforehooks capturing pre-update state for the two "removed" events.
Claude Sonnet | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the changes since the prior Pullfrog review (commit e5e4103), which fixes the one gap flagged previously.
- Fixed the
count: nullcontract gap:reactionOf(packages/plugin-gateway/src/util/dispatch.ts) now distinguishes an uncached message from a cached message whose last reaction of an emoji was just removed, returningcount: 0(notnull) for the latter. - Updated JSDoc:
reactionOf's comment and themessageReactionRemoveevent doc inutil/events.tsnow describe the actual contract. - Added a regression test:
tests/reactions.test.tsassertscountis0after removing the last reaction of an emoji from a cached message.
I verified the fix against MessageReaction's count getter (structures/MessageReaction.ts:36-37, this[kData].count ?? null) — the two partialReaction branches now correctly produce 0 vs null. The new test exercises exactly the previously-broken path and would fail without the fix. No new issues in this delta.
Claude Sonnet | 𝕏
79426e2 to
55d4acf
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|
…cached message is removed
55d4acf to
3c12fd4
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|

Stacked on #103.
🔗 Linked issue
Related to #54 and #55 (phase 7b of the roadmap).
🧭 Context
#101 added reaction and poll structures, but the cached message never changed when someone reacted or voted. So
message.reactionsstayed whatever the message had when it was created. The reaction and poll vote dispatches only reachedraw.📚 Description
plugin-cache. Reactions and poll votes now update the cached message: counts,
count_details,me/me_burstandme_voted. The work is done by small pure functions inlib/reactions.ts, run through a newupdatecache operation (read, transform, write; nothing is written when the key isn't cached). The dispatches only carry the voter's ID, socreateCacheOperationsandapplyGatewayDispatchtake an optional{ clientUserId }context for themeflags. Guild reactions carry the reacting member, so that member and their user are upserted too, the same wayMESSAGE_CREATEhandles its author.plugin-gateway. It passes the bot's ID as that context and emits discord.js's events:
messageReactionAdd/messageReactionRemovereaction,user | null,{ userId, type, burst }messageReactionRemoveAllmessage | null, the reactions the cache held,datamessageReactionRemoveEmojimessagePollVoteAdd/messagePollVoteRemoveanswer,userIdReactions and answers are read from the cached message after the dispatch has been counted in, so they carry the new counts. On an uncached message the event still fires. The reaction then has no counts (
countisnull), and the answer only has its ID. discord.js calls these partials.One difference from discord.js:
userisnullwhen neither the payload nor the cache has the user. That happens for reactions outside of guilds, where Discord sends no member.details.userIdalways has the ID. I preferred that over fetching the user from the REST API on every reaction.Key changes
@wolfstar/plugin-cacheupdateoperation,CacheOperationContext, reaction and poll vote counting@wolfstar/plugin-gatewayType of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.