vrchatapi / VRChatPython

A Python library for the VRChat API.
41 stars 10 forks source link

Client.fetch_world() - async #22

Closed CaptainDestructo closed 3 years ago

CaptainDestructo commented 3 years ago

I was having issues trying to use the get_world() function under Instance, so I threw this function in client.py to handle the world name specifically replace the synchronous fetch_world() function. It's yours if you want it.

ShingenPizza commented 3 years ago

But there already is a Client.fetch_world() method, just pick the name from that object.

CaptainDestructo commented 3 years ago

I tried doing that and had issues. Needed to get it working quick and dirty. I’ll see if I can replicate the issues I was having

CaptainDestructo commented 3 years ago

@ShingenPizza where is this method? I don't see it in the vrcpy folder. There's a get_world() classmethod in Instance, which returns the world object of an Instance, and a fetch_instance_via_id method in client which requires both a world_id and instance_id. If I don't have an instance_id to search with, I don't see how I can use this method.

Katistic commented 3 years ago

https://github.com/vrchatapi/VRChatPython/blob/73e0c1447392ce264e35d00bbb4d3814e4029d6b/vrcpy/client.py#L244

CaptainDestructo commented 3 years ago

Perhaps I should've clarified... I'm using the async rewrite. It's not present there as far as I can tell. I could make this pull request a little more useful by rewriting the fetch_world() funciton instead of just returning the name.

Katistic commented 3 years ago

No, it's my bad, I should have checked the branch Can you say what's happening? Tell us what you do, what you expect to happen, and what happens so we can fix the original problem instead of implementing a work-around. Since effectively, your fetch_world_name_via_id is the same as get_world

CaptainDestructo commented 3 years ago

So the primary issue, since I'm using the async rewrite branch, is that fetch_world() is nonexistent. While I could use fetch_instance_via_id() and from there Instance.get_world() to obtain the world object, this only works with a valid Instance ID. I haven't fully fleshed out my project yet, so I want to be prepared for the situation in which I many not have an instance ID to use.

Currently working on simply rewriting the fetch_world() command into Client.py which will require only a world ID.

CaptainDestructo commented 3 years ago

@Katistic I have now updated Client.py to fetch the LimitedWorld object of the world_id when fetch_world() is called. I couldn't get it to work with a World object however, as for some reason loop was being passed through World into BaseObject._assign(obj) as obj. Threw a TypeError for the loop not being iterable of course.

I'm offline for the night, and will be away from my desk until tomorrow evening (around 21 hours from now) but can answer questions from my phone intermittently as long as I don't have to scroll through code.

Katistic commented 3 years ago

I'll test and fix the world error then pull it :)

CaptainDestructo commented 3 years ago

The for some reason it pulls the loop in as obj. Could be due to World being a class based on LimitedWorld and not BaseObject idk. I’ll be at my desk in an hour or so

CaptainDestructo commented 3 years ago

What ended up being the issue? Just curious

Katistic commented 3 years ago

When passing loop from World to LimitedWorld, no kwarg was specified so it defaulted to obj (See here)

CaptainDestructo commented 3 years ago

Awesome thanks. I’ll pull the repo tomorrow night