1
0
bot/.config/ai/scpt/user.zsh
2024-02-21 19:22:37 +09:00

383 lines
8.3 KiB
Bash
Executable File

#!/bin/zsh
txt=_atproto.$1
did=$2
curl -sL plc.directory/$did/log |jq ".[]|.alsoKnownAs|.[]?" | grep -n .| head -n 4
dig -t TXT $txt|grep "did=did:plc:"|head -n 1
#dig syui.ai +short
#!/bin/zsh
#
case $OSTYPE in
darwin*)
alias date="/opt/homebrew/bin/gdate"
;;
esac
if [ "$1" = "test" ] || [ -z "$1" ];then
handle=syui.ai
else
handle=$1
fi
post=0
d=`date +"%Y-%m-%d"`
od=`date +"%Y-%m-%d" --date '1 day ago'`
unset cursor
function first_record(){
cursor=`curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$handle&collection=app.bsky.feed.post&limit=100" |jq -r ".cursor"`
t=`curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$handle&collection=app.bsky.feed.post&limit=100" |jq -r ".[]|.[]?|.value.createdAt"|cut -d T -f 1`
n=`echo $t|wc -l`
}
function cursor_record(){
cursor=`curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$handle&collection=app.bsky.feed.post&limit=100&cursor=$cursor" |jq -r ".cursor"`
t=`curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$handle&collection=app.bsky.feed.post&limit=100&cursor=$cursor" |jq -r ".[]|.[]?|.value.createdAt"|cut -d T -f 1`
n=`echo $t|wc -l`
}
function day_check(){
for ((i=1;i<=$n;i++))
do
tt=`echo $t|awk "NR==$i"`
if [ "$tt" = "$d" ];then
post=$((post + 1))
echo $post
fi
if [ "$tt" = "$od" ];then
echo $tt $od
echo $post
exit
fi
done
}
for ((ii=1;ii<=100;ii++))
do
if [ $ii -eq 1 ];then
first_record
else
echo $cursor
cursor_record
fi
day_check
done
#!/bin/zsh
url_plc="https://plc.directory/export"
host_at=bsky.social
url=https://plc.directory
url_at=https://$host_at/xrpc/com.atproto.repo.listRecords
dir=$HOME/.config/atr/txt
file=$dir/user_list.txt
atr=$HOME/.cargo/bin/atr
unset timed
case $OSTYPE in
darwin*)
alias date="/opt/homebrew/bin/gdate"
;;
esac
if [ -z "$1" ];then
exit
fi
if ! echo $1|grep "." >/dev/null 2>&1;then
echo "ex : user syui.bsky.social"
exit
fi
if [ ! -d $dir ];then
mkdir -p $dir
fi
if [ ! -f $file ];then
touch $file
fi
function mfile() {
t=`cat $file|sort|uniq`
if [ -n "$t" ];then
echo "$t" >! ${file}.back
mv ${file}.back $file
fi
}
function plc(){
if cat $file|grep "$1" >/dev/null 2>&1;then
cat $file|grep "$1"
exit
fi
json_tmp=`curl -sL "${url_plc}?after=${timed}"|jq .`
json=`echo $json_tmp|jq "select(.operation.handle == \"$1\")"`
if [ -z "$json" ];then
check=`echo $json_tmp|jq -r ".operation.alsoKnownAs"|head -n 1`
if [ "null" != "$check" ];then
json=`echo $json_tmp|jq "select(.operation.alsoKnownAs|.[] == \"at://$1\")"` >/dev/null 2>&1
fi
fi
if [ -n "$json" ];then
created_at=`echo $json|jq -r .createdAt |tail -n 1`
fi
if [ -n "$created_at" ];then
echo "$created_at : $1"
echo "$created_at : $1" >> $file
mfile
exit
fi
}
function fan_art(){
if ! echo $3|grep "https://bsky.app/profile/">/dev/null 2>&1;then
echo "please url : https://bsky.app/profile/$1/post/xxx"
exit
fi
if [ -z "$4" ];then
echo "please img-url : https://example.com/img.png"
exit
fi
img=$4
author=`echo $3|cut -d / -f 5`
cd $dir_git_card_page
cat $file_fanart|jq ".+ {\"add\":\"$1\",\"link\":\"$3\",\"author\":\"$author\",\"img\":\"$img\"}" >! $file_fanart.back
if cat $file_fanart|jq . ;then
mv $file_fanart.back $file_fanart
git add $file_fanart
git commit -m "add fanart"
git push -u orgin main
fi
}
if [ "$2" = "--url" ];then
if [ -z "$3" ];then
exit
fi
fan_art $3
exit
fi
function first(){
#https://bsky.app/profile/$1/post/$e
handle=$2
did="$atr did $2"
curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$handle&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.uri,.value.text,.value.createdAt"
}
if [ "$2" = "-f" ] || [ "$2" = "f" ];then
first $1
exit
fi
if [ "$2" = "-l" ];then
mfile
cat $file
exit
fi
function first_created(){
#https://bsky.app/profile/$1/post/$e
#curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$1&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.createdAt"
curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$1&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.value.createdAt"
}
if [ -z "$2" ];then
first_created $1
fi
if [ -n "$2" ] ;then
first $2
fi
#for ((i=0;i<=300;i++))
#do
# if [ $i -eq 0 ];then
# timed="1970-01-01"
# fi
# plc $1
# timed=`echo $json_tmp|jq -r .createdAt|tail -n 1`
#done
#!/bin/zsh
if [ -n "$1" ];then
did=$1
else
did=`atr did yui.syui.ai`
fi
pds=`curl -sL https://plc.directory/$did|jq -r ".service.[].serviceEndpoint" | cut -d / -f 3-`
handle=`curl -sL https://plc.directory/$did|jq -r ".alsoKnownAs.[]"|cut -d / -f 3-`
old_pds=`curl -sL https://plc.directory/$did/log|jq -r ".[0].service"|cut -d / -f 3-`
old_handle=`curl -sL https://plc.directory/$did/log|jq -r ".[0]|.handle"`
first_post=`curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$did&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.value.createdAt"`
body_handle=$handle
body_pds=$pds
if [ "$old_handle" != "null" ];then
body_handle="$old_handle -> $handle"
fi
if [ "$old_pds" != "null" ];then
body_pds="$old_pds -> $pds"
fi
old_pds=`curl -sL https://plc.directory/$did/log|jq -r ".[0]|.services.atproto_pds.endpoint"|cut -d / -f 3-`
old_handle=`curl -sL https://plc.directory/$did/log|jq -r ".[0]|.alsoKnownAs.[0]"|cut -d / -f 3-`
if [ "$old_handle" != "null" ];then
body_handle="$old_handle -> $handle"
fi
if [ "$old_pds" != "null" ];then
body_pds="$old_pds -> $pds"
fi
if [ "$old_pds" = "$pds" ];then
body_pds=$pds
fi
if [ "$old_handle" = "$handle" ];then
body_handle=$handle
fi
echo pds : $body_pds
echo handle : $body_handle
echo did : $did
echo createdAt : $first_post
#!/bin/zsh
url_plc="https://plc.directory/export"
host_at=bsky.social
url=https://plc.directory
url_at=https://$host_at/xrpc/com.atproto.repo.listRecords
dir=$HOME/.config/ai/txt
file=$dir/user_list.txt
unset timed
case $OSTYPE in
darwin*)
alias date="/opt/homebrew/bin/gdate"
;;
esac
if [ -z "$1" ];then
exit
fi
if ! echo $1|grep "." >/dev/null 2>&1;then
echo "ex : user syui.bsky.social"
exit
fi
if [ ! -d $dir ];then
mkdir -p $dir
fi
if [ ! -f $file ];then
touch $file
fi
function mfile() {
t=`cat $file|sort|uniq`
if [ -n "$t" ];then
echo "$t" >! ${file}.back
mv ${file}.back $file
fi
}
function plc(){
if cat $file|grep "$1" >/dev/null 2>&1;then
cat $file|grep "$1"
exit
fi
json_tmp=`curl -sL "${url_plc}?after=${timed}"|jq .`
json=`echo $json_tmp|jq "select(.operation.handle == \"$1\")"`
if [ -z "$json" ];then
check=`echo $json_tmp|jq -r ".operation.alsoKnownAs"|head -n 1`
if [ "null" != "$check" ];then
json=`echo $json_tmp|jq "select(.operation.alsoKnownAs|.[] == \"at://$1\")"` >/dev/null 2>&1
fi
fi
if [ -n "$json" ];then
created_at=`echo $json|jq -r .createdAt |tail -n 1`
fi
if [ -n "$created_at" ];then
echo "$created_at : $1"
echo "$created_at : $1" >> $file
mfile
exit
fi
}
function fan_art(){
if ! echo $3|grep "https://bsky.app/profile/">/dev/null 2>&1;then
echo "please url : https://bsky.app/profile/$1/post/xxx"
exit
fi
if [ -z "$4" ];then
echo "please img-url : https://example.com/img.png"
exit
fi
img=$4
author=`echo $3|cut -d / -f 5`
cd $dir_git_card_page
cat $file_fanart|jq ".+ {\"add\":\"$1\",\"link\":\"$3\",\"author\":\"$author\",\"img\":\"$img\"}" >! $file_fanart.back
if cat $file_fanart|jq . ;then
mv $file_fanart.back $file_fanart
git add $file_fanart
git commit -m "add fanart"
git push -u orgin main
fi
}
if [ "$2" = "--url" ];then
if [ -z "$3" ];then
exit
fi
fan_art $3
exit
fi
function first(){
#https://bsky.app/profile/$1/post/$e
curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$1&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.uri,.value"
}
if [ "$2" = "-f" ];then
first $1
exit
fi
if [ "$2" = "-l" ];then
mfile
cat $file
exit
fi
function first_created(){
#https://bsky.app/profile/$1/post/$e
#curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$1&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.createdAt"
curl -sL "https://bsky.social/xrpc/com.atproto.repo.listRecords?repo=$1&collection=app.bsky.feed.post&reverse=true" |jq -r ".[]|.[0]?|.value.createdAt"
}
first_created $1
#for ((i=0;i<=300;i++))
#do
# if [ $i -eq 0 ];then
# timed="1970-01-01"
# fi
# plc $1
# timed=`echo $json_tmp|jq -r .createdAt|tail -n 1`
#done