init nostr with gniazdo
This commit is contained in:
parent
2c3d3cef2f
commit
911f2f0330
3 changed files with 38 additions and 2 deletions
6
deps.edn
6
deps.edn
|
|
@ -15,7 +15,11 @@
|
||||||
;; json
|
;; json
|
||||||
cheshire/cheshire {:mvn/version "6.0.0"}
|
cheshire/cheshire {:mvn/version "6.0.0"}
|
||||||
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
;; metosin/muuntaja {:mvn/version "0.6.11"}
|
||||||
org.clojure/clojure {:mvn/version "1.12.1"}}
|
org.clojure/clojure {:mvn/version "1.12.1"}
|
||||||
|
;; websockets
|
||||||
|
stylefruits/gniazdo {:mvn/version "1.2.2"}
|
||||||
|
;; hato/hato {:mvn/version "1.0.0"}
|
||||||
|
}
|
||||||
|
|
||||||
:aliases
|
:aliases
|
||||||
{;; Run with clj -T:build function-in-build
|
{;; Run with clj -T:build function-in-build
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,11 @@
|
||||||
:mastodon-host "MASTODON_BASE_URL"
|
:mastodon-host "MASTODON_BASE_URL"
|
||||||
:mastodon-account-id "MASTODON_ACCOUNT_ID"
|
:mastodon-account-id "MASTODON_ACCOUNT_ID"
|
||||||
:api-host "API_HOST"
|
:api-host "API_HOST"
|
||||||
:api-port "API_PORT"})
|
:api-port "API_PORT"
|
||||||
|
:nostr-fetcher-npub "NOSTR_FETCHER_NPUB"
|
||||||
|
:nostr-id "NOSTR_ID"
|
||||||
|
:nostr-relay "NOSTR_RELAY"
|
||||||
|
})
|
||||||
|
|
||||||
(defn- load-config []
|
(defn- load-config []
|
||||||
(merge (read-string (slurp "config.edn"))
|
(merge (read-string (slurp "config.edn"))
|
||||||
|
|
|
||||||
28
src/micro_blog/nostr.clj
Normal file
28
src/micro_blog/nostr.clj
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
(ns micro-blog.nostr
|
||||||
|
(:require
|
||||||
|
[gniazdo.core :as ws]
|
||||||
|
[cheshire.core :as json]
|
||||||
|
[micro-blog.config :refer [config]]))
|
||||||
|
|
||||||
|
;; :nostr-fetcher-npub "NOSTR_FETCHER_NPUB"
|
||||||
|
;; :nostr-id "NOSTR_ID"
|
||||||
|
;; :nostr-relay "NOSTR_RELAY"
|
||||||
|
(def socket (atom nil))
|
||||||
|
|
||||||
|
(defn connect []
|
||||||
|
(reset! socket
|
||||||
|
(ws/connect
|
||||||
|
(@config :nostr-relay)
|
||||||
|
:on-receive #(prn 'received %))))
|
||||||
|
|
||||||
|
(defn subscribe-to-author [pubkey]
|
||||||
|
(let [sub-id "sub-1"
|
||||||
|
filter {:kinds [1] :authors [pubkey] :limit 10}
|
||||||
|
msg (json/generate-string ["REQ" sub-id filter])]
|
||||||
|
(send-msg msg)))
|
||||||
|
|
||||||
|
(defn send-msg [msg]
|
||||||
|
(ws/send-msg @socket msg))
|
||||||
|
|
||||||
|
(defn close []
|
||||||
|
(ws/close @socket))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue