Guest User

Untitled

a guest
May 1st, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # stalk your vrfrens
  3. # more features soon™
  4. set -euo pipefail
  5.  
  6. USER=$1
  7.  
  8. KEYFILE=/tmp/vrfrens-apikey.txt
  9. # cache key so we don't have to grab it every time
  10. if [ -f $KEYFILE ]; then
  11.   KEY=$(<$KEYFILE)
  12. else
  13.   KEY=$(curl -s https://api.vrchat.cloud/api/1/config | jq .apiKey -r)
  14.   echo $KEY > $KEYFILE
  15. fi
  16.  
  17. TOKFILE=/tmp/vrfrens-tok-$USER.txt
  18. # also cache TOK for some time to avoid logging in if necessary. Dunno how long
  19. # the tokens actually last.
  20. if [ -f $TOKFILE ] && test $(find $TOKFILE -not -mmin +30); then
  21.   TOK=$(<$TOKFILE)
  22. else
  23.   TOK=$(curl -su $USER "https://api.vrchat.cloud/api/1/auth/user?apiKey=$KEY" | jq .authToken -r)
  24.   echo $TOK > $TOKFILE
  25. fi
  26.  
  27. FRENS=$(curl -H "Cookie: auth=$TOK" -s "https://api.vrchat.cloud/api/1/auth/user/friends?apiKey=$KEY")
  28. echo You have $(echo $FRENS | jq -r 'length') friends online
  29. echo $FRENS | jq -r 'map("\(.displayName) is in \"\(.location)\"") | join("\n")'
  30.  
  31. OFFRENS=$(curl -H "Cookie: auth=$TOK" -s "https://api.vrchat.cloud/api/1/auth/user/friends?apiKey=$KEY&offline=true")
  32. echo You have $(echo $OFFRENS | jq -r 'length') friends offline:
  33. echo $OFFRENS | jq -r 'map(.displayName) | join("\n")'
Advertisement
Add Comment
Please, Sign In to add comment