From 8a1316674a1bcbc102fb4ee846e5b1c1928b572c Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 1 Aug 2025 01:58:33 +0900 Subject: [PATCH] add json --- .gitignore | 1 + bin/verse.zsh | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ json/user.json | 14 +++++++ json/verse.json | 23 ++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 .gitignore create mode 100755 bin/verse.zsh create mode 100644 json/user.json create mode 100644 json/verse.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ca4821a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +token.json diff --git a/bin/verse.zsh b/bin/verse.zsh new file mode 100755 index 0000000..6d5c114 --- /dev/null +++ b/bin/verse.zsh @@ -0,0 +1,97 @@ +#!/bin/zsh + +function at_env_arg() { + handle=syui.syui.ai + col=ai.syui.verse.user + rkey=self + host=syu.is +} + +function at_env() { + d=${0:a:h} + dd=${0:a:h:h} + pds=$host + f=$d/token.json + if [ ! -f $f ];then + echo password + read password + else + did=`cat $f|jq -r .did` + access=`cat $f|jq -r .accessJwt` + refresh=`cat $f|jq -r .refreshJwt` + fi + j_verse=`cat $dd/json/verse.json` + j_user=`cat $dd/json/user.json` + + case $col in + ai.syui.verse) + j=${j_verse} + ;; + ai.syui.verse.user) + j=${j_user} + ;; + esac + + if ! echo $j|jq .;then + exit + fi + if [ -n "`which gdate`" ];then + date=`gdate --iso-8601=seconds` + else + date=`date --iso-8601=seconds` + fi +} + +function at_create_session(){ + if [ ! -f $f ];then + req=com.atproto.server.createSession + url=https://$pds/xrpc/$req + curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$password\"}" $url >! $f + did=`cat $f|jq -r .did` + access=`cat $f|jq -r .accessJwt` + refresh=`cat $f|jq -r .refreshJwt` + fi +} + +function at_refresh_session(){ + req=com.atproto.server.refreshSession + url=https://${pds}/xrpc/$req + curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $refresh" $url >! $f + did=`cat $f|jq -r .did` + access=`cat $f|jq -r .accessJwt` + refresh=`cat $f|jq -r .refreshJwt` +} + +function at_put_record() { + req=com.atproto.repo.putRecord + url=https://$pds/xrpc/$req + + # jqでrecordを構築 + record=$(echo "$j" | jq ". + {\"createdAt\": \"$date\", \"updatedAt\": \"$date\"}") + + json=$(jq -n \ + --arg repo "$handle" \ + --arg did "$did" \ + --arg collection "$col" \ + --arg rkey "$rkey" \ + --argjson record "$record" \ + '{ + "repo": $repo, + "did": $did, + "collection": $collection, + "rkey": $rkey, + "record": $record + }') + + echo $json + if echo $json|jq . ;then + t=`curl -sL -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $access" -d "$json" $url` + echo $t|jq . + fi +} + +at_env_arg +at_env +at_create_session +at_refresh_session +at_put_record diff --git a/json/user.json b/json/user.json new file mode 100644 index 0000000..32e2ccd --- /dev/null +++ b/json/user.json @@ -0,0 +1,14 @@ +{ + "character": [ + { "id": 0, "cp": 100, "unique": true }, + { "id": 1, "cp": 100 , "unique": false } + ], + "item": [ + { "id": 0, "cp": 0 }, + { "id": 1, "cp": 0 } + ], + "card": [ + { "id": 0, "cp": 0 }, + { "id": 1, "cp": 0 } + ] +} diff --git a/json/verse.json b/json/verse.json new file mode 100644 index 0000000..fa2c669 --- /dev/null +++ b/json/verse.json @@ -0,0 +1,23 @@ +{ + "system": [ + { + "at": "account", + "ai": "ability", + "yui": "unique", + "world": "planet" + } + ], + "yui": { + "character": [ + {"id": 0, "name": "ai", "ability": "ai"}, + {"id": 1, "name": "shin", "ability": "atom"} + ] + }, + "ai": { + "ability": [ + { "id": 0, "name": "ai", "multiplier": { "ai": 2.0, "yui": 1.5, "atom": 1.2 } }, + { "id": 1, "name": "yui", "multiplier": { "ai": 2.0, "yui": 0.0, "atom": 0.0 } }, + { "id": 2, "name": "atom", "multiplier": { "ai": 0.0, "yui": 0.0, "atom": 0.0 } } + ] + } +}