Skip to content

feat(plugin-gateway): add parseEmoji and resolvePartialEmoji utils - #157

Merged
kodiakhq[bot] merged 1 commit into
mainfrom
refactor/gateway-emoji-util
Sep 28, 2026
Merged

kodiakhq[bot] merged 1 commit into
mainfrom
refactor/gateway-emoji-util

Conversation

@RedStar071

Copy link
Copy Markdown
Member

🔗 Linked issue

Follow-up to #156.

📚 Description

Emoji strings were parsed in two places with different rules. ReactionEmoji.resolveIdentifier/resolvePartial used FormattingPatterns.Emoji plus a name:id pattern. The poll answer path in MessagePayload used a looser regex of its own that treated a bare ID as an emoji name. Both now go through parseEmoji and resolvePartialEmoji in util/Util.ts, which match the functions of the same name in discord.js's Util.js.

Behaviour change: emoji: "123456789012345678" on a poll answer used to be sent as { name: "123456789012345678" }, and is now { id: "123456789012345678" }.

Two things I kept from our version instead of copying discord.js: the ID patterns accept 17 to 20 digits (theirs stop at 19), and a string with a colon that parses to nothing still falls back to URL-encoding it for reaction routes, as before. ReactionEmoji.resolvePartial stays public and delegates. It could be deprecated in favour of resolvePartialEmoji later if you'd rather have one entry point.

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

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.

Moves the duplicated emoji parsing from ReactionEmoji and MessagePayload
into util/Util.ts, like discord.js's Util.js.
@wolfstarbot wolfstarbot added the packages:plugin-gateway Changes in plugin-gateway label Sep 28, 2026

@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

This PR unifies two previously-divergent emoji-string-parsing implementations (ReactionEmoji's inline regex logic and a separate looser regex in the poll-answer path of MessagePayload) behind two new public utils.

  • parseEmoji/resolvePartialEmoji (util/Util.ts): new exported functions parsing a Unicode emoji, <a:name:id> mention, bare name:id pair, or (for resolvePartialEmoji) a bare snowflake string or {id,name,animated} object — modeled on discord.js's Util.js equivalents, with two documented, deliberate deviations (17–20 digit ID range instead of 17–19, and a colon-string that parses to nothing still URL-encode-falls-back for reaction routes).
  • ReactionEmoji.resolveIdentifier/resolvePartial: now delegate to resolvePartialEmoji instead of duplicating the parsing regexes inline.
  • MessagePayload's poll-answer emoji path: its local resolvePartialEmoji helper (renamed toPollEmoji) now delegates too. Documented behavior change: a bare numeric string as a poll answer emoji is now sent as { id: ... } instead of { name: ... }, covered by a new test.
  • Tests: new util.test.ts coverage for parseEmoji/resolvePartialEmoji, plus a new message-payload.test.ts case for the bare-ID behavior change.

I traced every branch of the old ReactionEmoji/MessagePayload parsing logic against the new implementation and found them behaviorally equivalent in all cases (including edge cases like empty strings, objects with neither id nor name, and colon-strings that don't parse to a custom emoji) — one edge case ({id, name: ""}) is actually a small improvement, since the old code's name ?? "_" didn't treat "" as nullish and produced a malformed identifier. Ran the affected test files (49/49 passing), oxlint (clean), and tsc --noEmit on the package (only pre-existing, unrelated @wolfstar/plugin-cache resolution errors from the build not being run in this sandbox). No stale references to the removed local helper, and no export collisions for the new PartialEmoji/PartialEmojiOnlyId types.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

@kodiakhq
kodiakhq Bot merged commit 3e54036 into main Sep 28, 2026
17 checks passed
@kodiakhq
kodiakhq Bot deleted the refactor/gateway-emoji-util branch September 28, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages:plugin-gateway Changes in plugin-gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants