1package rules
2
3import (
4 "fmt"
5 "strings"
6 "time"
7
8 appbsky "github.com/bluesky-social/indigo/api/bsky"
9 "github.com/bluesky-social/indigo/automod"
10 "github.com/bluesky-social/indigo/automod/helpers"
11)
12
13var botLinkStrings = []string{"ainna13762491", "LINK押して", "→ https://tiny", "⇒ http://tiny"}
14var botSpamTLDs = []string{".today", ".life"}
15var botSpamStrings = []string{"515-9719"}
16
17var _ automod.ProfileRuleFunc = BotLinkProfileRule
18
19func BotLinkProfileRule(c *automod.RecordContext, profile *appbsky.ActorProfile) error {
20 if profile.Description != nil {
21 for _, str := range botLinkStrings {
22 if strings.Contains(*profile.Description, str) {
23 c.AddAccountFlag("profile-bot-string")
24 c.AddAccountLabel("spam")
25 c.ReportAccount(automod.ReportReasonSpam, fmt.Sprintf("possible bot based on link in profile: %s", str))
26 c.Notify("slack")
27 return nil
28 }
29 }
30 if strings.Contains(*profile.Description, "🏈🍕🌀") {
31 c.AddAccountFlag("profile-bot-string")
32 c.ReportAccount(automod.ReportReasonSpam, "possible bot based on string in profile")
33 c.Notify("slack")
34 return nil
35 }
36 }
37 return nil
38}
39
40var _ automod.PostRuleFunc = SimpleBotPostRule
41
42func SimpleBotPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
43 for _, str := range botSpamStrings {
44 if strings.Contains(post.Text, str) {
45 // NOTE: reporting the *account* not individual posts
46 c.AddAccountFlag("post-bot-string")
47 c.ReportAccount(automod.ReportReasonSpam, fmt.Sprintf("possible bot based on string in post: %s", str))
48 c.Notify("slack")
49 return nil
50 }
51 }
52 return nil
53}
54
55var _ automod.IdentityRuleFunc = NewAccountBotEmailRule
56
57func NewAccountBotEmailRule(c *automod.AccountContext) error {
58 if c.Account.Identity == nil || !helpers.AccountIsYoungerThan(c, 1*time.Hour) {
59 return nil
60 }
61
62 for _, tld := range botSpamTLDs {
63 if strings.HasSuffix(c.Account.Private.Email, tld) {
64 c.AddAccountFlag("new-suspicious-email")
65 c.ReportAccount(automod.ReportReasonSpam, fmt.Sprintf("possible bot based on email domain TLD: %s", tld))
66 c.Notify("slack")
67 return nil
68 }
69 }
70 return nil
71}
72
73var _ automod.PostRuleFunc = TrivialSpamPostRule
74
75// looks for new accounts, which frequently post the same type of content
76func TrivialSpamPostRule(c *automod.RecordContext, post *appbsky.FeedPost) error {
77 if c.Account.Identity == nil || !helpers.AccountIsYoungerThan(&c.AccountContext, 8*24*time.Hour) {
78 return nil
79 }
80
81 // only posts with dumb patterns (for now)
82 txt := strings.ToLower(post.Text)
83 if !c.InSet("trivial-spam-text", txt) {
84 return nil
85 }
86
87 // only accounts with empty profile (for now)
88 if c.Account.Profile.HasAvatar {
89 return nil
90 }
91
92 c.ReportAccount(automod.ReportReasonOther, "trivial spam account (also labeled; remove label if this isn't spam!)")
93 c.AddAccountLabel("!hide")
94 c.Notify("slack")
95 return nil
96}