add scpt notify
This commit is contained in:
parent
ebe7c97d69
commit
1873c007d4
15
scpt/env
Normal file
15
scpt/env
Normal file
@ -0,0 +1,15 @@
|
||||
cfg=~/.config/ai/test.json
|
||||
host=`cat $cfg|jq -r .host`
|
||||
handle=`cat $cfg|jq -r .handle`
|
||||
pass=`cat $cfg|jq -r .password`
|
||||
date=`date --iso-8601=seconds`
|
||||
|
||||
if [ ! -f $cfg.t ];then
|
||||
$d/token.zsh
|
||||
fi
|
||||
|
||||
if [ -f $cfg.t ];then
|
||||
token=`cat $cfg.t|jq -r .accessJwt`
|
||||
refresh=`cat $cfg.t|jq -r .refreshJwt`
|
||||
did=`cat $cfg.t|jq -r .did`
|
||||
fi
|
27
scpt/main.zsh
Executable file
27
scpt/main.zsh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/bin/zsh
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias date="/opt/homebrew/bin/gdate"
|
||||
;;
|
||||
esac
|
||||
d=${0:a:h}
|
||||
source $d/env
|
||||
source $d/refresh.zsh
|
||||
source $d/token.zsh
|
||||
source $d/reply.zsh
|
||||
source $d/notify.zsh
|
||||
|
||||
case $1 in
|
||||
refresh|r)
|
||||
refresh
|
||||
;;
|
||||
token|t)
|
||||
token
|
||||
;;
|
||||
reply)
|
||||
reply
|
||||
;;
|
||||
notify|n)
|
||||
notify
|
||||
;;
|
||||
esac
|
27
scpt/notify.zsh
Executable file
27
scpt/notify.zsh
Executable file
@ -0,0 +1,27 @@
|
||||
function notify() {
|
||||
url=https://$host/xrpc/app.bsky.notification.listNotifications
|
||||
if [ ! -f $d/notify.json ];then
|
||||
curl -sL "Content-Type: application/json" -H "Authorization: Bearer $token" "$url?limit=100" >! $d/notify.json
|
||||
fi
|
||||
#cat $d/notify.json
|
||||
|
||||
for ((i=0;i<=99;i++))
|
||||
do
|
||||
cid=`cat $d/notify.json|jq ".|.[].[$i]?|.cid?"`
|
||||
uri=`cat $d/notify.json|jq ".|.[].[$i]?|.uri?"`
|
||||
echo $cid
|
||||
echo $uri
|
||||
cid_r=`cat $d/notify.json|jq ".[]|.[$i]?|.record.reply.root.cid?"`
|
||||
|
||||
if [ "$cid_r" = "null" ];then
|
||||
continue
|
||||
fi
|
||||
uri_r=`cat $d/notify.json|jq ".[]|.[$i]?|.record.reply.root.uri?"`
|
||||
cid_p=`cat $d/notify.json|jq ".[]|.[$i]?|.record.reply.parent.cid?"`
|
||||
uri_p=`cat $d/notify.json|jq ".[]|.[$i]?|.record.reply.parent.uri?"`
|
||||
echo $cid_r
|
||||
echo $uri_r
|
||||
echo $cid_p
|
||||
echo $uri_p
|
||||
done
|
||||
}
|
11
scpt/refresh.zsh
Executable file
11
scpt/refresh.zsh
Executable file
@ -0,0 +1,11 @@
|
||||
function refresh(){
|
||||
token=`cat $cfg.t|jq -r .accessJwt`
|
||||
refresh=`cat $cfg.t|jq -r .refreshJwt`
|
||||
if [ ! -f $cfg ];then
|
||||
token
|
||||
fi
|
||||
url=https://$host/xrpc/com.atproto.server.refreshSession
|
||||
j=`curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url`
|
||||
echo $j
|
||||
echo $j >! $cfg.t
|
||||
}
|
29
scpt/reply.zsh
Executable file
29
scpt/reply.zsh
Executable file
@ -0,0 +1,29 @@
|
||||
function reply() {
|
||||
|
||||
url="https://$host/xrpc/com.atproto.repo.createRecord"
|
||||
col="app.bsky.feed.post"
|
||||
|
||||
json="{
|
||||
\"repo\": \"$handle\",
|
||||
\"did\": \"$did\",
|
||||
\"collection\": \"$col\",
|
||||
\"record\": {
|
||||
\"text\": \"$text\",
|
||||
\"createdAt\": \"$date\",
|
||||
\"reply\": {
|
||||
\"root\": {
|
||||
\"cid\": \"$cid\",
|
||||
\"uri\": \"$uri\"
|
||||
},
|
||||
\"parent\": {
|
||||
\"cid\": \"$cid_p\",
|
||||
\"uri\": \"$uri_p\"
|
||||
}
|
||||
}
|
||||
}
|
||||
}"
|
||||
|
||||
echo $json|jq .
|
||||
url=https://$host/xrpc/com.atproto.repo.createRecord
|
||||
j=`curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token" -d "$json" $url`
|
||||
}
|
6
scpt/token.zsh
Executable file
6
scpt/token.zsh
Executable file
@ -0,0 +1,6 @@
|
||||
function token() {
|
||||
url=https://$host/xrpc/com.atproto.server.createSession
|
||||
j=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url`
|
||||
echo $j
|
||||
echo $j >! $cfg.t
|
||||
}
|
Loading…
Reference in New Issue
Block a user