Phase 1, part 3: Reddit
- Sign in with a Reddit web app; access tokens refresh automatically, and an app-only token reads rules before sign-in. - Reddit drafts: a title and text for one subreddit, chosen when writing. The subreddit's guidelines and rules go into the prompt, which asks for a community member's post that discloses the affiliation and avoids marketing language. - The Inbox shows the subreddit's rules (cached for a day, with Refresh) and warns, without blocking, about promotion rules, restricted subreddits, link-only subreddits, posting in the same subreddit within a week, more than 1 in 10 recent posts linking to the company's sites, and new accounts. - Publishing makes a text post with the source link at the end, or a link post where the subreddit takes only links. - Migration 4 adds the draft's title and subreddit, and the rules cache. Publishers now take a Post, which carries the title and subreddit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,9 +10,17 @@ import (
|
||||
"supermarket/internal/utm"
|
||||
)
|
||||
|
||||
// Post is what a publisher sends.
|
||||
type Post struct {
|
||||
Text string
|
||||
SourceURL string // tagged, if it's the company's
|
||||
Title string // Reddit
|
||||
Target string // Reddit: the subreddit
|
||||
}
|
||||
|
||||
// Publisher posts to one channel and returns the post's URL.
|
||||
type Publisher interface {
|
||||
Publish(ctx context.Context, text, sourceURL string) (string, error)
|
||||
Publish(ctx context.Context, p Post) (string, error)
|
||||
}
|
||||
|
||||
// Publishers are the channels that can post now, by channel ID.
|
||||
@@ -39,13 +47,8 @@ func Publish(ctx context.Context, d *db.DB, pubs Publishers, tags *utm.Tagger, i
|
||||
if pub == nil {
|
||||
return dr, fmt.Errorf("%s isn't connected: sign in under Settings → Credentials", dr.ChannelName())
|
||||
}
|
||||
if dr.TooLong() {
|
||||
withLink := ""
|
||||
if dr.Channel == ChannelX && dr.SourceURL != "" {
|
||||
withLink = " including the link"
|
||||
}
|
||||
return dr, fmt.Errorf("the post is %d characters%s; %s allows %d. Shorten it first",
|
||||
dr.Length(), withLink, dr.ChannelName(), dr.Limit())
|
||||
if problem := dr.Problem(); problem != "" {
|
||||
return dr, fmt.Errorf("%s. Fix it first", problem)
|
||||
}
|
||||
|
||||
res, err := d.Exec(`UPDATE drafts SET status = ?, error = '', updated_at = ? WHERE id = ? AND status IN (?, ?, ?)`,
|
||||
@@ -62,7 +65,7 @@ func Publish(ctx context.Context, d *db.DB, pubs Publishers, tags *utm.Tagger, i
|
||||
p := dr.UTM()
|
||||
text, src = tags.Text(text, p), tags.URL(src, p)
|
||||
}
|
||||
postURL, pubErr := pub.Publish(ctx, text, src)
|
||||
postURL, pubErr := pub.Publish(ctx, Post{Text: text, SourceURL: src, Title: dr.Title, Target: dr.Target})
|
||||
now := formatTime(time.Now())
|
||||
if pubErr != nil {
|
||||
if _, err := d.Exec(`UPDATE drafts SET status = ?, error = ?, updated_at = ? WHERE id = ?`,
|
||||
|
||||
Reference in New Issue
Block a user