feat(format): spell Discord's message markup once - #12
Merged
Merged
Conversation
Mentions, timestamps and custom emoji are assembled by hand wherever a message is built, and one assembled slightly wrong renders as literal text rather than failing: the bot shows `<@123>` to its users and nothing says why. Format holds the shapes so they are written correctly in one place. Timestamp styles are an enum rather than the single letter the API takes, since nothing about 'R' says "2 months ago" at a call site.
|
🎉 This PR is included in version 1.2.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mentions, timestamps and custom emoji get assembled by hand wherever a message is built, and one assembled slightly wrong renders as literal text rather than failing — the bot shows
<@123>to its users and nothing in the logs says why.Formatholds the shapes so they are written correctly in one place.Two things worth pointing out:
'R'says "2 months ago" at a call site, and the letters are case-sensitive in a way that is easy to get wrong (dandDare different formats). The default matches Discord's own default when no style is given.timestamp()takesint|DateTimeInterface. Seconds because that is what the API takes, and a native date because that is what most callers have. It deliberately knows nothing about any particular datetime library.This came out of a bot that had grown its own copy of exactly these five helpers.
🤖 Generated with Claude Code