Skip to content

Commit

Permalink
automod: annotate rules with function types (#502)
Browse files Browse the repository at this point in the history
As discussed; pretty straight-forward
  • Loading branch information
bnewbold authored Dec 28, 2023
2 parents e711d4a + 67329b1 commit 0590ced
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions automod/rules/gtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import (
// https://en.wikipedia.org/wiki/GTUBE
var gtubeString = "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"

var _ automod.PostRuleFunc = GtubePostRule

func GtubePostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if strings.Contains(post.Text, gtubeString) {
c.AddRecordLabel("spam")
}
return nil
}

var _ automod.ProfileRuleFunc = GtubeProfileRule

func GtubeProfileRule(c *automod.RecordContext, profile *appbsky.ActorProfile) error {
if profile.Description != nil && strings.Contains(*profile.Description, gtubeString) {
c.AddRecordLabel("spam")
Expand Down
4 changes: 4 additions & 0 deletions automod/rules/hashtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/bluesky-social/indigo/automod"
)

var _ automod.PostRuleFunc = BadHashtagsPostRule

// looks for specific hashtags from known lists
func BadHashtagsPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
for _, tag := range ExtractHashtags(post) {
Expand All @@ -17,6 +19,8 @@ func BadHashtagsPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error
return nil
}

var _ automod.PostRuleFunc = TooManyHashtagsPostRule

// if a post is "almost all" hashtags, it might be a form of search spam
func TooManyHashtagsPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
tags := ExtractHashtags(post)
Expand Down
2 changes: 2 additions & 0 deletions automod/rules/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/bluesky-social/indigo/automod/countstore"
)

var _ automod.IdentityRuleFunc = NewAccountRule

// triggers on first identity event for an account (DID)
func NewAccountRule(c *automod.AccountContext) error {
// need access to IndexedAt for this rule
Expand Down
4 changes: 4 additions & 0 deletions automod/rules/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

var interactionDailyThreshold = 800

var _ automod.RecordRuleFunc = InteractionChurnRule

// looks for accounts which do frequent interaction churn, such as follow-unfollow.
func InteractionChurnRule(c *automod.RecordContext) error {
did := c.Account.Identity.DID.String()
Expand Down Expand Up @@ -37,6 +39,8 @@ func InteractionChurnRule(c *automod.RecordContext) error {
return nil
}

var _ automod.RecordRuleFunc = DeleteInteractionRule

func DeleteInteractionRule(c *automod.RecordContext) error {
did := c.Account.Identity.DID.String()
switch c.RecordOp.Collection {
Expand Down
6 changes: 6 additions & 0 deletions automod/rules/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/bluesky-social/indigo/automod"
)

var _ automod.PostRuleFunc = KeywordPostRule

func KeywordPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
for _, tok := range ExtractTextTokensPost(post) {
if c.InSet("bad-words", tok) {
Expand All @@ -18,6 +20,8 @@ func KeywordPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
return nil
}

var _ automod.ProfileRuleFunc = KeywordProfileRule

func KeywordProfileRule(c *automod.RecordContext, profile *appbsky.ActorProfile) error {
for _, tok := range ExtractTextTokensProfile(profile) {
if c.InSet("bad-words", tok) {
Expand All @@ -29,6 +33,8 @@ func KeywordProfileRule(c *automod.RecordContext, profile *appbsky.ActorProfile)
return nil
}

var _ automod.PostRuleFunc = ReplySingleKeywordPostRule

func ReplySingleKeywordPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if post.Reply != nil && !IsSelfThread(c, post) {
tokens := ExtractTextTokensPost(post)
Expand Down
4 changes: 4 additions & 0 deletions automod/rules/misleading.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func isMisleadingURLFacet(facet PostFacet, logger *slog.Logger) bool {
return false
}

var _ automod.PostRuleFunc = MisleadingURLPostRule

func MisleadingURLPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
// TODO: make this an InSet() config?
if c.Account.Identity.Handle == "nowbreezing.ntw.app" {
Expand All @@ -100,6 +102,8 @@ func MisleadingURLPostRule(c *automod.RecordContext, post *appbsky.FeedPost) err
return nil
}

var _ automod.PostRuleFunc = MisleadingMentionPostRule

func MisleadingMentionPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
// TODO: do we really need to route context around? probably
ctx := context.TODO()
Expand Down
2 changes: 2 additions & 0 deletions automod/rules/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/bluesky-social/indigo/automod"
)

var _ automod.PostRuleFunc = AccountPrivateDemoPostRule

// dummy rule. this leaks PII (account email) in logs and should never be used in real life
func AccountPrivateDemoPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if c.Account.Private != nil {
Expand Down
2 changes: 2 additions & 0 deletions automod/rules/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/bluesky-social/indigo/automod"
)

var _ automod.PostRuleFunc = AccountDemoPostRule

// this is a dummy rule to demonstrate accessing account metadata (eg, profile) from within post handler
func AccountDemoPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if c.Account.Profile.Description != nil && len(post.Text) > 5 && *c.Account.Profile.Description == post.Text {
Expand Down
2 changes: 2 additions & 0 deletions automod/rules/promo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/bluesky-social/indigo/automod/countstore"
)

var _ automod.PostRuleFunc = AggressivePromotionRule

// looks for new accounts, with a commercial or donation link in profile, which directly reply to several accounts
//
// this rule depends on ReplyCountPostRule() to set counts
Expand Down
4 changes: 4 additions & 0 deletions automod/rules/replies.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/bluesky-social/indigo/automod/countstore"
)

var _ automod.PostRuleFunc = ReplyCountPostRule

// does not count "self-replies" (direct to self, or in own post thread)
func ReplyCountPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if post.Reply == nil || IsSelfThread(c, post) {
Expand All @@ -35,6 +37,8 @@ func ReplyCountPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error
// triggers on the N+1 post, so 6th identical reply
var identicalReplyLimit = 5

var _ automod.PostRuleFunc = IdenticalReplyPostRule

// Looks for accounts posting the exact same text multiple times. Does not currently count the number of distinct accounts replied to, just counts replies at all.
//
// There can be legitimate situations that trigger this rule, so in most situations should be a "report" not "label" action.
Expand Down

0 comments on commit 0590ced

Please sign in to comment.