Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # stalk your vrfrens
- # more features soon™
- set -euo pipefail
- USER=$1
- KEYFILE=/tmp/vrfrens-apikey.txt
- # cache key so we don't have to grab it every time
- if [ -f $KEYFILE ]; then
- KEY=$(<$KEYFILE)
- else
- KEY=$(curl -s https://api.vrchat.cloud/api/1/config | jq .apiKey -r)
- echo $KEY > $KEYFILE
- fi
- TOKFILE=/tmp/vrfrens-tok-$USER.txt
- # also cache TOK for some time to avoid logging in if necessary. Dunno how long
- # the tokens actually last.
- if [ -f $TOKFILE ] && test $(find $TOKFILE -not -mmin +30); then
- TOK=$(<$TOKFILE)
- else
- TOK=$(curl -su $USER "https://api.vrchat.cloud/api/1/auth/user?apiKey=$KEY" | jq .authToken -r)
- echo $TOK > $TOKFILE
- fi
- FRENS=$(curl -H "Cookie: auth=$TOK" -s "https://api.vrchat.cloud/api/1/auth/user/friends?apiKey=$KEY")
- echo You have $(echo $FRENS | jq -r 'length') friends online
- # grab all unique non-private worlds
- # || true to prevent grep's nonzero status from exiting the script with set -e
- WRLDS=$(echo $FRENS | jq -r 'map(.location) | unique | join ("\n")' | grep -v private || true)
- declare -A WLDINFO
- for w in $WRLDS; do
- if [[ "$w" =~ ([^:]+):.+ ]]; then
- wid="${BASH_REMATCH[1]}"
- WLDINFO[$w]=$(curl -H "Cookie: auth=$TOK" -s "https://api.vrchat.cloud/api/1/worlds/$wid?apiKey=$KEY")
- fi
- done
- echo $FRENS | jq -r 'map("\(.displayName) \(.location)") | join("\n")' | while read fren loc; do
- if [[ -z "$fren" ]]; then continue; fi
- fren="REDACTED"
- if [[ "$loc" = "private" ]] ; then
- echo $fren is in a private world.
- elif [[ "$loc" = "offline" ]] ; then
- echo $fren is actually offline, strange. # got this response once, weird
- else
- info=${WLDINFO[$loc]}
- if [[ "$w" =~ [^:]+:(.+) ]]; then
- instid="${BASH_REMATCH[1]}"
- population=$(echo $info | jq ".instances[] | select(.[0] == \"$instid\") | .[1]")
- if [[ -z "$population" ]]; then
- # XXX sometimes the the world info doesn't include the instance in the list
- # but usually it does (even if hidden), so we can get the poopulation.
- # echo $fren claims to be in $loc
- # echo something happened: $instid
- # echo $info
- # echo $info | jq '.instances[]'
- # well we can assume it's something less than the total occupants of the world
- population="unknown, <$(echo $info | jq -r .occupants)"
- fi
- fi
- echo $fren is in $(echo $info | jq -r '"\"\(.name)\" [\(.description)]"') \($population people including them\)
- fi
- done
- OFFRENS=$(curl -H "Cookie: auth=$TOK" -s "https://api.vrchat.cloud/api/1/auth/user/friends?apiKey=$KEY&offline=true")
- echo You have $(echo $OFFRENS | jq -r 'length') friends offline:
- #echo $OFFRENS | jq -r 'map(.displayName) | join("\n")'
Advertisement
Add Comment
Please, Sign In to add comment