forked from fiatjaf/noscl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.go
44 lines (36 loc) · 901 Bytes
/
metadata.go
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
package main
import (
"encoding/json"
"log"
"time"
"github.com/docopt/docopt-go"
"github.com/fiatjaf/go-nostr"
)
type Metadata struct {
Name string `json:"name,omitempty"`
About string `json:"about,omitempty"`
Picture string `json:"picture,omitempty"`
}
func setMetadata(opts docopt.Opts) {
initNostr()
name, _ := opts.String("--name")
about, _ := opts.String("--about")
picture, _ := opts.String("--picture")
jmetadata, _ := json.Marshal(Metadata{
Name: name,
About: about,
Picture: picture,
})
event, statuses, err := pool.PublishEvent(&nostr.Event{
PubKey: getPubKey(config.PrivateKey),
CreatedAt: uint32(time.Now().Unix()),
Kind: nostr.KindSetMetadata,
Tags: make(nostr.Tags, 0),
Content: string(jmetadata),
})
if err != nil {
log.Printf("Error publishing: %s.\n", err.Error())
return
}
printPublishStatus(event, statuses)
}