Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit 19720ce

Browse files
authored
Merge pull request #11 from Katistic/master
Fixes to Avatar favorites and other stuff
2 parents 8e68b95 + 688bc04 commit 19720ce

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

examples/async/Get avatar.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ async def main():
66
client = vrcpy.AClient()
77
await client.login("username", "password")
88

9-
# Wait for connecting objects
10-
# This can be used when doing client.fetch_me as well.
11-
await client.wait_for_cache()
12-
139
# Get avatar via id
1410
a = await client.fetch_avatar("avtr_fa5303c6-78d1-451c-a678-faf3eadb5c50")
1511
author = await a.author() # Get author of the avatar

vrcpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = "vrcpy"
22
__author__ = "Katistic"
3-
__version__ = "0.6.0"
3+
__version__ = "0.6.2"
44

55
from vrcpy.client import Client
66
from vrcpy.client import AClient

vrcpy/aobjects.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ async def author(self):
1616
return User(self.client, resp["data"])
1717

1818
async def favorite(self):
19-
resp = await self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Avatar,\
20-
"favoriteId": self.id})
21-
return Favorite(resp["data"])
19+
resp = await self.client.api.call("/favorites", "POST", json={"type": types.FavoriteType.Avatar,\
20+
"favoriteId": self.id, "tags": ["avatars1"]})
21+
22+
f = Favorite(self.client, resp["data"])
23+
await f.cacheTask
24+
25+
return f
2226

2327
## User
2428

@@ -118,6 +122,9 @@ async def fetch_favorites(self, t):
118122
for favorite in resp["data"]:
119123
f.append(Favorite(self.client, favorite))
120124

125+
for fav in f:
126+
await fav.cacheTask
127+
121128
return f
122129

123130
async def favorite(self):
@@ -151,13 +158,12 @@ async def __cinit__(self):
151158
if hasattr(self, "homeLocation"):
152159
if self.homeLocation == "": self.homeLocation = None
153160
else: self.homeLocation = await self.client.fetch_world(self.homeLocation)
161+
else: self.homeLocation = None
154162

155163
# Wait for all cacheTasks
156164
if not self.homeLocation == None:
157165
await self.homeLocation.cacheTask
158166

159-
self.client.cacheFull = True
160-
161167
## World
162168

163169
class LimitedWorld(o.LimitedWorld):
@@ -202,7 +208,7 @@ async def __cinit__(self):
202208
if self.type == types.FavoriteType.World:
203209
self.object = await self.client.fetch_world(self.favoriteId)
204210
elif self.type == types.FavoriteType.Friend:
205-
for friend in self.client.me.friends():
211+
for friend in self.client.me.friends:
206212
if friend.id == self.favoriteId:
207213
self.object = friend
208214
break

vrcpy/client.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,19 +538,11 @@ async def login(self, username, password):
538538
self.me = aobjects.CurrentUser(self, resp["data"])
539539
self.loggedIn = True
540540

541-
async def wait_for_cache(self):
542-
'''
543-
Used to stall task and wait for caching to finish
544-
Returns void
545-
'''
546-
547-
while not self.cacheFull:
548-
await asyncio.sleep(1)
541+
await self.me.cacheTask
549542

550543
def __init__(self, verify=True):
551544
super().__init__()
552545

553-
self.cacheFull = False
554546
self.api = ACall(verify=verify)
555547
self.loggedIn = False
556548
self.me = None

vrcpy/objects.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def favorite(self):
7070
Returns favorite object
7171
'''
7272

73-
resp = self.client.api.call("/favorites", "POST", params={"type": types.FavoriteType.Avatar,\
74-
"favoriteId": self.id})
75-
return Favorite(resp["data"])
73+
resp = self.client.api.call("/favorites", "POST", json={"type": types.FavoriteType.Avatar,\
74+
"favoriteId": self.id, "tags": ["avatars1"]})
75+
return Favorite(self.client, resp["data"])
7676

7777
def __init__(self, client, obj):
7878
super().__init__(client)
@@ -299,6 +299,7 @@ def __cinit__(self):
299299
if hasattr(self, "homeLocation"):
300300
if self.homeLocation == "": self.homeLocation = None
301301
else: self.homeLocation = self.client.fetch_world(self.homeLocation)
302+
else: self.homeLocation = None
302303

303304
def __init__(self, client, obj):
304305
super().__init__(client)

vrcpy/request.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import json
12
import asyncio
23
import aiohttp
34
import requests
45

56
from vrcpy.errors import *
67

78
def raise_for_status(resp):
9+
if type(resp["data"]) == bytes:
10+
resp["data"] = json.loads(resp["data"].decode())
11+
812
def handle_400():
913
if resp["data"]["error"]["message"] == "These users are not friends":
1014
raise NotFriendsError("These users are not friends")
@@ -85,7 +89,9 @@ async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth
8589
try: json = await resp.json()
8690
except: json = None
8791

88-
return {"status": resp.status, "data": json if not json == None else content}
92+
resp = {"status": resp.status, "data": json if not json == None else content}
93+
raise_for_status(resp)
94+
return resp
8995

9096
json = await resp.json()
9197
status = resp.status

0 commit comments

Comments
 (0)