Reddit: posted by hand, with the rules pasted

Reddit's API isn't open to apps like this one, so Supermarket no longer
signs in to Reddit, publishes or schedules there, or reads subreddits and
the account's posts. The internal/api/reddit client, Reddit's OAuth, its
keys and its Social accounts card are gone.

Supermarket still writes the post. Each Reddit draft in Posts has a box
for its subreddit's rules, with a link to them on Reddit: pasted once,
they're kept (subreddits.data, as pasted_rules) and given to the model
for later drafts. Open in Reddit saves the edits and opens the submit
page filled in; Copy title and Copy text (with the tagged source link)
cover a box that comes up empty; Mark as posted records it. Warnings come
from the pasted rules and the posts marked as posted. Fill's subreddit
suggestions are kept unchecked, and say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 11:48:54 -07:00
co-authored by Claude Opus 5.5
parent bae468e01c
commit 5451fe6d63
33 changed files with 382 additions and 1107 deletions
+9 -18
View File
@@ -8,7 +8,6 @@ import (
"strings"
"supermarket/internal/ai"
"supermarket/internal/api/reddit"
"supermarket/internal/api/twitter"
"supermarket/internal/inventory"
"supermarket/internal/profile"
@@ -24,7 +23,7 @@ type Request struct {
// Reddit: the subreddit to write for, and what's known about it (nil
// if its rules couldn't be read).
Subreddit string
SubredditInfo *reddit.Subreddit
SubredditInfo *Subreddit // the rules pasted for it; nil if none
// Signal, if set, is the buying signal the posts are written for.
Signal *signals.Signal
}
@@ -133,7 +132,7 @@ func Generate(ctx context.Context, client ai.Client, req Request) ([]Draft, erro
title = string(r[:RedditTitleLimit-1]) + "…"
}
drafts = append(drafts, Draft{InventoryName: name, Kind: req.Entry.Relationship, Channel: ch, SignalID: req.signalID(),
Title: title, Target: reddit.CleanName(req.Subreddit), Content: strings.TrimSpace(rp.Body),
Title: title, Target: CleanSubreddit(req.Subreddit), Content: strings.TrimSpace(rp.Body),
SourceURL: src, ItemIDs: ids, Status: StatusDraft})
continue
}
@@ -314,7 +313,7 @@ func oneLine(s string) string {
// punishes marketing, so the rules are stricter than for other channels.
func redditInstructions(req Request) string {
var b strings.Builder
sub := reddit.CleanName(req.Subreddit)
sub := CleanSubreddit(req.Subreddit)
fmt.Fprintf(&b, "- reddit: an object with a title (at most %d characters) and a body, for r/%s. "+
"Write as a member of the community who works at %s, and say so plainly in the body (\"I work at %s\"). "+
"Lead with what's useful or interesting to this community, not with the company. No hashtags, no emoji, no marketing language, "+
@@ -326,20 +325,12 @@ func redditInstructions(req Request) string {
"about it, and invite questions and feedback.\n")
}
if info := req.SubredditInfo; info != nil {
b.WriteString("<subreddit>\n")
if info.Description != "" {
fmt.Fprintf(&b, "About r/%s: %s\n", sub, oneLine(info.Description))
}
if info.SubmitText != "" {
fmt.Fprintf(&b, "Posting guidelines: %s\n", oneLine(truncateRunes(info.SubmitText, 1500)))
}
for i, r := range info.Rules {
if r.Kind == "comment" {
continue
}
fmt.Fprintf(&b, "Rule %d: %s. %s\n", i+1, r.Name, oneLine(truncateRunes(r.Description, 400)))
}
b.WriteString("</subreddit>\n")
b.WriteString("<subreddit_rules>\n")
b.WriteString(truncateRunes(info.Rules, 6000))
b.WriteString("\n</subreddit_rules>\n")
} else {
fmt.Fprintf(&b, " r/%s's rules weren't given: follow Reddit's usual norms (no self-promotion beyond one post in ten, no spam), "+
"and keep the post useful even if promotion turns out to be forbidden.\n", sub)
}
return b.String()
}