Skip to content

feat: count reactions and poll votes in the cache and emit their gateway events - #104

Merged
RedStar071 merged 2 commits into
feat/structure-guildfrom
feat/reactions
Sep 25, 2026
Merged

RedStar071 merged 2 commits into
feat/structure-guildfrom
feat/reactions

Conversation

@RedStar071

Copy link
Copy Markdown
Member

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.reactions stayed whatever the message had when it was created. The reaction and poll vote dispatches only reached raw.

📚 Description

plugin-cache. Reactions and poll votes now update the cached message: counts, count_details, me/me_burst and me_voted. The work is done by small pure functions in lib/reactions.ts, run through a new update cache operation (read, transform, write; nothing is written when the key isn't cached). The dispatches only carry the voter's ID, so createCacheOperations and applyGatewayDispatch take an optional { clientUserId } context for the me flags. Guild reactions carry the reacting member, so that member and their user are upserted too, the same way MESSAGE_CREATE handles its author.

plugin-gateway. It passes the bot's ID as that context and emits discord.js's events:

Event Arguments
messageReactionAdd / messageReactionRemove reaction, user | null, { userId, type, burst }
messageReactionRemoveAll message | null, the reactions the cache held, data
messageReactionRemoveEmoji the removed reaction
messagePollVoteAdd / messagePollVoteRemove answer, userId

Reactions 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 (count is null), and the answer only has its ID. discord.js calls these partials.

One difference from discord.js: user is null when neither the payload nor the cache has the user. That happens for reactions outside of guilds, where Discord sends no member. details.userId always has the ID. I preferred that over fetching the user from the REST API on every reaction.

Key changes

Area Change
@wolfstar/plugin-cache update operation, CacheOperationContext, reaction and poll vote counting
@wolfstar/plugin-gateway Six events, bot ID passed to the cache

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

🤖 AI disclosure: Wolfstar Agent Kit modified this description. My AI open-source policy.

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

◈ PR Lens

PR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  • update cache operation: a new CacheOperation variant (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 cached APIMessage.
  • CacheOperationContext: createCacheOperations/applyGatewayDispatch now take an optional { clientUserId }, needed because reaction/poll-vote dispatches only carry the voter's ID, not the bot's — used to compute me/me_burst/me_voted.
  • Pure reaction/poll math (lib/reactions.ts): addReaction, removeReaction, removeReactionEmoji, countPollVote mutate a cached message's reactions/poll.results immutably.
  • Guild reaction member upsert: MESSAGE_REACTION_ADD in a guild upserts the reacting member/user, mirroring the existing MESSAGE_CREATE author-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, with before hooks capturing pre-update state for the two "removed" events.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Claude Sonnet | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-api@104

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-cache@104

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-gateway@104

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-i18next@104

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-logger@104

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-subcommands-advanced@104

commit: 3c12fd4

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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: null contract 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, returning count: 0 (not null) for the latter.
  • Updated JSDoc: reactionOf's comment and the messageReactionRemove event doc in util/events.ts now describe the actual contract.
  • Added a regression test: tests/reactions.test.ts asserts count is 0 after 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.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@RedStar071
RedStar071 merged commit 90d77c9 into main Sep 25, 2026
18 of 25 checks passed
@RedStar071
RedStar071 deleted the feat/reactions branch September 25, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant