diff --git a/count.go b/count.go index 48bcaa4..e0d2080 100644 --- a/count.go +++ b/count.go @@ -101,16 +101,16 @@ var count = &cli.Command{ for _, tagFlag := range c.StringSlice("tag") { spl := strings.SplitN(tagFlag, "=", 2) if len(spl) == 2 { - tags = append(tags, spl) + tags = append(tags, []string{spl[0], decodeTagValue(spl[1])}) } else { return fmt.Errorf("invalid --tag '%s'", tagFlag) } } for _, etag := range c.StringSlice("e") { - tags = append(tags, []string{"e", etag}) + tags = append(tags, []string{"e", decodeTagValue(etag)}) } for _, ptag := range c.StringSlice("p") { - tags = append(tags, []string{"p", ptag}) + tags = append(tags, []string{"p", decodeTagValue(ptag)}) } if len(tags) > 0 { filter.Tags = make(nostr.TagMap) diff --git a/event.go b/event.go index 7516363..fb4de9f 100644 --- a/event.go +++ b/event.go @@ -211,24 +211,30 @@ example: if found { // tags may also contain extra elements separated with a ";" tagValues := strings.Split(tagValue, ";") + if len(tagValues) >= 1 { + tagValues[0] = decodeTagValue(tagValues[0]) + } tag = append(tag, tagValues...) } tags = append(tags, tag) } for _, etag := range c.StringSlice("e") { - if tags.FindWithValue("e", etag) == nil { - tags = append(tags, nostr.Tag{"e", etag}) + decodedEtag := decodeTagValue(etag) + if tags.FindWithValue("e", decodedEtag) == nil { + tags = append(tags, nostr.Tag{"e", decodedEtag}) } } for _, ptag := range c.StringSlice("p") { - if tags.FindWithValue("p", ptag) == nil { - tags = append(tags, nostr.Tag{"p", ptag}) + decodedPtag := decodeTagValue(ptag) + if tags.FindWithValue("p", decodedPtag) == nil { + tags = append(tags, nostr.Tag{"p", decodedPtag}) } } for _, dtag := range c.StringSlice("d") { - if tags.FindWithValue("d", dtag) == nil { - tags = append(tags, nostr.Tag{"d", dtag}) + decodedDtag := decodeTagValue(dtag) + if tags.FindWithValue("d", decodedDtag) == nil { + tags = append(tags, nostr.Tag{"d", decodedDtag}) } } if len(tags) > 0 { diff --git a/helpers.go b/helpers.go index 02d30ed..68e3c72 100644 --- a/helpers.go +++ b/helpers.go @@ -508,6 +508,15 @@ func parseEventID(value string) (nostr.ID, error) { return nostr.ID{}, fmt.Errorf("invalid event id (\"%s\"): expected hex, note, or nevent", value) } +func decodeTagValue(value string) string { + if strings.HasPrefix(value, "npub1") || strings.HasPrefix(value, "nevent1") || strings.HasPrefix(value, "note1") || strings.HasPrefix(value, "nprofile1") || strings.HasPrefix(value, "naddr1") { + if ptr, err := nip19.ToPointer(value); err == nil { + return ptr.AsTagReference() + } + } + return value +} + var colors = struct { reset func(...any) (int, error) italic func(...any) string diff --git a/req.go b/req.go index 554f0db..2725054 100644 --- a/req.go +++ b/req.go @@ -354,19 +354,19 @@ func applyFlagsToFilter(c *cli.Command, filter *nostr.Filter) error { for _, tagFlag := range c.StringSlice("tag") { spl := strings.SplitN(tagFlag, "=", 2) if len(spl) == 2 { - tags = append(tags, spl) + tags = append(tags, []string{spl[0], decodeTagValue(spl[1])}) } else { return fmt.Errorf("invalid --tag '%s'", tagFlag) } } for _, etag := range c.StringSlice("e") { - tags = append(tags, []string{"e", etag}) + tags = append(tags, []string{"e", decodeTagValue(etag)}) } for _, ptag := range c.StringSlice("p") { - tags = append(tags, []string{"p", ptag}) + tags = append(tags, []string{"p", decodeTagValue(ptag)}) } for _, dtag := range c.StringSlice("d") { - tags = append(tags, []string{"d", dtag}) + tags = append(tags, []string{"d", decodeTagValue(dtag)}) } if len(tags) > 0 && filter.Tags == nil {