this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:rightwards_twisted_arrows: Merge with upstream

+112 -20
+85
cmd/automod/helpers.go
··· 1 + package main 2 + 3 + import ( 4 + comatproto "github.com/bluesky-social/indigo/api/atproto" 5 + toolsozone "github.com/bluesky-social/indigo/api/ozone" 6 + "github.com/bluesky-social/indigo/atproto/syntax" 7 + "github.com/bluesky-social/indigo/automod" 8 + ) 9 + 10 + func addAccountLabel(c *automod.RecordContext, did syntax.DID, label string) error { 11 + am := c.GetAccountMeta(did) 12 + eng := c.InternalEngine() 13 + if eng.OzoneClient == nil { 14 + c.Logger.Warn("skipping label addition", "did", did, "label", label) 15 + return nil 16 + } 17 + 18 + // check if label is already applied 19 + for _, l := range am.AccountLabels { 20 + if l == label { 21 + return nil 22 + } 23 + } 24 + 25 + // send label via engine 26 + c.Logger.Warn("adding label", "did", did, "label", label) 27 + comment := "auto-adding label" 28 + _, err := toolsozone.ModerationEmitEvent(c.Ctx, eng.OzoneClient, &toolsozone.ModerationEmitEvent_Input{ 29 + CreatedBy: eng.OzoneClient.Auth.Did, 30 + Event: &toolsozone.ModerationEmitEvent_Input_Event{ 31 + ModerationDefs_ModEventLabel: &toolsozone.ModerationDefs_ModEventLabel{ 32 + CreateLabelVals: []string{label}, 33 + NegateLabelVals: []string{}, 34 + Comment: &comment, 35 + }, 36 + }, 37 + Subject: &toolsozone.ModerationEmitEvent_Input_Subject{ 38 + AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ 39 + Did: did.String(), 40 + }, 41 + }, 42 + }) 43 + return err 44 + } 45 + 46 + func removeAccountLabel(c *automod.RecordContext, did syntax.DID, label string) error { 47 + am := c.GetAccountMeta(did) 48 + eng := c.InternalEngine() 49 + if eng.OzoneClient == nil { 50 + c.Logger.Warn("skipping label removal", "did", did, "label", label) 51 + return nil 52 + } 53 + 54 + // check if label is already applied 55 + exists := false 56 + for _, l := range am.AccountLabels { 57 + if l == label { 58 + exists = true 59 + break 60 + } 61 + } 62 + if !exists { 63 + return nil 64 + } 65 + 66 + // send label via engine 67 + c.Logger.Warn("removing label", "did", did, "label", label) 68 + comment := "auto-removing label" 69 + _, err := toolsozone.ModerationEmitEvent(c.Ctx, eng.OzoneClient, &toolsozone.ModerationEmitEvent_Input{ 70 + CreatedBy: eng.OzoneClient.Auth.Did, 71 + Event: &toolsozone.ModerationEmitEvent_Input_Event{ 72 + ModerationDefs_ModEventLabel: &toolsozone.ModerationDefs_ModEventLabel{ 73 + CreateLabelVals: []string{}, 74 + NegateLabelVals: []string{label}, 75 + Comment: &comment, 76 + }, 77 + }, 78 + Subject: &toolsozone.ModerationEmitEvent_Input_Subject{ 79 + AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ 80 + Did: did.String(), 81 + }, 82 + }, 83 + }) 84 + return err 85 + }
+1 -1
cmd/automod/main.go
··· 93 93 &cli.IntFlag{ 94 94 Name: "firehose-parallelism", 95 95 Usage: "force a fixed number of parallel firehose workers. default (or 0) for auto-scaling; 200 works for a large instance", 96 - Value: 200, 96 + Value: 200, 97 97 EnvVars: []string{"AUTOMOD_FIREHOSE_PARALLELISM"}, 98 98 }, 99 99 }
+22 -15
cmd/automod/rules.go
··· 22 22 return nil 23 23 } 24 24 25 - authorDid := c.Account.Identity.DID.String() 25 + authorDID := c.Account.Identity.DID 26 26 27 27 if post.Reply == nil || IsSelfThread(c, post) { 28 28 mentionedDids := mentionedDids(post) 29 - for _, botDid := range mentionedDids { 30 - handleBotSignal(c, botDid, authorDid, botType) 29 + for _, botDID := range mentionedDids { 30 + handleBotSignal(c, botDID, authorDID, botType) 31 31 } 32 32 return nil 33 33 } ··· 36 36 return nil 37 37 } 38 38 39 - botDid := parentURI.Authority().String() 40 - handleBotSignal(c, botDid, authorDid, botType) 41 - 39 + botDID, err := parentURI.Authority().AsDID() 40 + if err != nil { 41 + return err 42 + } 43 + handleBotSignal(c, botDID, authorDID, botType) 42 44 return nil 43 45 } 44 46 45 - func handleBotSignal(c *automod.RecordContext, botDid string, authorDid string, botType int) { 47 + func handleBotSignal(c *automod.RecordContext, botDID string, authorDID string, botType int) { 46 48 if botType == 1 { 47 - c.IncrementDistinct("goodbot", botDid, authorDid) 48 - c.IncrementDistinct("bladerunner", authorDid, botDid) 49 + c.IncrementDistinct("goodbot", botDID, authorDID) 50 + c.IncrementDistinct("bladerunner", authorDID, botDID) 49 51 c.Logger.Error("good bot reply") 50 52 51 - if c.GetCountDistinct("goodbot", botDid, countstore.PeriodTotal) > GOOD_BOT_REPLY_THRESHOLD-1 { 53 + // XXX: bypass counts for early testing 54 + if err = addAccountLabel(c, botDID, "good-bot"); err != nil { 55 + return err 56 + } 57 + 58 + if c.GetCountDistinct("goodbot", botDID, countstore.PeriodTotal) > GOOD_BOT_REPLY_THRESHOLD-1 { 52 59 c.Logger.Error("good bot") 53 60 // c.AddAccountLabel("good-bot") 54 61 // c.Notify("slack") 55 62 } 56 63 57 - if c.GetCountDistinct("bladerunner", authorDid, countstore.PeriodTotal) > BLADERUNNER_THRESHOLD-1 { 64 + if c.GetCountDistinct("bladerunner", authorDID, countstore.PeriodTotal) > BLADERUNNER_THRESHOLD-1 { 58 65 c.Logger.Error("bladerunner") 59 66 // c.AddAccountLabel("bladerunner") 60 67 // c.Notify("slack") ··· 63 70 return 64 71 } 65 72 66 - c.IncrementDistinct("badbot", botDid, authorDid) 67 - c.IncrementDistinct("jabroni", authorDid, botDid) 73 + c.IncrementDistinct("badbot", botDID, authorDID) 74 + c.IncrementDistinct("jabroni", authorDID, botDID) 68 75 c.Logger.Error("bad bot reply") 69 76 70 - if c.GetCountDistinct("badbot", botDid, countstore.PeriodTotal) > BAD_BOT_REPLY_THRESHOLD-1 { 77 + if c.GetCountDistinct("badbot", botDID, countstore.PeriodTotal) > BAD_BOT_REPLY_THRESHOLD-1 { 71 78 // @TODO: this would add label to the reply author's account not the parent/bot's account 72 79 // c.AddAccountLabel("bad-bot") 73 80 c.Logger.Error("bad bot") 74 81 // c.Notify("slack") 75 82 } 76 83 77 - if c.GetCountDistinct("jabroni", authorDid, countstore.PeriodTotal) > JABRONI_THRESHOLD-1 { 84 + if c.GetCountDistinct("jabroni", authorDID, countstore.PeriodTotal) > JABRONI_THRESHOLD-1 { 78 85 // c.AddAccountLabel("jabroni") 79 86 c.Logger.Error("jabroni") 80 87 // c.Notify("slack")
+2 -2
go.mod
··· 3 3 go 1.22.2 4 4 5 5 require ( 6 - github.com/bluesky-social/indigo v0.0.0-20241022184456-f49cfdb05a3b 6 + github.com/bluesky-social/indigo v0.0.0-20241022192011-1b2d84c83f3b 7 7 github.com/carlmjohnson/versioninfo v0.22.5 8 8 github.com/joho/godotenv v1.5.1 9 9 github.com/prometheus/client_golang v1.17.0 10 10 github.com/redis/go-redis/v9 v9.3.0 11 + github.com/stretchr/testify v1.9.0 11 12 github.com/urfave/cli/v2 v2.25.7 12 13 golang.org/x/time v0.3.0 13 14 ) ··· 82 83 github.com/puzpuzpuz/xsync/v3 v3.0.2 // indirect 83 84 github.com/russross/blackfriday/v2 v2.1.0 // indirect 84 85 github.com/spaolacci/murmur3 v1.1.0 // indirect 85 - github.com/stretchr/testify v1.9.0 // indirect 86 86 github.com/vmihailenco/go-tinylfu v0.2.2 // indirect 87 87 github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect 88 88 github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
+2 -2
go.sum
··· 8 8 github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 9 9 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 10 10 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 11 - github.com/bluesky-social/indigo v0.0.0-20241022184456-f49cfdb05a3b h1:vPd4Ydvqh/K8xbDeRmBFEoEr1iNtgUj0/1cMlvGD8Z4= 12 - github.com/bluesky-social/indigo v0.0.0-20241022184456-f49cfdb05a3b/go.mod h1:Zx9nSWgd/FxMenkJW07VKnzspxpHBdPrPmS+Fspl2I0= 11 + github.com/bluesky-social/indigo v0.0.0-20241022192011-1b2d84c83f3b h1:Qu4WUVEPJ9K11Q/TlzKsgzlDjai6nUNswwEAuCe8tMw= 12 + github.com/bluesky-social/indigo v0.0.0-20241022192011-1b2d84c83f3b/go.mod h1:Zx9nSWgd/FxMenkJW07VKnzspxpHBdPrPmS+Fspl2I0= 13 13 github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= 14 14 github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= 15 15 github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=