mirror Discord replies as replies on X and bluesky

Replying to a message on the watched channel now posts the reply as a
reply to the posts that message produced, instead of as a standalone
post.

Discord tells us the parent through MessageReference, and the store maps
it back to the Ref each output returned; that Ref rides along on the new
Post.ReplyTo. X takes it as in_reply_to_tweet_id. Bluesky needs the
thread root as well as the parent, so a Ref now carries the root it was
posted under and a post that is not itself a reply acts as its own root.

Replying to something we never distributed, an error notice from the bot
for instance, still posts normally.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-26 11:55:28 +09:00
parent 067c9252c9
commit 1c2ab29404
6 changed files with 75 additions and 10 deletions

18
main.go
View File

@@ -114,7 +114,8 @@ func (dist *distributor) reportf(format string, args ...any) {
dist.d.Write(errstr)
}
// created posts a new Discord message to every output.
// created posts a new Discord message to every output, as a reply when the
// Discord message itself was a reply to something we already distributed.
func (dist *distributor) created(event discord.Event) {
if length := utf8.RuneCountInString(event.Content); length > maxTweetLength {
dist.reportf("Error: message is %d characters, exceeding the %d character limit; not posted", length, maxTweetLength)
@@ -131,12 +132,23 @@ func (dist *distributor) created(event discord.Event) {
return
}
// A reply to a message we never distributed becomes a top level post.
var parents store.Refs
if event.ReplyToID != "" {
parents, _ = dist.store.Get(event.ReplyToID)
}
refs := store.Refs{}
for _, out := range dist.outputs {
ref, err := out.Write(output.Post{
post := output.Post{
Text: event.Content,
Images: images,
})
}
if parent, ok := parents[out.GetName()]; ok && !parent.IsZero() {
post.ReplyTo = &parent
}
ref, err := out.Write(post)
if err != nil {
dist.reportf("%s Error: %s", out.GetName(), err)
continue