-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveFriends.sh
More file actions
executable file
·51 lines (43 loc) · 2.14 KB
/
removeFriends.sh
File metadata and controls
executable file
·51 lines (43 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
authCookie="authcookie_3c285f01-8d07-4819-b348-cf4e25091acb"
cutoffDate="2021-01-1T00:00:1.000Z" # Remove all friends who haven't logged in after this date.
apiKey="JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26"
# Remove friends.txt if already exist
rm friends.txt &> /dev/null
# Testing credentials
echo "Testing credentials"
response=$(curl -s -w "%{http_code}\n" -o /dev/null --request GET --url "https://vrchat.com/api/1/auth/user?apiKey=$apiKey" --cookie "auth=$authCookie; Expires=null; Domain=vrchat.com")
if [ "$response" != "200" ]; then
echo "Problem calling VRChat API. Response code: $response"
exit 1
fi
userInfo=$(curl -s --request GET --url "https://vrchat.com/api/1/auth/user?apiKey=$apiKey" --cookie "auth=$authCookie; Expires=null; Domain=vrchat.com")
echo "Hello $(echo $userInfo | jq .displayName -r)"
# Gather friends' ids, username and last login date in fiends.txt. We ask for 100 at a time. Max 1000 friends.
echo "Fetching friends..."
for i in {1..10}; do
curl -s -S --request GET --url "https://vrchat.com/api/1/auth/user/friends?offline=true&n=$(($i*100))&offset=0&apiKey=$apiKey" \
--cookie "auth=$authCookie; Expires=null; Domain=vrchat.com" \
| jq ".[] | {id, username, last_login}" \
| jq "select(.last_login < \"$cutoffDate\") | select(.username != null )" >> friends.txt
done
count=$(jq .username -r friends.txt | wc -l)
if [ "$count" == "0" ]; then
echo "No friends to remove, all friends have been online after set cutoffDate: $cutoffDate"
echo "Please edit the cutoffDate in this script to change how long friends have to have been offline for in order to be removed."
exit 2
fi
jq .username -r friends.txt
echo "Do you want to delete these friends? ($(jq .username -r friends.txt | wc -l))"
echo "If you're sure type 'yes' and hit enter"
read ready
if [[ $ready != "yes" ]]; then
echo "Abort"
exit 3
fi
# Send Delete request for each friend id in friends.txt
for friend in $(cat friends.txt | jq .id -r); do
curl --request DELETE --url "https://vrchat.com/api/1/auth/user/friends/$friend?apiKey=$apiKey" \
--cookie "auth=$authCookie; Expires=null; Domain=vrchat.com"
echo
done