Compare commits

...

3 Commits

Author SHA1 Message Date
Yasuhiro Matsumoto
242b028656 -until now 2023-12-12 13:34:30 -03:00
Yasuhiro Matsumoto
f0d90b567c -since now 2023-12-12 13:34:30 -03:00
fiatjaf
2d1e27f766 fix for nil error case on publish. 2023-12-10 20:49:08 -03:00
2 changed files with 25 additions and 9 deletions

View File

@@ -222,7 +222,8 @@ example:
ctx, cancel := context.WithTimeout(c.Context, 10*time.Second) ctx, cancel := context.WithTimeout(c.Context, 10*time.Second)
defer cancel() defer cancel()
if err := relay.Publish(ctx, evt); err == nil { err := relay.Publish(ctx, evt)
if err == nil {
// published fine // published fine
log("success.\n") log("success.\n")
continue nextline continue nextline

27
req.go
View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"strconv"
"strings" "strings"
"github.com/mailru/easyjson" "github.com/mailru/easyjson"
@@ -61,13 +62,13 @@ example:
Usage: "shortcut for --tag p=<value>", Usage: "shortcut for --tag p=<value>",
Category: CATEGORY_FILTER_ATTRIBUTES, Category: CATEGORY_FILTER_ATTRIBUTES,
}, },
&cli.IntFlag{ &cli.StringFlag{
Name: "since", Name: "since",
Aliases: []string{"s"}, Aliases: []string{"s"},
Usage: "only accept events newer than this (unix timestamp)", Usage: "only accept events newer than this (unix timestamp)",
Category: CATEGORY_FILTER_ATTRIBUTES, Category: CATEGORY_FILTER_ATTRIBUTES,
}, },
&cli.IntFlag{ &cli.StringFlag{
Name: "until", Name: "until",
Aliases: []string{"u"}, Aliases: []string{"u"},
Usage: "only accept events older than this (unix timestamp)", Usage: "only accept events older than this (unix timestamp)",
@@ -184,13 +185,27 @@ example:
filter.Tags[tag[0]] = append(filter.Tags[tag[0]], tag[1]) filter.Tags[tag[0]] = append(filter.Tags[tag[0]], tag[1])
} }
if since := c.Int("since"); since != 0 { if since := c.String("since"); since != "" {
ts := nostr.Timestamp(since) if since == "now" {
ts := nostr.Now()
filter.Since = &ts filter.Since = &ts
} else if i, err := strconv.Atoi(since); err == nil {
ts := nostr.Timestamp(i)
filter.Since = &ts
} else {
return fmt.Errorf("parse error: Invalid numeric literal %q", since)
} }
if until := c.Int("until"); until != 0 { }
ts := nostr.Timestamp(until) if until := c.String("until"); until != "" {
if until == "now" {
ts := nostr.Now()
filter.Until = &ts filter.Until = &ts
} else if i, err := strconv.Atoi(until); err == nil {
ts := nostr.Timestamp(i)
filter.Until = &ts
} else {
return fmt.Errorf("parse error: Invalid numeric literal %q", until)
}
} }
if limit := c.Int("limit"); limit != 0 { if limit := c.Int("limit"); limit != 0 {
filter.Limit = limit filter.Limit = limit