Skip to content

feat(messaging): write to a member without risking the caller - #17

Merged
mikield merged 1 commit into
masterfrom
feat/direct-messages
Sep 2, 2026
Merged

mikield merged 1 commit into
masterfrom
feat/direct-messages

Conversation

@mikield

@mikield mikield commented Sep 2, 2026

Copy link
Copy Markdown
Member

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.

$this->directMessage->send($userId, 'You have been blocked for 1 hour.');

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:

  • Logged at info, not error. Closed DMs say nothing about the health of the bot; reporting them loudly only teaches whoever reads the log to ignore it. RecordingLogger now 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

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.
@mikield
mikield merged commit ccfa40f into master Sep 2, 2026
3 of 4 checks passed
@mikield
mikield deleted the feat/direct-messages branch September 2, 2026 01:50
github-actions Bot pushed a commit that referenced this pull request Sep 2, 2026
## [0.11.0](v0.10.0...v0.11.0) (2026-09-02)

### Features

* **messaging:** write to a member without risking the caller ([#17](#17)) ([ccfa40f](ccfa40f))

### Reverts

* take scheduling back out of the core ([#18](#18)) ([63bd82e](63bd82e)), closes [#16](#16)
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 0.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant