1package rules
2
3import (
4 "net/url"
5 "strings"
6 "time"
7
8 "github.com/bluesky-social/indigo/automod"
9 "github.com/bluesky-social/indigo/automod/countstore"
10 "github.com/bluesky-social/indigo/automod/helpers"
11)
12
13// triggers on first identity event for an account (DID)
14func NewAccountRule(c *automod.AccountContext) error {
15 if c.Account.Identity == nil || !helpers.AccountIsYoungerThan(c, 4*time.Hour) {
16 return nil
17 }
18
19 did := c.Account.Identity.DID.String()
20 exists := c.GetCount("acct/exists", did, countstore.PeriodTotal)
21 if exists == 0 {
22 c.Logger.Info("new account")
23 c.Increment("acct/exists", did)
24
25 pdsURL, err := url.Parse(c.Account.Identity.PDSEndpoint())
26 if err != nil {
27 c.Logger.Warn("invalid PDS URL", "err", err, "endpoint", c.Account.Identity.PDSEndpoint())
28 return nil
29 }
30 pdsHost := strings.ToLower(pdsURL.Host)
31 existingAccounts := c.GetCount("host/newacct", pdsHost, countstore.PeriodTotal)
32 c.Increment("host/newacct", pdsHost)
33
34 // new PDS host
35 if existingAccounts == 0 {
36 c.Logger.Info("new PDS instance", "pdsHost", pdsHost)
37 c.Increment("host", "new")
38 c.AddAccountFlag("host-first-account")
39 c.Notify("slack")
40 }
41 }
42 return nil
43}
44
45var _ automod.IdentityRuleFunc = NewAccountRule
46
47func CelebSpamIdentityRule(c *automod.AccountContext) error {
48
49 hdl := c.Account.Identity.Handle.String()
50 if strings.Contains(hdl, "elon") && strings.Contains(hdl, "musk") {
51 c.AddAccountFlag("handle-elon-musk")
52 c.ReportAccount(automod.ReportReasonSpam, "possible Elon Musk impersonator")
53 return nil
54 }
55
56 return nil
57}
58
59var _ automod.IdentityRuleFunc = CelebSpamIdentityRule