usage:

wsconn wss://relay.nostr.band
# note: query id is populated automatically
wsc '["COUNT", "<QUERY_ID>", {"kinds": [41]}]'
#[
#  "COUNT",
#  "QUERY_53",
#  {
#    "count": 1831
#  }
#]

script:

function wsconn(){
  qid=0  
  WSCADDR=$1
  rm wsc.out
  screen -L -Logfile wsc.out -dmS wsc wscat -c $1
  screen -S wsc -p0 -X logfile flush 0
}
function wsreconn(){
  wsdisconn
  wsconn $WSCADDR
}
function wsdisconn(){
  kill $(screen -ls | grep -P "\d+\.wsc\W" | grep -Po "\d+")
}
function wsc(){
  let qid++
  queryid="QUERY_$qid"
  query=$(echo $1 | perl -pe "s/<QUERY_ID>/$queryid/")
  screen -S wsc -X stuff "$query\n"
  match=$(tail -f wsc.out | sed "/\"$queryid\",\W$/ q")
  res=$(cat wsc.out | grep -F -A 100 "\"$queryid\"" | ansi2txt | tail -n +2)
  echo "${res:5:-2}" | jq
}
Edit

Pub: 17 Oct 2023 23:56 UTC

Edit: 18 Oct 2023 00:43 UTC

Views: 214