···11+package rules
22+33+import (
44+ appbsky "github.com/bluesky-social/indigo/api/bsky"
55+ "github.com/bluesky-social/indigo/automod"
66+)
77+88+var _ automod.PostRuleFunc = DistinctMentionsRule
99+1010+var mentionHourlyThreshold = 20
1111+1212+// DistinctMentionsRule looks for accounts which mention an unusually large number of distinct accounts per period.
1313+func DistinctMentionsRule(evt *automod.RecordEvent, post *appbsky.FeedPost) error {
1414+ did := evt.Account.Identity.DID.String()
1515+1616+ // Increment counters for all new mentions in this post.
1717+ var newMentions bool
1818+ for _, facet := range post.Facets {
1919+ for _, feature := range facet.Features {
2020+ mention := feature.RichtextFacet_Mention
2121+ if mention == nil {
2222+ continue
2323+ }
2424+ evt.IncrementDistinct("mentions", did, mention.Did)
2525+ newMentions = true
2626+ }
2727+ }
2828+2929+ // If there were any new mentions, check if it's gotten spammy.
3030+ if !newMentions {
3131+ return nil
3232+ }
3333+ if mentionHourlyThreshold <= evt.GetCountDistinct("mentions", did, automod.PeriodHour) {
3434+ evt.AddAccountFlag("high-distinct-mentions")
3535+ }
3636+3737+ return nil
3838+}