示例#1
0
        private async void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (Authenticated)
            {
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", AuthToken);

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

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var resp = JsonConvert.DeserializeObject <List <NotificationResponse> >(await response.Content.ReadAsStringAsync());

                    foreach (var res in resp)
                    {
                        double result = DateTime.Now.Subtract(res.created_at).TotalSeconds;

                        var amount = Math.Round(result, 0);

                        if (amount < 200)
                        {
                            switch (res.type.Convert())
                            {
                            default:
                                OnNotificationReceived?.Invoke(this, new NotificationEventArgs(res.type.Convert(), res.message, this.GetAPIUserByID(res.senderUserId).Result));
                                break;

                            case NotificationType.friendRequest:
                                OnFriendshipRequestReceived?.Invoke(this, new NotificationEventArgs(res.type.Convert(), res.message, this.GetAPIUserByID(res.senderUserId).Result));
                                break;

                            case NotificationType.invite:
                                OnInviteReceived?.Invoke(this, new NotificationEventArgs(res.type.Convert(), res.message, this.GetAPIUserByID(res.senderUserId).Result));
                                break;

                            case NotificationType.requestInvite:
                                OnRequestInvite?.Invoke(this, new NotificationEventArgs(res.type.Convert(), res.message, this.GetAPIUserByID(res.senderUserId).Result));
                                break;
                            }
                        }
                    }
                }
            }
        }
 private void ReceiveInvite(InviteModel invite)
 {
     //update the UI
     OnInviteReceived?.Invoke(invite, null);
 }