-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
80 lines (60 loc) · 1.34 KB
/
search.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
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
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"log/slog"
"github.com/nbd-wtf/go-nostr"
)
// Implemenets the Runner interface
type Search struct {
fs *flag.FlagSet
title string
hashtags []string
}
func NewSearch() *Search {
s := Search{
fs: flag.NewFlagSet("search", flag.ExitOnError),
}
s.fs.StringVar(&s.title, "title", "", "article title")
s.fs.Func("tag", "tag article", func(v string) error {
s.hashtags = append(s.hashtags, v)
return nil
})
return &s
}
func (s *Search) Parse(args []string) error {
return s.fs.Parse(args)
}
func (s *Search) Name() string {
return s.fs.Name()
}
// 1. Check that title and content is non-empty
// 2. Create the nostr event from the commandline arguments
// 3. Publish the event to the config relays
func (s *Search) Run(container *Container) error {
nb, err := container.CurrentNotebook()
if err != nil {
return err
}
tags := make(nostr.TagMap)
if s.title != "" {
tags["title"] = []string{s.title}
}
tags["t"] = append(tags["t"], s.hashtags...)
filter := nostr.Filter{
Kinds: []int{nostr.KindArticle},
Tags: tags,
Limit: 500,
}
notes, err := nb.Search(filter)
if err != nil {
return err
}
slog.Info("events found", "eventCount", len(notes))
fmt.Println("\n[*] Notes")
for _, n := range notes {
fmt.Printf("%s\n", n.Title())
fmt.Printf("%s\n\n", n.Path)
}
return nil
}