mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-22 08:19:06 -05:00
count uses all relays again, now correctly.
This commit is contained in:
parent
e4a9b3ccc7
commit
8d111e556e
31
count.go
31
count.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ import (
|
||||||
var count = &cli.Command{
|
var count = &cli.Command{
|
||||||
Name: "count",
|
Name: "count",
|
||||||
Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
|
Usage: "generates encoded COUNT messages and optionally use them to talk to relays",
|
||||||
Description: `outputs a NIP-45 request -- (mostly the same as 'nak req').`,
|
Description: `outputs a NIP-45 request (the flags are mostly the same as 'nak req').`,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "author",
|
Name: "author",
|
||||||
|
@ -112,17 +113,27 @@ var count = &cli.Command{
|
||||||
filter.Limit = limit
|
filter.Limit = limit
|
||||||
}
|
}
|
||||||
|
|
||||||
relay := c.Args().First()
|
relays := c.Args().Slice()
|
||||||
if relay != "" {
|
successes := 0
|
||||||
relay, err := nostr.RelayConnect(c.Context, relay)
|
failures := make([]error, 0, len(relays))
|
||||||
if err != nil {
|
if len(relays) > 0 {
|
||||||
return err
|
for _, relayUrl := range relays {
|
||||||
|
relay, err := nostr.RelayConnect(c.Context, relayUrl)
|
||||||
|
if err != nil {
|
||||||
|
failures = append(failures, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
||||||
|
if err != nil {
|
||||||
|
failures = append(failures, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf("%s: %d\n", relay.URL, count)
|
||||||
|
successes++
|
||||||
}
|
}
|
||||||
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
if successes == 0 {
|
||||||
if err != nil {
|
return errors.Join(failures...)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
fmt.Println(count)
|
|
||||||
} else {
|
} else {
|
||||||
// no relays given, will just print the filter
|
// no relays given, will just print the filter
|
||||||
var result string
|
var result string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user