mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 09:09:08 -04:00
count uses all relays again, now correctly.
This commit is contained in:
parent
e4a9b3ccc7
commit
8d111e556e
25
count.go
25
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 len(relays) > 0 {
|
||||||
|
for _, relayUrl := range relays {
|
||||||
|
relay, err := nostr.RelayConnect(c.Context, relayUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
failures = append(failures, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
count, err := relay.Count(c.Context, nostr.Filters{filter})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
failures = append(failures, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf("%s: %d\n", relay.URL, count)
|
||||||
|
successes++
|
||||||
|
}
|
||||||
|
if successes == 0 {
|
||||||
|
return errors.Join(failures...)
|
||||||
}
|
}
|
||||||
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