mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-08 16:48:51 +00:00
also parse npub/nevent/naddr when used as tag values, turn them into their corresponding hex or address format.
This commit is contained in:
6
count.go
6
count.go
@@ -101,16 +101,16 @@ var count = &cli.Command{
|
|||||||
for _, tagFlag := range c.StringSlice("tag") {
|
for _, tagFlag := range c.StringSlice("tag") {
|
||||||
spl := strings.SplitN(tagFlag, "=", 2)
|
spl := strings.SplitN(tagFlag, "=", 2)
|
||||||
if len(spl) == 2 {
|
if len(spl) == 2 {
|
||||||
tags = append(tags, spl)
|
tags = append(tags, []string{spl[0], decodeTagValue(spl[1])})
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("invalid --tag '%s'", tagFlag)
|
return fmt.Errorf("invalid --tag '%s'", tagFlag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, etag := range c.StringSlice("e") {
|
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") {
|
for _, ptag := range c.StringSlice("p") {
|
||||||
tags = append(tags, []string{"p", ptag})
|
tags = append(tags, []string{"p", decodeTagValue(ptag)})
|
||||||
}
|
}
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
filter.Tags = make(nostr.TagMap)
|
filter.Tags = make(nostr.TagMap)
|
||||||
|
|||||||
18
event.go
18
event.go
@@ -211,24 +211,30 @@ example:
|
|||||||
if found {
|
if found {
|
||||||
// tags may also contain extra elements separated with a ";"
|
// tags may also contain extra elements separated with a ";"
|
||||||
tagValues := strings.Split(tagValue, ";")
|
tagValues := strings.Split(tagValue, ";")
|
||||||
|
if len(tagValues) >= 1 {
|
||||||
|
tagValues[0] = decodeTagValue(tagValues[0])
|
||||||
|
}
|
||||||
tag = append(tag, tagValues...)
|
tag = append(tag, tagValues...)
|
||||||
}
|
}
|
||||||
tags = append(tags, tag)
|
tags = append(tags, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, etag := range c.StringSlice("e") {
|
for _, etag := range c.StringSlice("e") {
|
||||||
if tags.FindWithValue("e", etag) == nil {
|
decodedEtag := decodeTagValue(etag)
|
||||||
tags = append(tags, nostr.Tag{"e", etag})
|
if tags.FindWithValue("e", decodedEtag) == nil {
|
||||||
|
tags = append(tags, nostr.Tag{"e", decodedEtag})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, ptag := range c.StringSlice("p") {
|
for _, ptag := range c.StringSlice("p") {
|
||||||
if tags.FindWithValue("p", ptag) == nil {
|
decodedPtag := decodeTagValue(ptag)
|
||||||
tags = append(tags, nostr.Tag{"p", ptag})
|
if tags.FindWithValue("p", decodedPtag) == nil {
|
||||||
|
tags = append(tags, nostr.Tag{"p", decodedPtag})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, dtag := range c.StringSlice("d") {
|
for _, dtag := range c.StringSlice("d") {
|
||||||
if tags.FindWithValue("d", dtag) == nil {
|
decodedDtag := decodeTagValue(dtag)
|
||||||
tags = append(tags, nostr.Tag{"d", dtag})
|
if tags.FindWithValue("d", decodedDtag) == nil {
|
||||||
|
tags = append(tags, nostr.Tag{"d", decodedDtag})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
|
|||||||
@@ -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)
|
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 {
|
var colors = struct {
|
||||||
reset func(...any) (int, error)
|
reset func(...any) (int, error)
|
||||||
italic func(...any) string
|
italic func(...any) string
|
||||||
|
|||||||
8
req.go
8
req.go
@@ -354,19 +354,19 @@ func applyFlagsToFilter(c *cli.Command, filter *nostr.Filter) error {
|
|||||||
for _, tagFlag := range c.StringSlice("tag") {
|
for _, tagFlag := range c.StringSlice("tag") {
|
||||||
spl := strings.SplitN(tagFlag, "=", 2)
|
spl := strings.SplitN(tagFlag, "=", 2)
|
||||||
if len(spl) == 2 {
|
if len(spl) == 2 {
|
||||||
tags = append(tags, spl)
|
tags = append(tags, []string{spl[0], decodeTagValue(spl[1])})
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("invalid --tag '%s'", tagFlag)
|
return fmt.Errorf("invalid --tag '%s'", tagFlag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, etag := range c.StringSlice("e") {
|
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") {
|
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") {
|
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 {
|
if len(tags) > 0 && filter.Tags == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user