this repo has no description
0
fork

Configure Feed

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

add label helpers

+83
+83
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 + comment := "auto-adding label" 27 + _, err := toolsozone.ModerationEmitEvent(c.Ctx, eng.OzoneClient, &toolsozone.ModerationEmitEvent_Input{ 28 + CreatedBy: eng.OzoneClient.Auth.Did, 29 + Event: &toolsozone.ModerationEmitEvent_Input_Event{ 30 + ModerationDefs_ModEventLabel: &toolsozone.ModerationDefs_ModEventLabel{ 31 + CreateLabelVals: []string{label}, 32 + NegateLabelVals: []string{}, 33 + Comment: &comment, 34 + }, 35 + }, 36 + Subject: &toolsozone.ModerationEmitEvent_Input_Subject{ 37 + AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ 38 + Did: did.String(), 39 + }, 40 + }, 41 + }) 42 + return err 43 + } 44 + 45 + func removeAccountLabel(c *automod.RecordContext, did syntax.DID, label string) error { 46 + am := c.GetAccountMeta(did) 47 + eng := c.InternalEngine() 48 + if eng.OzoneClient == nil { 49 + c.Logger.Warn("skipping label removal", "did", did, "label", label) 50 + return nil 51 + } 52 + 53 + // check if label is already applied 54 + exists := false 55 + for _, l := range am.AccountLabels { 56 + if l == label { 57 + exists = true 58 + break 59 + } 60 + } 61 + if !exists { 62 + return nil 63 + } 64 + 65 + // send label via engine 66 + comment := "auto-removing label" 67 + _, err := toolsozone.ModerationEmitEvent(c.Ctx, eng.OzoneClient, &toolsozone.ModerationEmitEvent_Input{ 68 + CreatedBy: eng.OzoneClient.Auth.Did, 69 + Event: &toolsozone.ModerationEmitEvent_Input_Event{ 70 + ModerationDefs_ModEventLabel: &toolsozone.ModerationDefs_ModEventLabel{ 71 + CreateLabelVals: []string{}, 72 + NegateLabelVals: []string{label}, 73 + Comment: &comment, 74 + }, 75 + }, 76 + Subject: &toolsozone.ModerationEmitEvent_Input_Subject{ 77 + AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ 78 + Did: did.String(), 79 + }, 80 + }, 81 + }) 82 + return err 83 + }