khatru-pyramid/nostr.go

31 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"context"
"github.com/nbd-wtf/go-nostr"
sdk "github.com/nbd-wtf/nostr-sdk"
cache_memory "github.com/nbd-wtf/nostr-sdk/cache/memory"
)
var sys = sdk.System{
Pool: nostr.NewSimplePool(context.Background()),
RelaysCache: cache_memory.New32[[]sdk.Relay](1000),
MetadataCache: cache_memory.New32[sdk.ProfileMetadata](1000),
FollowsCache: cache_memory.New32[[]sdk.Follow](1),
RelayListRelays: []string{"wss://purplepag.es", "wss://relay.nostr.band"},
FollowListRelays: []string{"wss://public.relaying.io", "wss://relay.nostr.band"},
MetadataRelays: []string{"wss://nostr-pub.wellorder.net", "wss://purplepag.es", "wss://relay.nostr.band"},
Store: &db,
}
func fetchAndStoreProfile(ctx context.Context, pubkey string) sdk.ProfileMetadata {
profile := sys.FetchProfileMetadata(ctx, pubkey)
if profile.Event != nil {
if _, err := sys.StoreRelay().Publish(ctx, *profile.Event); err != nil {
log.Warn().Err(err).Msg("failed to save profile locally")
}
}
return profile
}