Skip to content

Commit

Permalink
add to automod
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Sep 5, 2024
1 parent a4f3863 commit e0a717d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions automod/rules/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func DefaultRules() automod.RuleSet {
ReplySingleBadWordPostRule,
AggressivePromotionRule,
IdenticalReplyPostRule,
IdenticalReplyPostSameParentRule,
DistinctMentionsRule,
YoungAccountDistinctMentionsRule,
MisleadingLinkUnicodeReversalPostRule,
Expand Down
33 changes: 33 additions & 0 deletions automod/rules/replies.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,39 @@ func IdenticalReplyPostRule(c *automod.RecordContext, post *appbsky.FeedPost) er
return nil
}

// Similar to above rule but only counts replies to the same post. More aggressively applies a spam label to new accounts that are less than a day old.
var identicalReplySameParentLimit = 3
var identicalReplySameParentSpamLabel = 24 * time.Hour
var _ automod.PostRuleFunc = IdenticalReplyPostSameParentRule

func IdenticalReplyPostSameParentRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if post.Reply == nil || IsSelfThread(c, post) {
return nil
}

if ParentOrRootIsFollower(c, post) {
return nil
}

period := countstore.PeriodDay
bucket := c.Account.Identity.DID.String() + "/" + post.Reply.Parent.Uri + "/" + HashOfString(post.Text)
c.IncrementPeriod("reply-text-same-post", bucket, period)

count := c.GetCount("reply-text-same-post", bucket, period)
if count >= identicalReplySameParentLimit {
// if account is young, add spam label. otherwise just report.
createdAt := c.Account.CreatedAt
c.AddAccountFlag("multi-identical-reply-same-post")
c.ReportAccount(automod.ReportReasonSpam, fmt.Sprintf("possible spam (%d identical reply-posts to same post today)", count))
if time.Since(*createdAt) < identicalReplySameParentSpamLabel {
c.AddAccountLabel("spam")
}
c.Notify("slack")
}

return nil
}

// TODO: bumping temporarily
// var youngReplyAccountLimit = 12
var youngReplyAccountLimit = 30
Expand Down

0 comments on commit e0a717d

Please sign in to comment.