-
Notifications
You must be signed in to change notification settings - Fork 125
/
harassment.go
158 lines (140 loc) · 4.93 KB
/
harassment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package rules
import (
"fmt"
"time"
appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/bluesky-social/indigo/automod"
"github.com/bluesky-social/indigo/automod/countstore"
"github.com/bluesky-social/indigo/automod/helpers"
)
var _ automod.PostRuleFunc = HarassmentTargetInteractionPostRule
// looks for new accounts, which interact with frequently-harassed accounts, and report them for review
func HarassmentTargetInteractionPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if c.Account.Identity == nil || !helpers.AccountIsYoungerThan(&c.AccountContext, 24*time.Hour) {
return nil
}
var interactionDIDs []string
facets, err := helpers.ExtractFacets(post)
if err != nil {
return err
}
for _, pf := range facets {
if pf.DID != nil {
interactionDIDs = append(interactionDIDs, *pf.DID)
}
}
if post.Reply != nil && !helpers.IsSelfThread(c, post) {
parentURI, err := syntax.ParseATURI(post.Reply.Parent.Uri)
if err != nil {
return err
}
interactionDIDs = append(interactionDIDs, parentURI.Authority().String())
}
// quote posts
if post.Embed != nil && post.Embed.EmbedRecord != nil && post.Embed.EmbedRecord.Record != nil {
uri, err := syntax.ParseATURI(post.Embed.EmbedRecord.Record.Uri)
if err != nil {
c.Logger.Warn("invalid AT-URI in post embed record (quote-post)", "uri", post.Embed.EmbedRecord.Record.Uri)
} else {
interactionDIDs = append(interactionDIDs, uri.Authority().String())
}
}
if len(interactionDIDs) == 0 {
return nil
}
// more than a handful of followers or posts from author account? skip
if c.Account.FollowersCount > 10 || c.Account.PostsCount > 10 {
return nil
}
postCount := c.GetCount("post", c.Account.Identity.DID.String(), countstore.PeriodTotal)
if postCount > 20 {
return nil
}
interactionDIDs = helpers.DedupeStrings(interactionDIDs)
for _, d := range interactionDIDs {
did, err := syntax.ParseDID(d)
if err != nil {
c.Logger.Warn("invalid DID in record", "did", d)
continue
}
if did == c.Account.Identity.DID {
continue
}
targetIsProtected := false
if c.InSet("harassment-target-dids", did.String()) {
targetIsProtected = true
} else {
// check if the target account has a harassment protection tag in Ozone
targetAccount := c.GetAccountMeta(did)
if targetAccount == nil {
continue
}
if targetAccount.Private != nil {
for _, t := range targetAccount.Private.AccountTags {
if t == "harassment-protection" {
targetIsProtected = true
break
}
}
}
}
if !targetIsProtected {
continue
}
// ignore if the target account follows the new account
rel := c.GetAccountRelationship(syntax.DID(did))
if rel.FollowedBy {
continue
}
//c.AddRecordFlag("interaction-harassed-target")
var privCreatedAt *time.Time
if c.Account.Private != nil && c.Account.Private.IndexedAt != nil {
privCreatedAt = c.Account.Private.IndexedAt
}
c.Logger.Warn("possible harassment", "targetDID", did, "author", c.Account.Identity.DID, "accountCreated", c.Account.CreatedAt, "privateAccountCreated", privCreatedAt)
c.ReportAccount(automod.ReportReasonOther, fmt.Sprintf("possible harassment of known target account: %s (also labeled; remove label if this isn't harassment)", did))
c.AddAccountLabel("!hide")
c.Notify("slack")
return nil
}
return nil
}
var _ automod.PostRuleFunc = HarassmentTrivialPostRule
// looks for new accounts, which frequently post the same type of content
func HarassmentTrivialPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
if c.Account.Identity == nil || !helpers.AccountIsYoungerThan(&c.AccountContext, 7*24*time.Hour) {
return nil
}
// only posts with dumb pattern
if post.Text != "F" {
return nil
}
did := c.Account.Identity.DID.String()
c.Increment("trivial-harassing", did)
count := c.GetCount("trivial-harassing", did, countstore.PeriodDay)
if count > 5 {
//c.AddRecordFlag("trivial-harassing-post")
c.ReportAccount(automod.ReportReasonOther, fmt.Sprintf("possible targetted harassment (also labeled; remove label if this isn't harassment!)"))
c.AddAccountLabel("!hide")
c.Notify("slack")
}
return nil
}
var _ automod.OzoneEventRuleFunc = HarassmentProtectionOzoneEventRule
// looks for new harassment protection tags on accounts, and logs them
func HarassmentProtectionOzoneEventRule(c *automod.OzoneEventContext) error {
if c.Event.EventType != "tag" || c.Event.Event.ModerationDefs_ModEventTag == nil {
return nil
}
for _, t := range c.Event.Event.ModerationDefs_ModEventTag.Add {
if t == "harassment-protection" {
c.Logger.Info("adding harassment protection to account", "ozoneComment", c.Event.Event.ModerationDefs_ModEventTag.Comment, "did", c.Account.Identity.DID, "handle", c.Account.Identity.Handle)
// to make slack message clearer; bluring flags and tags is a bit weird
c.AddAccountFlag("harassment-protection")
//c.Notify("slack")
break
}
}
return nil
}