private static async Task <List <FriendData> > GetFriendsAsync(VrchatApiWrapper wrapper, bool isOffline) { var users = new List <FriendData>(); var offset = 0; for (; ;) { List <OtherUserInfo> friends; try { var list = await wrapper.Friends.GetFriendsAsync(offset, 20, isOffline); friends = list.Select(x => new OtherUserInfo { Id = x.Id, CurrentAvatarImageUrl = x.CurrentAvatarImageUrl, CurrentAvatarThumbnailImageUrl = x.CurrentAvatarThumbnailImageUrl, DeveloperType = x.DeveloperType, DisplayName = x.DisplayName, InstanceId = x.InstanceId, Location = x.Location, Tags = x.Tags, UserName = x.UserName, WorldId = x.WorldId }).ToList(); } catch (Exception) { friends = null; } if (friends == null) { continue; } foreach (var userBriefResponse in friends) { var user = new FriendData { Id = userBriefResponse.Id, Name = userBriefResponse.DisplayName, Location = userBriefResponse.Location, ImageUrl = userBriefResponse.CurrentAvatarThumbnailImageUrl }; await ConvertLocationAsync(wrapper, user); users.Add(user); } if (friends.Count < 20) { break; } offset += friends.Count; } return(users); }
public async Task <List <FriendData> > GetFriendsAsync(VrchatApiWrapper wrapper) { var users = new List <FriendData>(); var onlineList = await GetFriendsAsync(wrapper, false); var offlineList = await GetFriendsAsync(wrapper, true); users.AddRange(onlineList); users.AddRange(offlineList); return(users); }
/// <summary> /// ワールド情報を取得します。 /// </summary> /// <param name="wrapper"></param> /// <param name="worldId"></param> /// <returns></returns> public async Task <WorldInfo> GetWorldAsync(VrchatApiWrapper wrapper, string worldId) { try { return(await wrapper.World.GetByIdAsync(worldId)); } catch (Exception) { // ignored } return(null); }
private static async Task <UserInfo> LoginAsync(string id, string password) { var wrapper = new VrchatApiWrapper(id, password); await wrapper.RemoteConfig.GetRemoteConfigAsync(); var userResponse = await wrapper.CurrentUser.LoginAsync(); if (userResponse == null) { return(null); } VrchatApiData.Instance.Wrapper = wrapper; return(userResponse); }
/// <summary> /// ワールドのインスタンス情報を取得します。 /// </summary> /// <param name="wrapper"></param> /// <param name="worldId"></param> /// <param name="instanceId"></param> /// <returns></returns> public async Task <InstanceInfo> GetInstanceAsync(VrchatApiWrapper wrapper, string worldId, string instanceId) { try { var instanceInfo = await wrapper.World.GetInstanceInfoAsync(worldId, instanceId); if (instanceInfo != null) { return(instanceInfo); } } catch (Exception) { // ignored } return(null); }
private static async Task ConvertLocationAsync(VrchatApiWrapper wrapper, FriendData user) { var worldData = new WorldData(); var location = user.Location; var userId = user.Id; user.InstanceOccupant = ""; switch (location) { case "offline": user.StatusText = "Offline"; break; case "private": user.StatusText = "Private"; break; default: if (location.Contains(':')) { var array = location.Split(':'); if (array.GetElementOrDefault(1) == userId) { user.StatusText = "Private"; } else { var worldResponse = await worldData.GetWorldAsync(wrapper, array.GetElementOrDefault(0)); if (worldResponse != null) { var worldInstanceResponse = await worldData.GetInstanceAsync(wrapper, array.GetElementOrDefault(0), array.GetElementOrDefault(1)); if (worldInstanceResponse?.Users != null) { user.StatusText = worldResponse.Name; } } } } break; } }
/// <summary> /// ワールドを検索します。 /// </summary> /// <param name="wrapper"></param> /// <param name="searchOption"></param> /// <returns></returns> public async Task <List <WorldInfo> > SearchWorldAsync(VrchatApiWrapper wrapper, WorldSearchOption searchOption = null) { var worldBriefResponse = new List <WorldInfo>(); var offset = 0; for (;;) { var world = new List <WorldInfo>(); try { if (searchOption == null || searchOption.NoOption) { world = await wrapper.World.SearchAsync(offset : offset); } else { world = await wrapper.World.SearchAsync(offset : offset, keyword : searchOption.Keyword, endpointType : searchOption.EndpointType, sort : searchOption.SortOptions, featured : searchOption.IsFeatured); } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); Console.Error.WriteLine(ex.StackTrace); } worldBriefResponse.AddRange(world); if (world.Count < 20) { break; } offset += worldBriefResponse.Count; } return(worldBriefResponse); }