Example #1
0
        public static async Task <bool> Message(this VRCSharpSession session, APIUser user, string Message, string worldIdWithTags)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);

            var payload = JsonConvert.SerializeObject(new InvitePayload()
            {
                message = "", type = "invite", details = new Details($"{session.Info.displayName} said: {Message}", worldIdWithTags)
            });

            var response = await client.PostAsync($"https://vrchat.com/api/1/user/{user.id}/notification?apiKey={GlobalVars.ApiKey}", new StringContent(payload, Encoding.UTF8, "application/json"));

            Console.WriteLine(payload.ToString());
            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public static async Task <FriendStatus> Friend(this VRCSharpSession session, APIUser User)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);
            var payload = JsonConvert.SerializeObject(new FriendRequest()
            {
                _params = new FriendRequest.Params()
                {
                    userId = User.id
                }
            });
            var response = await client.PostAsync($"https://vrchat.com/api/1/user/{User.id}/friendRequest?apiKey={GlobalVars.ApiKey}", new StringContent(payload, Encoding.UTF8, "application/json"));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <FriendStatus>(await response.Content.ReadAsStringAsync()));
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public static async Task <bool> Moderate(this VRCSharpSession session, APIUser user, ModerationType type)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);
            var payload = JsonConvert.SerializeObject(new ModerationPayload()
            {
                moderated = user.id, type = type.Convert()
            });

            var response = await client.PostAsync($"https://vrchat.com/api/1/auth/user/playermoderations?apiKey={GlobalVars.ApiKey}&userId={user.id}", new StringContent(payload, Encoding.UTF8, "application/json"));

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public static async Task <FriendRequestCancel> Unfriend(this VRCSharpSession session, APIUser User)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);

            var response = await client.DeleteAsync($"https://vrchat.com/api/1/user/{User.id}/friendRequest?apiKey={GlobalVars.ApiKey}");

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(JsonConvert.DeserializeObject <FriendRequestCancel>(await response.Content.ReadAsStringAsync()));
            }
            else
            {
                return(null);
            }
        }
Example #5
0
        public static async Task <APIWorld> GetAPIWorldByID(this VRCSharpSession session, string WorldID)
        {
            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);

            var response = await client.GetAsync($"https://vrchat.com/api/1/worlds/{WorldID}?apiKey={GlobalVars.ApiKey}");

            return(JsonConvert.DeserializeObject <APIWorld>(await response.Content.ReadAsStringAsync()));
        }
Example #6
0
        public static async Task <bool> VoteKick(this VRCSharpSession session, APIUser User)
        {
            if (APIWorldHelper.CurrentWorldID == null)
            {
                Console.WriteLine("I can't votekick if you haven't made me join a world!");
                return(false);
            }
            else
            {
                HttpClientHandler handler = null;
                HttpClient        client  = new HttpClient();

                if (session.UseProxies)
                {
                    //Load proxies from Proxies.txt
                    handler       = new HttpClientHandler();
                    handler.Proxy = APIExtensions.GetRandomProxy();
                    client        = new HttpClient(handler);
                }

                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);
                var payload = JsonConvert.SerializeObject(new VoteKickPayload()
                {
                    worldId = APIWorldHelper.CurrentWorldID, instanceId = APIWorldHelper.CurrentInstanceID.ToString()
                });
                Console.WriteLine(payload.ToString());
                var response = await client.PostAsync($"https://vrchat.com/api/1/user/{User.id}/votekick?apiKey={GlobalVars.ApiKey}", new StringContent(payload, Encoding.UTF8, "application/json"));

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #7
0
        public static async Task <bool> VisitWorld(this VRCSharpSession session, APIWorld World, int InstanceID)
        {
            var nvc = new List <KeyValuePair <string, string> >();

            nvc.Add(new KeyValuePair <string, string>("userId", "asd"));
            nvc.Add(new KeyValuePair <string, string>("worldId", $"{World.id}:{InstanceID.ToString()}"));
            var req = new HttpRequestMessage(HttpMethod.Put, "https://vrchat.com/api/1/visits")
            {
                Content = new FormUrlEncodedContent(nvc)
            };

            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (session.UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", session.AuthToken);


            var response = await client.SendAsync(req);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                APIWorldHelper.CurrentWorldID    = World.id;
                APIWorldHelper.CurrentInstanceID = InstanceID;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        public async Task <bool> Login()
        {
            AuthToken = "Basic " + GlobalVars.Base64Encode(_username + ":" + _password);

            HttpClientHandler handler = null;
            HttpClient        client  = new HttpClient();

            if (UseProxies)
            {
                //Load proxies from Proxies.txt
                handler       = new HttpClientHandler();
                handler.Proxy = APIExtensions.GetRandomProxy();
                client        = new HttpClient(handler);
            }
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", AuthToken);

            var response = await client.GetAsync($"https://api.vrchat.cloud/api/1/auth/user?apiKey={GlobalVars.ApiKey}");

            if (response.StatusCode != HttpStatusCode.OK)
            {
                Authenticated = false;
                Details       = "Invalid Authorization.";
                OnAttemptedLogin?.Invoke(this, Details);
            }
            else
            {
                Authenticated = true;
                Details       = "Successful Login Attempt.";
                Info          = JsonConvert.DeserializeObject <AccountInfo>(await response.Content.ReadAsStringAsync());
                OnAttemptedLogin?.Invoke(this, Details);
            }


            return(Authenticated);
        }