예제 #1
0
        private void BtnAfk_Click(object sender, RoutedEventArgs e)
        {
            if (RPC.AFK)
            {
                if (string.IsNullOrEmpty(TextAfk.Text))
                {
                    RPC.AFK             = false;
                    ViewLiveRPC.Content = new ViewRPC(ViewType.Default);
                    EnableElements();
                    try
                    {
                        RPC.Shutdown();
                    }
                    catch { }
                }
                else
                {
                    RPC.Presence.Details = TextAfk.Text;
                    TextAfk.Text         = "";
                    RPC.Update();
                }
            }
            else
            {
                if (string.IsNullOrEmpty(TextAfk.Text))
                {
                    MessageBox.Show("You need to enter an afk reason");
                }
                else
                {
                    if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                    {
                        RPC.Log.Error("App", $"No network connection available");
                        EnableElements();
                        App.WD.ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "No Network Connection");
                        return;
                    }
                    if (RPC.Config.Disabled.DiscordCheck && !FuncDiscord.CheckDiscordClient())
                    {
                        return;
                    }
                    RPC.AFK = true;

                    ViewLiveRPC.Content = new ViewRPC(ViewType.Loading);
                    BtnAfk.BorderBrush  = (Brush)Application.Current.Resources["Brush_Button"];
                    BtnAfk.Background   = (Brush)Application.Current.Resources["Brush_Button"];
                    BtnAfk.Foreground   = SystemColors.ControlBrush;
                    if (IsRPCOn())
                    {
                        RPC.Shutdown();
                    }
                    DisableElements();
                    BtnUpdatePresence.IsEnabled = false;
                    RPC.SetPresence(TextAfk.Text, "", "cat", "Sleepy cat zzzz", "", "");
                    TextAfk.Text = "";
                    if (ToggleAfkTime.IsChecked.Value)
                    {
                        RPC.Presence.Timestamps = new DiscordRPC.Timestamps(DateTime.UtcNow);
                    }
                    else
                    {
                        RPC.Presence.Timestamps = null;
                    }
                    RPC.Start(469643793851744257);
                }
            }
        }
예제 #2
0
        private void BtnToggleRPC_Click(object sender, RoutedEventArgs e)
        {
            if (!IsRPCOn())
            {
                if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
                {
                    RPC.Log.Error("App", $"No network connection available");
                    EnableElements();
                    App.WD.ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "No Network Connection");
                    return;
                }
                if (RPC.Config.Disabled.DiscordCheck && !FuncDiscord.CheckDiscordClient())
                {
                    return;
                }
                DisableElements();
                ulong ID = 0;
                if (RPC.Type == "default")
                {
                    ID = 450894077165043722;
                    RPC.CheckField(TextDefaultText1.Text);
                    RPC.CheckField(TextDefaultText2.Text);
                    string LKey = "";
                    string SKey = "";
                    if (ItemsDefaultLarge.SelectedIndex != -1)
                    {
                        LKey = (ItemsDefaultLarge.SelectedItem as ComboBoxItem).Content.ToString().ToLower();
                    }
                    if (ItemsDefaultSmall.SelectedIndex != -1)
                    {
                        SKey = (ItemsDefaultSmall.SelectedItem as ComboBoxItem).Content.ToString().ToLower();
                    }
                    RPC.SetPresence(TextDefaultText1.Text, TextDefaultText2.Text, LKey, TextDefaultLarge.Text, SKey, TextDefaultSmall.Text);
                    if (ToggleDefaultTime.IsChecked.Value)
                    {
                        RPC.Presence.Timestamps = new DiscordRPC.Timestamps(DateTime.UtcNow);
                    }
                }
                else if (RPC.Type == "custom")
                {
                    RPC.CheckField(TextCustomText1.Text);
                    RPC.CheckField(TextCustomText2.Text);
                    TextCustomClientID.Text = TextCustomClientID.Text.Replace(" ", "");
                    if (!ulong.TryParse(TextCustomClientID.Text, out ID))
                    {
                        EnableElements();
                        RPC.Log.Error("App", $"Client ID is invalid");
                        ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "Client ID is invalid");
                        return;
                    }
                    if (!ToggleTokenCheck.IsChecked.Value)
                    {
                        Dictionary <string, string> dict = new Dictionary <string, string>
                        {
                            { "client_id", ID.ToString() }
                        };
                        HttpResponseMessage T = null;
                        try
                        {
                            T = RPC.HttpClient.PostAsync("https://discordapp.com/api/oauth2/token/rpc", new FormUrlEncodedContent(dict)).GetAwaiter().GetResult();
                        }
                        catch
                        {
                            RPC.Log.Error("API", $"Cannot connect to Discord API");
                            ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "(API) Network issue");
                            EnableElements();
                            return;
                        }
                        if (T.StatusCode.ToString() != "InternalServerError")
                        {
                            RPC.Log.Error("API", $"Client ID is invalid");
                            ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "(API) Client ID is invalid");
                            EnableElements();
                            return;
                        }
                    }
                    RPC.SetPresence(this);
                    if (ToggleCustomTime.IsChecked.Value)
                    {
                        RPC.Presence.Timestamps = new DiscordRPC.Timestamps(DateTime.UtcNow);
                    }
                }
                if (ID == 0)
                {
                    EnableElements();
                    return;
                }
                ViewLiveRPC.Content = new ViewRPC(ViewType.Loading);

                try
                {
                    RPC.Start(ID);
                }
                catch (Exception ex)
                {
                    RPC.Log.Error("RPC", ex);
                    ViewLiveRPC.Content = new ViewRPC(ViewType.Error, "Could not start RPC");
                    try
                    {
                        RPC.Shutdown();
                    }
                    catch { }
                    EnableElements(true);
                }
            }
            else
            {
                RPC.AFK = false;
                RPC.Shutdown();
                ViewLiveRPC.Content = new ViewRPC(ViewType.Default);
                EnableElements();
            }
        }