forked from janek/mostr
First CLI Prototype
This commit is contained in:
commit
199273d21b
|
@ -0,0 +1 @@
|
||||||
|
/target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,10 @@
|
||||||
|
[package]
|
||||||
|
name = "mostr"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nostr-sdk = "0.30"
|
||||||
|
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
|
|
@ -0,0 +1,13 @@
|
||||||
|
# mostr
|
||||||
|
|
||||||
|
A nested task chat, powered by nostr!
|
||||||
|
|
||||||
|
## Quickstart
|
||||||
|
|
||||||
|
First, start a nostr dev-relay like
|
||||||
|
https://github.com/coracle-social/bucket
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run # Listen to events
|
||||||
|
nostril --envelope --content "realtime message" --kind 90002 | websocat ws://localhost:4736 # Send a test event
|
||||||
|
```
|
|
@ -0,0 +1,52 @@
|
||||||
|
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let my_keys: Keys = Keys::generate();
|
||||||
|
|
||||||
|
let client = Client::new(&my_keys);
|
||||||
|
let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)));
|
||||||
|
|
||||||
|
client.add_relay("ws://localhost:4736").await;
|
||||||
|
//client.add_relay("wss://relay.damus.io").await;
|
||||||
|
//client
|
||||||
|
// .add_relay_with_opts(
|
||||||
|
// "wss://relay.nostr.info",
|
||||||
|
// RelayOptions::new().proxy(proxy).flags(RelayServiceFlags::default().remove(RelayServiceFlags::WRITE)),
|
||||||
|
// )
|
||||||
|
// .await?;
|
||||||
|
//client
|
||||||
|
// .add_relay_with_opts(
|
||||||
|
// "ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion",
|
||||||
|
// RelayOptions::new().proxy(proxy),
|
||||||
|
// )
|
||||||
|
// .await?;
|
||||||
|
|
||||||
|
//let metadata = Metadata::new()
|
||||||
|
// .name("username")
|
||||||
|
// .display_name("My Username")
|
||||||
|
// .about("Description")
|
||||||
|
// .picture(Url::parse("https://example.com/avatar.png")?)
|
||||||
|
// .banner(Url::parse("https://example.com/banner.png")?)
|
||||||
|
// .nip05("username@example.com")
|
||||||
|
// .lud16("yuki@getalby.com")
|
||||||
|
// .custom_field("custom_field", "my value");
|
||||||
|
|
||||||
|
//client.set_metadata(&metadata).await?;
|
||||||
|
|
||||||
|
client.connect().await;
|
||||||
|
|
||||||
|
let filter = Filter::new().kind(Kind::from(90002));
|
||||||
|
let sub_id: SubscriptionId = client.subscribe(vec![filter], None).await;
|
||||||
|
|
||||||
|
let mut notifications = client.notifications();
|
||||||
|
while let Ok(notification) = notifications.recv().await {
|
||||||
|
if let RelayPoolNotification::Event { subscription_id, event, .. } = notification {
|
||||||
|
let kind = event.kind;
|
||||||
|
let content = &event.content;
|
||||||
|
println!("{kind}: {content}");
|
||||||
|
//break; // Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue