mirror Discord deletions to X and bluesky

Deleting a message on the watched channel now deletes the posts it
produced. Making that possible reshapes how a message reaches an output:

  - OutputInterface takes an output.Post and returns an output.Ref, the
    identifier the platform gave the new post (tweet ID for X, URI and
    CID for bluesky). It also gained Delete(Ref).
  - The discord package no longer forwards raw MessageCreate values but
    a discord.Event carrying the kind of change, so the MessageDelete
    handler can use the same channel. Deleted messages arrive without an
    author, so only the channel ID can be filtered on.
  - The new store package remembers Discord message ID -> per output Ref.
    Set POST_STORE to a path to keep that mapping across restarts;
    without it the mapping is memory only and a restart makes older
    messages undeletable. It holds the most recent 1000 messages.

main.go grows a distributor type to hold the outputs and the store
rather than threading them through the event loop.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-26 11:54:29 +09:00
parent 4bd51a31a8
commit 067c9252c9
11 changed files with 753 additions and 62 deletions

19
output/bluesky_test.go Normal file
View File

@@ -0,0 +1,19 @@
package output
import "testing"
func TestRecordKey(t *testing.T) {
rkey, err := recordKey("at://did:plc:abc123/app.bsky.feed.post/3kqz7xyz")
if err != nil {
t.Fatal(err)
}
if rkey != "3kqz7xyz" {
t.Errorf("recordKey = %q, want 3kqz7xyz", rkey)
}
for _, uri := range []string{"", "at://did:plc:abc123/app.bsky.feed.post/", "nonsense"} {
if _, err := recordKey(uri); err == nil {
t.Errorf("recordKey(%q) returned no error", uri)
}
}
}