feat(messaging): write to a member without risking the caller - #17
Merged
Merged
Conversation
A member who has closed their direct messages, who shares no server with the bot any more, or who has blocked it cannot be written to. Letting that throw abandons whatever the caller was in the middle of — which is usually the punishment or the decision the message was only announcing, so the member escapes the ban by having closed their DMs. DirectMessage reports whether the message landed and leaves the caller to decide whether it mattered. Being unable to reach someone is logged at info rather than error: it says nothing about the health of the bot, and reporting it loudly only teaches whoever reads the log to ignore it. RecordingLogger now keeps the level each message was logged at, so that last part is something a test can hold the framework to.
|
🎉 This PR is included in version 0.11.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.
A member who has closed their direct messages, who shares no server with the bot any more, or who has simply blocked it cannot be written to. Every bot hits this, and the failure mode is nastier than it looks: letting the DM throw abandons whatever the caller was in the middle of, which is usually the punishment or the decision the message was only announcing. The member escapes the ban by having closed their DMs.
Returns whether the member could be reached, and leaves the caller to decide whether it mattered. Reaching someone is almost never a precondition for the thing being announced.
Two small decisions:
info, noterror. Closed DMs say nothing about the health of the bot; reporting them loudly only teaches whoever reads the log to ignore it.RecordingLoggernow keeps the level alongside the message, so this is something a test can actually hold the framework to rather than a claim in a docblock.MessageBuilder|string. Most of what a bot says privately is one line, and building a message for it says nothing the string does not.Lifted from a bot that had written this same class, having first learned the hard way why it needed to exist.
🤖 Generated with Claude Code