Repository navigation
feat(plugin-gateway): add parseEmoji and resolvePartialEmoji utils - #157
Conversation
Moves the duplicated emoji parsing from ReactionEmoji and MessagePayload into util/Util.ts, like discord.js's Util.js.
There was a problem hiding this comment.
✅ 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, barename:idpair, or (forresolvePartialEmoji) a bare snowflake string or{id,name,animated}object — modeled on discord.js'sUtil.jsequivalents, 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 toresolvePartialEmojiinstead of duplicating the parsing regexes inline.MessagePayload's poll-answer emoji path: its localresolvePartialEmojihelper (renamedtoPollEmoji) 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.tscoverage forparseEmoji/resolvePartialEmoji, plus a newmessage-payload.test.tscase 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.
Claude Sonnet | 𝕏

🔗 Linked issue
Follow-up to #156.
📚 Description
Emoji strings were parsed in two places with different rules.
ReactionEmoji.resolveIdentifier/resolvePartialusedFormattingPatterns.Emojiplus aname:idpattern. The poll answer path inMessagePayloadused a looser regex of its own that treated a bare ID as an emoji name. Both now go throughparseEmojiandresolvePartialEmojiinutil/Util.ts, which match the functions of the same name in discord.js'sUtil.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.resolvePartialstays public and delegates. It could be deprecated in favour ofresolvePartialEmojilater if you'd rather have one entry point.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.