From 091cbdaa149fe9f0889af2f5d7b3015bff975a5f Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sat, 26 Oct 2024 09:40:43 -0400 Subject: cmd/stealthmountain: make the code easier to read Signed-off-by: Xe Iaso --- cmd/stealthmountain/main.go | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'cmd/stealthmountain') diff --git a/cmd/stealthmountain/main.go b/cmd/stealthmountain/main.go index 536bacf..268f20f 100644 --- a/cmd/stealthmountain/main.go +++ b/cmd/stealthmountain/main.go @@ -88,39 +88,41 @@ func main() { continue } - if sneakPeakRegex.MatchString(post.Text) { - actorID := m.Header.Get("bsky-actor-did") - slog.Info("found a stealth mountain!", "id", commit.Rev, "actor", actorID) - reply, err := bsky.NewPostBuilder(`I think you mean "sneak peek"`).Build() - if err != nil { - slog.Error("can't build reply post", "err", err) - } - parent := comatproto.RepoStrongRef{ - LexiconTypeID: "app.bsky.feed.post", - Uri: fmt.Sprintf("at://%s/app.bsky.feed.post/%s", actorID, commit.RKey), - Cid: commit.CID, - } - root := parent - - if post.Reply != nil { - root = *post.Reply.Root - } - - reply.Reply = &bskyData.FeedPost_ReplyRef{ - Parent: &parent, - Root: &root, - } - - reply.CreatedAt = time.Now().UTC().Format(time.RFC3339) - - cid, uri, err := bsAgent.PostToFeed(ctx, reply) - if err != nil { - slog.Error("cannot post to feed", "err", err) - continue - } - - slog.Info("posted to bluesky", "bluesky_cid", cid, "bluesky_uri", uri) + if !sneakPeakRegex.MatchString(post.Text) { + continue + } + + actorID := m.Header.Get("bsky-actor-did") + slog.Info("found a stealth mountain!", "id", commit.Rev, "actor", actorID) + reply, err := bsky.NewPostBuilder(`I think you mean "sneak peek"`).Build() + if err != nil { + slog.Error("can't build reply post", "err", err) } + parent := comatproto.RepoStrongRef{ + LexiconTypeID: "app.bsky.feed.post", + Uri: fmt.Sprintf("at://%s/app.bsky.feed.post/%s", actorID, commit.RKey), + Cid: commit.CID, + } + root := parent + + if post.Reply != nil { + root = *post.Reply.Root + } + + reply.Reply = &bskyData.FeedPost_ReplyRef{ + Parent: &parent, + Root: &root, + } + + reply.CreatedAt = time.Now().UTC().Format(time.RFC3339) + + cid, uri, err := bsAgent.PostToFeed(ctx, reply) + if err != nil { + slog.Error("cannot post to feed", "err", err) + continue + } + + slog.Info("posted to bluesky", "bluesky_cid", cid, "bluesky_uri", uri) } } -- cgit v1.2.3