diff --git a/automod/engine/fetchaccountmeta.go b/automod/engine/fetchaccountmeta.go index fe3d81f0..2a0bca90 100644 --- a/automod/engine/fetchaccountmeta.go +++ b/automod/engine/fetchaccountmeta.go @@ -9,7 +9,6 @@ import ( appbsky "github.com/bluesky-social/indigo/api/bsky" "github.com/bluesky-social/indigo/atproto/identity" "github.com/bluesky-social/indigo/atproto/syntax" - "github.com/bluesky-social/indigo/automod/util" ) func (e *Engine) GetAccountMeta(ctx context.Context, ident *identity.Identity) (*AccountMeta, error) { @@ -69,8 +68,8 @@ func (e *Engine) GetAccountMeta(ctx context.Context, ident *identity.Identity) ( Description: pv.Description, DisplayName: pv.DisplayName, }, - AccountLabels: util.DedupeStrings(labels), - AccountNegatedLabels: util.DedupeStrings(negLabels), + AccountLabels: dedupeStrings(labels), + AccountNegatedLabels: dedupeStrings(negLabels), AccountFlags: flags, } if pv.PostsCount != nil { diff --git a/automod/engine/persist.go b/automod/engine/persist.go index b48f570f..5a80c0ef 100644 --- a/automod/engine/persist.go +++ b/automod/engine/persist.go @@ -5,7 +5,6 @@ import ( "fmt" comatproto "github.com/bluesky-social/indigo/api/atproto" - "github.com/bluesky-social/indigo/automod/util" ) func (eng *Engine) persistCounters(ctx context.Context, eff *Effects) error { @@ -152,8 +151,8 @@ func (eng *Engine) persistRecordModActions(c *RecordContext) error { } // NOTE: record-level actions are *not* currently de-duplicated (aka, the same record could be labeled multiple times, or re-reported, etc) - newLabels := util.DedupeStrings(c.effects.RecordLabels) - newFlags := util.DedupeStrings(c.effects.RecordFlags) + newLabels := dedupeStrings(c.effects.RecordLabels) + newFlags := dedupeStrings(c.effects.RecordFlags) newReports, err := eng.circuitBreakReports(ctx, c.effects.RecordReports) if err != nil { return err diff --git a/automod/engine/persisthelpers.go b/automod/engine/persisthelpers.go index 59c6d546..f6db1d3b 100644 --- a/automod/engine/persisthelpers.go +++ b/automod/engine/persisthelpers.go @@ -9,13 +9,12 @@ import ( comatproto "github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/atproto/syntax" "github.com/bluesky-social/indigo/automod/countstore" - "github.com/bluesky-social/indigo/automod/util" "github.com/bluesky-social/indigo/xrpc" ) func dedupeLabelActions(labels, existing, existingNegated []string) []string { newLabels := []string{} - for _, val := range util.DedupeStrings(labels) { + for _, val := range dedupeStrings(labels) { exists := false for _, e := range existingNegated { if val == e { @@ -38,7 +37,7 @@ func dedupeLabelActions(labels, existing, existingNegated []string) []string { func dedupeFlagActions(flags, existing []string) []string { newFlags := []string{} - for _, val := range util.DedupeStrings(flags) { + for _, val := range dedupeStrings(flags) { exists := false for _, e := range existing { if val == e { diff --git a/automod/util/strings.go b/automod/engine/util.go similarity index 72% rename from automod/util/strings.go rename to automod/engine/util.go index 8fac9e52..195454c1 100644 --- a/automod/util/strings.go +++ b/automod/engine/util.go @@ -1,6 +1,6 @@ -package util +package engine -func DedupeStrings(in []string) []string { +func dedupeStrings(in []string) []string { var out []string seen := make(map[string]bool) for _, v := range in { diff --git a/automod/flagstore/flagstore_mem.go b/automod/flagstore/flagstore_mem.go index 933363af..4f128075 100644 --- a/automod/flagstore/flagstore_mem.go +++ b/automod/flagstore/flagstore_mem.go @@ -2,8 +2,6 @@ package flagstore import ( "context" - - "github.com/bluesky-social/indigo/automod/util" ) type MemFlagStore struct { @@ -32,7 +30,7 @@ func (s MemFlagStore) Add(ctx context.Context, key string, flags []string) error for _, f := range flags { v = append(v, f) } - v = util.DedupeStrings(v) + v = dedupeStrings(v) s.Data[key] = v return nil } diff --git a/automod/flagstore/util.go b/automod/flagstore/util.go new file mode 100644 index 00000000..923a55c6 --- /dev/null +++ b/automod/flagstore/util.go @@ -0,0 +1,13 @@ +package flagstore + +func dedupeStrings(in []string) []string { + var out []string + seen := make(map[string]bool) + for _, v := range in { + if !seen[v] { + out = append(out, v) + seen[v] = true + } + } + return out +} diff --git a/automod/util/must.go b/automod/util/must.go deleted file mode 100644 index af63b443..00000000 --- a/automod/util/must.go +++ /dev/null @@ -1,14 +0,0 @@ -package util - -func Must(err error) { - if err != nil { - panic(err) - } -} - -func MustResult[T any](v T, err error) T { - if err != nil { - panic(err) - } - return v -}