Skip to content

Commit

Permalink
automod: rule fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Nov 30, 2023
1 parent 4da452d commit 08054b3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
23 changes: 23 additions & 0 deletions automod/rules/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"unicode"

appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod"
)

func dedupeStrings(in []string) []string {
Expand Down Expand Up @@ -154,3 +156,24 @@ func ExtractTextURLsProfile(profile *appbsky.ActorProfile) []string {
}
return ExtractTextURLs(s)
}

// checks if the post event is a reply post for which the author is replying to themselves, or author is the root author (OP)
func IsSelfThread(evt *automod.RecordEvent, post *appbsky.FeedPost) bool {
if post.Reply == nil {
return false
}
did := evt.Account.Identity.DID.String()
parentURI, err := syntax.ParseATURI(post.Reply.Parent.Uri)
if err != nil {
return false
}
rootURI, err := syntax.ParseATURI(post.Reply.Root.Uri)
if err != nil {
return false
}

if parentURI.Authority().String() == did || rootURI.Authority().String() == did {
return true
}
return false
}
4 changes: 2 additions & 2 deletions automod/rules/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewAccountRule(evt *automod.IdentityEvent) error {
if age > 2*time.Hour {
return nil
}
exists := evt.GetCount("exists", did, automod.PeriodTotal)
exists := evt.GetCount("acct/exists", did, automod.PeriodTotal)
if exists == 0 {
evt.Logger.Info("new account")
evt.Increment("acct/exists", did)
Expand All @@ -31,7 +31,7 @@ func NewAccountRule(evt *automod.IdentityEvent) error {
return nil
}
pdsHost := strings.ToLower(pdsURL.Host)
existingAccounts := evt.GetCount("newaccthost", pdsHost, automod.PeriodTotal)
existingAccounts := evt.GetCount("host/newacct", pdsHost, automod.PeriodTotal)
evt.Increment("host/newacct", pdsHost)

// new PDS host
Expand Down
2 changes: 1 addition & 1 deletion automod/rules/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func KeywordProfileRule(evt *automod.RecordEvent, profile *appbsky.ActorProfile)
}

func ReplySingleKeywordPostRule(evt *automod.RecordEvent, post *appbsky.FeedPost) error {
if post.Reply != nil {
if post.Reply != nil && !IsSelfThread(evt, post) {
tokens := ExtractTextTokensPost(post)
if len(tokens) == 1 && evt.InSet("bad-words", tokens[0]) {
evt.AddRecordFlag("reply-single-bad-word")
Expand Down

0 comments on commit 08054b3

Please sign in to comment.