Skip to content

Commit

Permalink
beemo: config arg to require min words to notify
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Sep 16, 2024
1 parent 4302826 commit 941fc5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/beemo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
},
}
Expand Down
10 changes: 10 additions & 0 deletions cmd/beemo/notify_mentions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"), ",") {
Expand All @@ -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)
Expand Down

0 comments on commit 941fc5f

Please sign in to comment.