Repository navigation
Expand file tree
/
Copy pathprofile.go
More file actions
73 lines (65 loc) · 1.56 KB
/
Copy pathprofile.go
File metadata and controls
73 lines (65 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"github.com/urfave/cli/v2"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/sdk"
)
func doProfile(cCtx *cli.Context) error {
user := cCtx.String("u")
j := cCtx.Bool("json")
cfg := cCtx.App.Metadata["config"].(*Config)
relay := cfg.FindRelay(Relay{Read: true})
if relay == nil {
return errors.New("cannot connect relays")
}
defer relay.Close()
var pub string
if user == "" {
if _, s, err := nip19.Decode(cfg.PrivateKey); err != nil {
return err
} else {
if pub, err = nostr.GetPublicKey(s.(string)); err != nil {
return err
}
}
} else {
if pp := sdk.InputToProfile(context.TODO(), user); pp == nil {
return fmt.Errorf("failed to parse pubkey from '%s'", user)
} else {
pub = pp.PublicKey
}
}
// get set-metadata
filter := nostr.Filter{
Kinds: []int{nostr.KindSetMetadata},
Authors: []string{pub},
Limit: 1,
}
evs := cfg.Events(filter)
if len(evs) == 0 {
return errors.New("cannot find user")
}
var profile Profile
err := json.Unmarshal([]byte(evs[0].Content), &profile)
if err != nil {
return err
}
if j {
json.NewEncoder(os.Stdout).Encode(profile)
return nil
}
fmt.Printf("Name: %v\n", profile.Name)
fmt.Printf("DisplayName: %v\n", profile.DisplayName)
fmt.Printf("WebSite: %v\n", profile.Website)
fmt.Printf("Picture: %v\n", profile.Picture)
fmt.Printf("NIP-05: %v\n", profile.Nip05)
fmt.Printf("LUD-16: %v\n", profile.Lud16)
fmt.Printf("About: %v\n", profile.About)
return nil
}