ai/at
ai/at
1
0

Compare commits

...

7 Commits

Author SHA1 Message Date
09916187d5
update scpt 2024-12-26 22:15:01 +09:00
64a709e5a0
fix 2024-12-14 12:15:22 +09:00
f9e4866597
fix 2024-12-14 11:54:30 +09:00
d532d51ab9
fix 2024-11-28 05:25:43 +09:00
1512a1452f
fix 2024-11-28 04:48:55 +09:00
199a908ead
fix 2024-11-28 04:46:44 +09:00
0403ba0bc4
add scpt 2024-11-28 04:46:07 +09:00
6 changed files with 634 additions and 0 deletions

47
at.json Normal file
View File

@ -0,0 +1,47 @@
{
"atmosphere": {
"name": "at",
"repo": "https://github.com/bluesky-social/atproto",
"uri": "https://atproto.com/ja/guides/glossary",
"exosphere": {
"km":[{ "min": 700, "max": 10000 }],
"tag": [ "universe" ]
},
"thermosphere": {
"km":[{ "min": 80, "max": 700 }],
"tag": [ "aurora" ]
},
"mesosphere": {
"km":[{ "min": 50, "max": 80 }],
"tag": [ "meteor" ]
},
"stratosphere": {
"km":[{ "min": 12, "max": 50 }],
"tag": [ "ozone", "bigsky" ],
"service":[
{ "name":"ozone", "repo":"https://github.com/bluesky-social/atproto/tree/main/services/ozone" },
{ "name":"bgs", "repo":"https://github.com/bluesky-social/indigo/tree/main/cmd/bigsky" }
]
},
"troposphere": {
"km":[{ "min": 0, "max": 12 }],
"tag": [ "bluesky"],
"service":[
{ "name":"bsky", "repo":"https://github.com/bluesky-social/atproto/tree/main/services/bsky", "tag":[ "api", "appview" ] },
{ "name":"bsync","repo":"https://github.com/bluesky-social/atproto/tree/main/services/bsync" },
{ "name":"pds", "repo":"https://github.com/bluesky-social/atproto/tree/main/services/pds" }
]
},
"other": {
"tag": [ "plc", "feed", "oauth", "social-app", "stream" ],
"service":[
{ "name":"plc", "repo":"https://github.com/did-method-plc/did-method-plc/tree/main/packages/server", "tag" : [ "did" ] },
{ "name":"social-app", "repo":"https://github.com/bluesky-social/social-app", "tag": [ "web" ] },
{ "name":"oauth", "repo":"https://github.com/bluesky-social/cookbook/tree/main/python-oauth-web-app" },
{ "name":"feed", "repo":"https://github.com/bluesky-social/feed-generator" },
{ "name":"stream", "repo":"https://github.com/bluesky-social/jetstream" }
]
}
},
"ref": "https://en.wikipedia.org/wiki/Atmosphere_of_Earth"
}

View File

@ -0,0 +1,50 @@
import "server-only";
import { z } from "zod";
import { ensureUser } from "../user";
import { DataLayerError } from "../error";
import { fetchAuthenticatedAtproto } from "@/lib/auth";
import { AtUri } from "./uri";
const PutRecordResponse = z.object({
uri: AtUri,
cid: z.string(),
});
type PutRecordInput = {
rkey?: string;
record: unknown;
collection: string;
};
export async function atprotoPutRecord({
rkey,
record,
collection,
}: PutRecordInput) {
const user = await ensureUser();
const pdsUrl = new URL(user.pdsUrl);
pdsUrl.pathname = "/xrpc/com.atproto.repo.putRecord";
const response = await fetchAuthenticatedAtproto(pdsUrl.toString(), {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
rkey: rkey || "self",
repo: user.did,
collection,
validate: false,
record: record,
}),
});
if (!response.ok) {
throw new DataLayerError(`Failed to create record ${response.status}`, {
cause: response,
});
}
return PutRecordResponse.parse(await response.json());
}

60
scpt/at.zsh Executable file
View File

@ -0,0 +1,60 @@
#!/bin/zsh
d=${0:a:h}
source $d/src/tag.zsh
source $d/src/func.zsh
at-env
case $1 in
version|v)
at-version
;;
uri|u)
at-uri $2
;;
did|d)
at-did $2
;;
collection|c)
at-collection $2 $3
;;
at-docs|docs)
at-docs
;;
cid)
at-cid $2 $3
;;
login|l)
at-login $2 $3
;;
refresh|r)
at-refresh
;;
session|s)
at-session
;;
profile|pro)
at-profile
;;
download-character-icon)
source $d/ai/syui/game/character.zsh
download_character_icon
;;
create-game-character)
source $d/ai/syui/game/character.zsh
create_game_character
;;
ai-create-user)
source $d/ai/syui/game/character.zsh
ai_create_user
;;
*)
echo "${help[@]}"
echo "${host[@]}"
echo "${lexicon[@]}"
echo "${github[@]}"
echo "${tag[@]}"
;;
esac
at-unset

View File

@ -0,0 +1,302 @@
character=(
ai
manny
quinn
chinese
kirin
leviathan
phoenix
wyvern
cerberus
dragon
kitsune
pegasus
)
img=(
bafkreie34pjuc6coenzcdwrgrh4fbacq7bkhsz263g5vpbsqxwaz37kkwy
bafkreie34pjuc6coenzcdwrgrh4fbacq7bkhsz263g5vpbsqxwaz37kkwy
bafkreie34pjuc6coenzcdwrgrh4fbacq7bkhsz263g5vpbsqxwaz37kkwy
bafkreidlealfybajqzwv5eoz4jshnsijc2vnktlhpw4ph47krwj6aigqby
bafkreiegpqedlrfa4ljhssdnkrr5hyd5huy2xhh2zszj5wq2wuuzejggmq
bafkreig6vszkx3c4dcortjwfsz6sa6zwqgj7zpxj4lxfrrkwql4xhiu5ou
bafkreich7fsumke2yvumvixkruonzrcevk3f6g2cntzfwdn4n2c2vox5dm
bafkreiacjvagsekhiiljz3j237b6klrt6pkptxljt7kltprgg5276gv25q
bafkreihpni4lp55jysalcntulzal5rbhidtbseanlucpyucagzxmv6xj24
bafkreia3huw2gdenqatoobx3hcft74chced46bw4znfgepo5aenegobkri
bafkreidy74aieb6ie646xhosginox5zbnbnrtd76cnt4pbn73hrxgfnple
bafkreifnbfj27fr6nv7qeqqmwdibf7qrw4lauvzoknw5hexbifmwqt6kmq
)
function download_character_icon(){
t=(
"https://sketchfab.com/3d-models/super-9a80a6d6cf6f4b08906505c7f945d3ce"
)
t=(
"https://sketchfab.com/3d-models/cerberus-quirky-series-4379b571b5a440119d1ebaddb0711142"
"https://sketchfab.com/3d-models/chinese-dragon-quirky-series-a383d3cf5b004978ac620806558b2924"
"https://sketchfab.com/3d-models/dragon-quirky-series-9a0989aae9b84ebdade28e84a0702a71"
"https://sketchfab.com/3d-models/kirin-quirky-series-b280c8bc5b87471eac1068acc91fdce1"
"https://sketchfab.com/3d-models/kitsune-quirky-series-4fc8b2ade43f4d4bb8a8e6e227f00a62"
"https://sketchfab.com/3d-models/leviathan-quirky-series-002200e1db2c461fbcaa8d2fdac2d766"
"https://sketchfab.com/3d-models/pegasus-quirky-series-a4488ae7a2d2405c927a50f5a8b2d6bb"
"https://sketchfab.com/3d-models/phoenix-quirky-series-1f0a01247b78441ab5b9cf8e9711e78e"
"https://sketchfab.com/3d-models/wyvern-quirky-series-7baad217325a45b4877514b3f5924be9"
)
for i in $t; do
name=`echo $i|cut -d / -f 5|cut -d - -f 1`
tt=`curl -sL $i|tr ' ' '\n' |grep .jpeg|cut -d '"' -f 2`
normal=`echo $tt|awk "NR==1"`
min=`echo $tt|awk "NR==2"`
if [ ! -f $name.jpeg ];then
curl -sL $normal -o $name.jpeg
fi
if [ ! -f ${name}-min.jpeg ];then
#curl -sL $min -o ${name}-min.jpeg
fi
array+=(`echo $tt|sed "1,2d"|cut -d ";" -f 2|cut -d '&' -f 1|tr '\n' ' '`)
echo $name
for ((i=1; i<=$#array; i++)); do
echo "Index: $i, Value: ${array[$i]}"
#curl -sL ${array[$i]} -o ${name}-${i}.jpeg
done
done
}
case $OSTYPE in
darwin*)
day=`gdate --iso-8601=seconds`
;;
*)
day=`date --iso-8601=seconds`
;;
esac
function create_game_character() {
t=(
ai
chinese
kirin
leviathan
phoenix
wyvern
cerberus
dragon
kitsune
pegasus
)
for ((i=1; i<=$#t; i++)); do
created=2020-01-01T00:00:00+09:00
col=ai.syui.game.character
req=com.atproto.repo.getRecord
url=https://$host/xrpc/$req
id=$i
name=${t[$i]}
chara=$name
rkey=$chara
repo=$did_yui
json="{\"collection\":\"$col\", \"rkey\":\"$rkey\", \"repo\":\"$repo\"}"
if [ $((RANDOM % 2)) -eq 0 ];then
gender=male
else
gender=female
fi
case $name in
ai)
gender=none
group=origin
season=0
;;
chinese|dragon|cerberus|pegasus|leviathan)
gender=male
group=fantasy
season=1
;;
kitsune|phoenix|kirin|wyvern)
gender=female
group=fantasy
season=1
;;
*)
continue ;;
esac
jj=`curl -sL "$url?repo=$repo&collection=$col&rkey=$rkey"`
link=`echo $jj|jq -r '.value.embed.external.thumb.ref.[]'`
size=`echo $jj|jq -r .value.embed.external.thumb.size`
mtype=`echo $jj|jq -r .value.embed.external.thumb.mimeType`
echo $name
echo $gender
echo https://cdn.bsky.app/img/feed_thumbnail/plain/$did_yui/$link
## upload img
#if [ -f ./${name}.jpeg ];then
# jj=`ai img-upload ./${name}.jpeg`
#elif [ -f ./${name}.png ];then
# jj=`ai img-upload ./${name}.png`
#fi
#link=`echo $jj|jq -r ".blob.ref.[]"`
#size=`echo $jj|jq -r .blob.size`
#mtype=`echo $jj|jq -r .blob.mimeType`
req=com.atproto.repo.putRecord
url=https://$host/xrpc/$req
nickname=$name
fullname=$name
uri=at://${did_yui}/$col/$chara
json="{
\"repo\": \"$handle_yui\",
\"did\": \"$did_yui\",
\"collection\": \"$col\",
\"rkey\": \"$chara\",
\"record\": {
\"id\": $id,
\"name\": \"$name\",
\"fullname\": \"$fullname\",
\"nickname\": \"$nickname\",
\"gender\": \"$gender\",
\"season\": $season,
\"group\": \"$group\",
\"embed\": {
\"\$type\": \"app.bsky.embed.external\",
\"external\": {
\"uri\": \"$uri\",
\"thumb\": {
\"\$type\": \"blob\",
\"ref\": {
\"\$link\": \"$link\"
},
\"mimeType\": \"$mtype\",
\"size\": $size
} } }, \"createdAt\": \"$created\", \"updatedAt\": \"$day\" } }"
if echo $json|jq . ;then
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
fi
done
}
function ai_create_user() {
col=ai.syui.game.user
rkey=ai
did=$did_yui
handle=$handle_yui
#rkey=syui
#img=https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:4hqjfn7m6n5hno3doamuhgef/bafkreie34pjuc6coenzcdwrgrh4fbacq7bkhsz263g5vpbsqxwaz37kkwy@jpeg
req=com.atproto.repo.putRecord
url=https://$host/xrpc/$req
for ((i=1; i<=${#character}; i++)); do
cname=${character[$i]}
cid=${img[$i]}
imguri=https://cdn.bsky.app/img/feed_thumbnail/plain/$did_yui/${cid}@jpeg
echo $imguri
echo $i $character $cname
season=1
group=test
lv=1
hp=100
exp=0
rank=0
mode=0
attack=0
attack_post=0
critical=0
critical_d=0
case $cname in
ai)
group=origin
season=0
mode=2
;;
manny|quinn)
group=test
;;
*)
group=fantasy
;;
esac
jc="\"$cname\": { \"group\": \"$group\", \"season\": $season, \"img\": \"$imguri\", \"lv\": $lv, \"exp\": $exp, \"hp\": $hp, \"rank\": $rank, \"mode\": $mode, \"attack\": $attack, \"attack_post\": $attack_post, \"critical\": $critical, \"critical_d\": $critical_d }"
if [ $#character -ne $i ];then
jc=${jc},
fi
json=${json}${jc}
done
json="
{
\"repo\": \"$handle_yui\",
\"did\": \"$did_yui\",
\"collection\": \"$col\",
\"rkey\": \"$rkey\",
\"record\": {
\"did\": \"$did\",
\"limit\": false,
\"login\": false,
\"handle\": \"$handle\",
\"aiten\": 10,
\"gender\": \"famale\",
\"character\": {
$json
},
\"createdAt\": \"${created}\",
\"updatedAt\": \"${created}\"
}
}"
if echo $json|jq . ;then
echo $token_yui
echo y
read y
if [ "y" = "$y" ];then
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
fi
fi
col=ai.syui.game
rkey=self
at_uri=at://$did_yui/ai.syui.game.user/ai
json="
{
\"repo\": \"$handle_yui\",
\"did\": \"$did_yui\",
\"collection\": \"$col\",
\"rkey\": \"$rkey\",
\"record\": {
\"account\": \"$at_uri\",
\"username\": \"ai\",
\"createdAt\": \"$created\"
}
}"
if echo $json|jq . ;then
echo y
read y
if [ "y" = "$y" ];then
curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token_yui" -d $json $url
fi
fi
}

136
scpt/src/func.zsh Normal file
View File

@ -0,0 +1,136 @@
function at-env() {
host=bsky.social
handle_syui=syui.ai
handle_yui=yui.syui.ai
did_yui=did:plc:4hqjfn7m6n5hno3doamuhgef
did_syui=did:plc:uqzpqmrjnptsxezjx4xuh2mn
handle=$handle_yui
did=$did_yui
created=2020-01-01T00:00:00+09:00
at_uri=at://$did_yui/ai.syui.game.user/syui
docs_uri=https://docs.bsky.app/docs/api
did=`echo $at_uri|cut -d / -f 3`
collection=`echo $at_uri|cut -d / -f 4`
rkey=`echo $at_uri|cut -d / -f 5`
d=${0:a:h}
f=~/.config/.at-zsh.json
if [ -f $f ];then
token=`cat $f|jq -r .accessJwt`
did=`cat $f|jq -r .did`
handle=`cat $f|jq -r .handle`
actor=$did
fi
}
function at-unset() {
unset t password token refresh
}
function at-version() {
curl -sL ${host}/xrpc/_health |jq .
}
function at-uri() {
if [ -n "$1" ];then
at_uri=$1
fi
req=/xrpc/com.atproto.repo.getRecord
url=https://${host}${req}
did=`echo $at_uri|cut -d / -f 3`
collection=`echo $at_uri|cut -d / -f 4`
rkey=`echo $at_uri|cut -d / -f 5`
curl -sL "$url?repo=$did&collection=$collection&rkey=$rkey"|jq .
}
function at-did() {
if [ -n "$1" ];then
handle=$1
fi
req=/xrpc/com.atproto.repo.describeRepo
url=https://${host}${req}
curl -sL "$url?repo=$handle"|jq .
}
function at-collection() {
reverse=false
if [ -n "$1" ];then
at_uri=$1
fi
if [ "$2" = "-r" ];then
reverse=true
fi
req=/xrpc/com.atproto.repo.listRecords
url=https://${host}${req}
did=`echo $at_uri|cut -d / -f 3`
collection=`echo $at_uri|cut -d / -f 4`
curl -sL "$url?repo=$did&collection=$collection&reverse=$reverse"|jq .
}
function at-docs() {
for i in $lexicon; do
req=`echo $i|tr '.' '-'|sed 's/[A-Z]/-&/g'|tr '[A-Z]' '[a-z]'`
url=$docs_uri/$req
echo $url
done
}
function at-login() {
if [ -z "$1" ] || [ -z "$2" ];then
echo handle password
exit
fi
handle=$1
password=$2
echo $password
json="{\"identifier\":\"$handle\",\"password\":\"$password\"}"
req=/xrpc/com.atproto.server.createSession
url=https://${host}${req}
if [ ! -d ~/.config ];then
mkdir -p ~/.config
fi
t=`curl -sL -X POST -H "Content-Type: application/json" -d $json $url`
if echo $t |jq .;then
echo $t >! $f
fi
}
function at-refresh() {
echo $f
token=`cat $f|jq -r .refreshJwt`
req=/xrpc/com.atproto.server.refreshSession
url=https://${host}${req}
t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url`
if echo $t |jq .;then
echo $t >! $f
fi
}
function at-cid() {
did=`at-did $1|jq -r .did`
cid=$2
req=/xrpc/com.atproto.sync.getBlob
url="https://${host}${req}?did=${did}&cid=${cid}"
curl -sL $url
}
function at-session() {
req=/xrpc/com.atproto.server.getSession
url=https://${host}${req}
t=`curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url`
if ! echo $t |jq .;then
echo refresh
t=`at-refresh`
fi
}
function at-profile() {
if [ ! -f $f ];then
echo login
exit
else
t=`at-session`
fi
req=/xrpc/app.bsky.actor.getProfile
url="https://${host}${req}?actor=$did"
curl -sL -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $token" $url|jq .
}

39
scpt/src/tag.zsh Normal file
View File

@ -0,0 +1,39 @@
help=(
at.zsh v
at.zsh d handle
at.zsh u at-uri
at.zsh c at-uri -r
at.zsh docs
at.zsh l handle password
at.zsh r
at.zsh s
at.zsh cid handle cid
at.zsh pro
at.zsh col ai.syui.game.user self
)
host=(
bsky.social
public.api.bsky.app
plc.directory
)
lexicon=(
# https://github.com/bluesky-social/atproto/tree/main/lexicons
com.atproto.repo.describeRepo
com.atproto.repo.getRecord
com.atproto.repo.listRecords
com.atproto.identity.resolveHandle
com.atproto.server.createSession
com.atproto.server.refreshSession
com.atproto.server.getSession
com.atproto.sync.getBlob
app.bsky.actor.getProfile
)
github=(
https://github.com/bluesky-social/atproto
https://github.com/bluesky-social/social-app
https://github.com/bluesky-social/feed-generator
https://github.com/bluesky-social/jetstream
https://github.com/bluesky-social/indigo
https://github.com/did-method-plc/did-method-plc
)
tag=( at bsky bsync pds bgs plc ozone feed jetstream social-app oauth )