Skip to content

Commit

Permalink
feat: first working poc
Browse files Browse the repository at this point in the history
Signed-off-by: r3drun3 <simone.ragonesi@sighup.io>
  • Loading branch information
R3DRUN3 committed Oct 5, 2023
1 parent d8e2b50 commit 03a2eae
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# macos
.DS_Store
.DS_Store

# Vs code
.vscode
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,22 @@ NostrO facilitates operations such as keyword search on filtered user notes, and
> **Note**
> The tool is currently in the experimental phase, and we welcome pull requests and contributions!

## Examples

Retrieve relay info:
```console
nostro relay info relay.nostrview.com
####################### RELAY INFO #######################
NAME: relay.nostrview.com
DESCRIPTION: Nostrview relay
PUB KEY: 2e9397a8c9268585668b76479f88e359d0ee261f8e8ea07b3b3450546d1601c8
CONTACT: 2e9397a8c9268585668b76479f88e359d0ee261f8e8ea07b3b3450546d1601c8
SUPPORTED NIPS: [1 2 4 9 11 12 15 16 20 22 26 28 33 40 111]
SOFTWARE: git+https://github.com/Cameri/nostream.git
VERSION: 1.22.2
LIMITATION: &{524288 10 10 5000 256 4 2500 102400 0 false true}
PAYMENTSURL: https://relay.nostrview.com/invoices
##########################################################
```

12 changes: 9 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ import (
"fmt"
"os"

"github.com/r3drun3/nostro/internal/commands"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "nostro",
Short: "Nostr OSINT",
Long: `NostrO enables you to do Open Source Intelligence on the Nostr protocol`,
Short: "Nostr OSINT.",
Long: `NostrO enables you to do Open Source Intelligence on the Nostr protocol.`,
Run: func(cmd *cobra.Command, args []string) {
// Your CLI's main logic goes here
// Display a message indicating that a subcommand is required
fmt.Println("################### Welcome to NostrO 🔎 𓅦 ###################")
fmt.Println("Please specify a subcommand (e.g., 'relay').")
},
}

func init() {
rootCmd.AddCommand(commands.RelayCmd)
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ require github.com/spf13/cobra v1.7.0

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/nbd-wtf/go-nostr v0.24.1
github.com/spf13/pflag v1.0.5 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/nbd-wtf/go-nostr v0.24.1 h1:VqWDceiYTKZaOrizgwix/l/MXmDqqXHLqZd6rhiCxbo=
github.com/nbd-wtf/go-nostr v0.24.1/go.mod h1:eE8Qf8QszZbCd9arBQyotXqATNUElWsTEEx+LLORhyQ=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
Expand Down
10 changes: 10 additions & 0 deletions internal/commands/relay.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package commands

import (
"github.com/spf13/cobra"
)

var RelayCmd = &cobra.Command{
Use: "relay",
Short: "Relay commands",
}
71 changes: 71 additions & 0 deletions internal/commands/relayinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// package commands

// import (
// "context"
// "fmt"

// "github.com/nbd-wtf/go-nostr/nip11"
// "github.com/spf13/cobra"
// )

// var infoCmd = &cobra.Command{
// Use: "info [RELAY]",
// Short: "Retrieve relay information document (nip-11)",
// Long: `The info subcommand retrieves the relay capabilities, administrative contacts, and various server attributes.`,
// Args: cobra.ExactArgs(1), // Expects exactly 1 argument (relay name)
// Run: func(cmd *cobra.Command, args []string) {
// url := args[0]
// data, err := nip11.Fetch(context.Background(), url)

// if err != nil {
// panic(err)
// }
// fmt.Println(data)

// },
// }

// func init() {
// // Add the "info" subcommand to the "relay" command
// relayCmd.AddCommand(infoCmd)
// }

package commands

import (
"context"
"fmt"

"github.com/nbd-wtf/go-nostr/nip11"
"github.com/spf13/cobra"
)

var relayInfoCmd = &cobra.Command{
Use: "info [RELAY]",
Short: "Retrieve relay information document (nip-11)",
Long: `The info subcommand retrieves the relay capabilities, administrative contacts, and various server attributes.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
relay := args[0]
data, err := nip11.Fetch(context.Background(), relay)
if err != nil {
panic(err)
}
fmt.Println("####################### RELAY INFO #######################")
fmt.Println("NAME: ", data.Name)
fmt.Println("DESCRIPTION: ", data.Description)
fmt.Println("PUB KEY: ", data.PubKey)
fmt.Println("CONTACT: ", data.Contact)
fmt.Println("SUPPORTED NIPS: ", data.SupportedNIPs)
fmt.Println("SOFTWARE: ", data.Software)
fmt.Println("VERSION: ", data.Version)
fmt.Println("LIMITATION: ", data.Limitation)
fmt.Println("PAYMENTSURL: ", data.PaymentsURL)
fmt.Println("##########################################################")

},
}

func init() {
RelayCmd.AddCommand(relayInfoCmd)
}
16 changes: 0 additions & 16 deletions internal/config/config.go

This file was deleted.

0 comments on commit 03a2eae

Please sign in to comment.