this repo has no description
0
fork

Configure Feed

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

:sparkles: Add rule for good/bad bot

+119 -8
+99 -7
cmd/automod/rules.go
··· 4 4 "strings" 5 5 6 6 appbsky "github.com/bluesky-social/indigo/api/bsky" 7 + "github.com/bluesky-social/indigo/atproto/syntax" 7 8 "github.com/bluesky-social/indigo/automod" 9 + "github.com/bluesky-social/indigo/automod/countstore" 8 10 ) 9 11 10 - // https://en.wikipedia.org/wiki/GTUBE 11 - var gtubeString = "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X" 12 + var _ automod.PostRuleFunc = GoodbotBadbotRule 13 + var GOOD_BOT_REPLY_THRESHOLD = 2 14 + var BAD_BOT_REPLY_THRESHOLD = 2 15 + var BLADERUNNER_THRESHOLD = 2 16 + var JABRONI_THRESHOLD = 2 17 + 18 + func GoodbotBadbotRule(c *automod.RecordContext, post *appbsky.FeedPost) error { 19 + if post.Reply == nil || IsSelfThread(c, post) { 20 + return nil 21 + } 22 + 23 + botType := GetBotResponseType(post.Text) 24 + 25 + if botType == -1 { 26 + return nil 27 + } 28 + 29 + parentURI, err := syntax.ParseATURI(post.Reply.Parent.Uri) 30 + if err != nil { 31 + return nil 32 + } 33 + 34 + botDid := parentURI.Authority().String() 35 + authorDid := c.Account.Identity.DID.String() 36 + 37 + if botType == 1 { 38 + c.IncrementDistinct("goodbot", botDid, authorDid) 39 + c.IncrementDistinct("bladerunner", authorDid, botDid) 40 + c.Logger.Error("good bot reply") 12 41 13 - var _ automod.PostRuleFunc = GtubePostRule 42 + if c.GetCountDistinct("goodbot", botDid, countstore.PeriodTotal) > GOOD_BOT_REPLY_THRESHOLD-1 { 43 + c.Logger.Error("good bot") 44 + // c.AddAccountLabel("good-bot") 45 + // c.Notify("slack") 46 + } 14 47 15 - func GtubePostRule(c *automod.RecordContext, post *appbsky.FeedPost) error { 16 - if strings.Contains(post.Text, gtubeString) { 17 - c.AddRecordLabel("spam") 18 - c.Notify("slack") 48 + if c.GetCountDistinct("bladerunner", authorDid, countstore.PeriodTotal) > BLADERUNNER_THRESHOLD-1 { 49 + c.Logger.Error("bladerunner") 50 + // c.AddAccountLabel("bladerunner") 51 + // c.Notify("slack") 52 + } 53 + 54 + return nil 19 55 } 56 + 57 + c.IncrementDistinct("badbot", botDid, authorDid) 58 + c.IncrementDistinct("jabroni", authorDid, botDid) 59 + c.Logger.Error("bad bot reply") 60 + 61 + if c.GetCountDistinct("badbot", botDid, countstore.PeriodTotal) > BAD_BOT_REPLY_THRESHOLD-1 { 62 + // @TODO: this would add label to the reply author's account not the parent/bot's account 63 + // c.AddAccountLabel("bad-bot") 64 + c.Logger.Error("bad bot") 65 + // c.Notify("slack") 66 + } 67 + 68 + if c.GetCountDistinct("jabroni", authorDid, countstore.PeriodTotal) > JABRONI_THRESHOLD-1 { 69 + // c.AddAccountLabel("jabroni") 70 + c.Logger.Error("jabroni") 71 + // c.Notify("slack") 72 + } 73 + 20 74 return nil 21 75 } 76 + 77 + // @TODO: this isn't a clean check and doing some duplicate regex checks that can be avoided 78 + func GetBotResponseType(s string) int { 79 + // Normalize the string by converting to lowercase and trimming spaces 80 + s = strings.TrimSpace(strings.ToLower(s)) 81 + 82 + if s == "good bot" { 83 + return 1 84 + } 85 + 86 + if s == "bad bot" { 87 + return 0 88 + } 89 + 90 + // If neither pattern matches 91 + return -1 92 + } 93 + 94 + // checks if the post event is a reply post for which the author is replying to themselves, or author is the root author (OP) 95 + func IsSelfThread(c *automod.RecordContext, post *appbsky.FeedPost) bool { 96 + if post.Reply == nil { 97 + return false 98 + } 99 + did := c.Account.Identity.DID.String() 100 + parentURI, err := syntax.ParseATURI(post.Reply.Parent.Uri) 101 + if err != nil { 102 + return false 103 + } 104 + rootURI, err := syntax.ParseATURI(post.Reply.Root.Uri) 105 + if err != nil { 106 + return false 107 + } 108 + 109 + if parentURI.Authority().String() == did || rootURI.Authority().String() == did { 110 + return true 111 + } 112 + return false 113 + }
+15
cmd/automod/rules_test.go
··· 1 + package main 2 + 3 + import ( 4 + "testing" 5 + 6 + "github.com/stretchr/testify/assert" 7 + ) 8 + 9 + func TestGetBotResponseType(t *testing.T) { 10 + assert := assert.New(t) 11 + 12 + assert.Equal(GetBotResponseType("bad bot"), 0) 13 + assert.Equal(GetBotResponseType("good bot"), 1) 14 + assert.Equal(GetBotResponseType("good bot beahvior is punished"), -1) 15 + }
+1 -1
cmd/automod/server.go
··· 112 112 113 113 ruleset := automod.RuleSet{ 114 114 PostRules: []automod.PostRuleFunc{ 115 - GtubePostRule, 115 + GoodbotBadbotRule, 116 116 }, 117 117 } 118 118
+4
go.mod
··· 17 17 github.com/beorn7/perks v1.0.1 // indirect 18 18 github.com/cespare/xxhash/v2 v2.2.0 // indirect 19 19 github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect 20 + github.com/davecgh/go-spew v1.1.1 // indirect 20 21 github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect 21 22 github.com/felixge/httpsnoop v1.0.4 // indirect 22 23 github.com/go-logr/logr v1.4.1 // indirect ··· 73 74 github.com/multiformats/go-varint v0.0.7 // indirect 74 75 github.com/opentracing/opentracing-go v1.2.0 // indirect 75 76 github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect 77 + github.com/pmezard/go-difflib v1.0.0 // indirect 76 78 github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect 77 79 github.com/prometheus/client_model v0.5.0 // indirect 78 80 github.com/prometheus/common v0.45.0 // indirect ··· 80 82 github.com/puzpuzpuz/xsync/v3 v3.0.2 // indirect 81 83 github.com/russross/blackfriday/v2 v2.1.0 // indirect 82 84 github.com/spaolacci/murmur3 v1.1.0 // indirect 85 + github.com/stretchr/testify v1.9.0 // indirect 83 86 github.com/vmihailenco/go-tinylfu v0.2.2 // indirect 84 87 github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect 85 88 github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect ··· 103 106 golang.org/x/text v0.14.0 // indirect 104 107 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect 105 108 google.golang.org/protobuf v1.31.0 // indirect 109 + gopkg.in/yaml.v3 v3.0.1 // indirect 106 110 gorm.io/driver/postgres v1.5.7 // indirect 107 111 gorm.io/gorm v1.25.9 // indirect 108 112 lukechampine.com/blake3 v1.2.1 // indirect