From 941fc5fcef1b8778020abb169d24170444704820 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Sun, 15 Sep 2024 23:26:46 -0700 Subject: [PATCH] beemo: config arg to require min words to notify --- cmd/beemo/main.go | 6 ++++++ cmd/beemo/notify_mentions.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/cmd/beemo/main.go b/cmd/beemo/main.go index 544ee3d84..311bd1cb0 100644 --- a/cmd/beemo/main.go +++ b/cmd/beemo/main.go @@ -106,6 +106,12 @@ func run(args []string) error { Required: true, EnvVars: []string{"BEEMO_MENTION_DIDS"}, }, + &cli.IntFlag{ + Name: "minimum-words", + Usage: "minimum length of post text (word count; zero for no minimum)", + Value: 0, + EnvVars: []string{"BEEMO_MINIMUM_WORDS"}, + }, }, }, } diff --git a/cmd/beemo/notify_mentions.go b/cmd/beemo/notify_mentions.go index 96026ecf6..7e4c5d143 100644 --- a/cmd/beemo/notify_mentions.go +++ b/cmd/beemo/notify_mentions.go @@ -19,11 +19,19 @@ type MentionChecker struct { mentionDIDs []syntax.DID logger *slog.Logger directory identity.Directory + minimumWords int } func (mc *MentionChecker) ProcessPost(ctx context.Context, did syntax.DID, rkey syntax.RecordKey, post appbsky.FeedPost) error { mc.logger.Debug("processing post record", "did", did, "rkey", rkey) + if mc.minimumWords > 0 { + words := strings.Split(post.Text, " ") + if len(words) < mc.minimumWords { + return nil + } + } + for _, facet := range post.Facets { for _, feature := range facet.Features { mention := feature.RichtextFacet_Mention @@ -57,6 +65,7 @@ func notifyMentions(cctx *cli.Context) error { ctx := context.Background() logger := configLogger(cctx, os.Stdout) relayHost := cctx.String("relay-host") + minimumWords := cctx.Int("minimum-words") mentionDIDs := []syntax.DID{} for _, raw := range strings.Split(cctx.String("mention-dids"), ",") { @@ -72,6 +81,7 @@ func notifyMentions(cctx *cli.Context) error { mentionDIDs: mentionDIDs, logger: logger, directory: identity.DefaultDirectory(), + minimumWords: minimumWords, } logger.Info("beemo mention checker starting up...", "relayHost", relayHost, "mentionDIDs", mentionDIDs)