porting all github actions from bluesky-social/indigo to tangled CI
at main 1.9 kB view raw
1package helpers 2 3import ( 4 "time" 5 6 "github.com/bluesky-social/indigo/automod" 7) 8 9// no accounts exist before this time 10var atprotoAccountEpoch = time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC) 11 12// returns true if account creation timestamp is plausible: not-nil, not in distant past, not in the future 13func plausibleAccountCreation(when *time.Time) bool { 14 if when == nil { 15 return false 16 } 17 // this is mostly to check for misconfigurations or null values (eg, UNIX epoch zero means "unknown" not actually 1970) 18 if !when.After(atprotoAccountEpoch) { 19 return false 20 } 21 // a timestamp in the future would also indicate some misconfiguration 22 if when.After(time.Now().Add(time.Hour)) { 23 return false 24 } 25 return true 26} 27 28// checks if account was created recently, based on either public or private account metadata. if metadata isn't available at all, or seems bogus, returns 'false' 29func AccountIsYoungerThan(c *automod.AccountContext, age time.Duration) bool { 30 // TODO: consider swapping priority order here (and below) 31 if c.Account.CreatedAt != nil && plausibleAccountCreation(c.Account.CreatedAt) { 32 return time.Since(*c.Account.CreatedAt) < age 33 } 34 if c.Account.Private != nil && plausibleAccountCreation(c.Account.Private.IndexedAt) { 35 return time.Since(*c.Account.Private.IndexedAt) < age 36 } 37 return false 38} 39 40// checks if account was *not* created recently, based on either public or private account metadata. if metadata isn't available at all, or seems bogus, returns 'false' 41func AccountIsOlderThan(c *automod.AccountContext, age time.Duration) bool { 42 if c.Account.CreatedAt != nil && plausibleAccountCreation(c.Account.CreatedAt) { 43 return time.Since(*c.Account.CreatedAt) >= age 44 } 45 if c.Account.Private != nil && plausibleAccountCreation(c.Account.Private.IndexedAt) { 46 return time.Since(*c.Account.Private.IndexedAt) >= age 47 } 48 return false 49}