Example #1
0
        private async void messageEditBody_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter && !Keyboard.IsKeyDown(Key.LeftShift))
            {
                string toSend = await DiscordWindow.ProcessMessageText(messageEditBody.Text, Message.Channel);

                e.Handled = true;
                if (toSend.Length < 2000)
                {
                    await Message.ModifyAsync(new Action <MessageProperties>((p) => p.Content = toSend));

                    App.DiscordWindow.StatusShowSuccess("Message edited!");
                    messageBody.Visibility     = Visibility.Visible;
                    messageEditBody.Visibility = Visibility.Collapsed;
                    App.DiscordWindow.messageTextBox.Focus();
                }
                else
                {
                    App.DiscordWindow.StatusShowError("Your message is too long! Make sure its less than 2000 characters!", false);
                }
            }
            else if (e.Key == Key.Escape)
            {
                e.Handled = true;
                messageBody.Visibility     = Visibility.Visible;
                messageEditBody.Visibility = Visibility.Collapsed;
                messageEditBody.Text       = Message.Content;
                App.DiscordWindow.messageTextBox.Focus();
            }
        }
Example #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;

            System.Windows.Forms.Application.EnableVisualStyles();
            SetBrowserEmulationMode();

            if (File.Exists(Path.Combine(CurrentDirectory, "Config.json"))) // Checks for configuration file
            {
                try
                {
                    // Loads configuration
                    Config = JsonConvert.DeserializeObject <Config>(
                        File.ReadAllText(Path.Combine(CurrentDirectory, "Config.json")));
                }
                catch
                {
                    // Creates new configuration
                    Config.Save();
                }
            }
            else
            {
                try
                {
                    // Creates new configuration
                    File.WriteAllText(Path.Combine(CurrentDirectory, "Config.json"),
                                      JsonConvert.SerializeObject(Config, Formatting.Indented));
                }
                catch
                {
                    // Relaunches app as administrator
                    // Helps if app is installed to Program Files and it can't access config.json
                    TaskDialog dialog = new TaskDialog();
                    dialog.WindowTitle             = "Unable to write config file";
                    dialog.MainInstruction         = "Unable to write configuration file!";
                    dialog.Content                 = "Sorry! I was unable to write my configuration file! I may be in a protected directory, do you want to try relaunch as an administrator and try again?";
                    dialog.MainIcon                = TaskDialogIcon.Error;
                    dialog.AllowDialogCancellation = true;
                    dialog.ButtonStyle             = TaskDialogButtonStyle.CommandLinks;
                    TaskDialogButton relaunchAsAdmin = new TaskDialogButton("Relaunch as administrator\nLets hope this works!\0");
                    relaunchAsAdmin.ElevationRequired = true;
                    dialog.Buttons.Add(relaunchAsAdmin);
                    dialog.Buttons.Add(new TaskDialogButton(ButtonType.Cancel));

                    if (dialog.Show() == relaunchAsAdmin)
                    {
                        ProcessStartInfo info = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location);
                        info.UseShellExecute = true;
                        info.Verb            = "runas";
                        info.Arguments       = "firstrun";
                        Process.Start(info);
                        Environment.Exit(0);
                    }
                    else
                    {
                        Environment.Exit(0);
                    }
                }
            }

            SelectedTheme = Config.Personalisation.SelectedTheme;

            ChangeTheme();

            Config.Save();

            if (!String.IsNullOrEmpty(App.Config.Token))
            {
                DiscordWindow window = new DiscordWindow(App.Config.Token);
                MainWindow = window;
                window.Show();
            }
            else
            {
                LoginWindow window = new LoginWindow();
                MainWindow = window;
                window.Show();
            }
        }
Example #3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            if (token.Visibility == Visibility.Visible)
            {
                DiscordWindow window = new DiscordWindow(tokenBox.Password.Trim('"'));
                if (botToken.IsChecked == true)
                {
                    window.type = Discord.TokenType.Bot;
                }
                window.Show();
                App.Current.MainWindow = window;
                if (rememberMe.IsChecked == true)
                {
                    App.Config.Token = tokenBox.Password.Trim('"');
                    App.Config.Save();
                }

                Close();
            }
            else
            {
                usernameBox.BorderBrush = App.SecondaryForegroundBrush;
                passwordBox.BorderBrush = App.SecondaryForegroundBrush;
                errorText.Visibility    = Visibility.Collapsed;


                errorText.Text = "";
                if (string.IsNullOrEmpty(usernameBox.Text))
                {
                    usernameBox.BorderBrush = new SolidColorBrush(App.ErrorColour);
                    errorText.Text         += "Enter an email address dipshit.\r\n";
                }
                else if (!Tools.IsValidEmail(usernameBox.Text))
                {
                    usernameBox.BorderBrush = new SolidColorBrush(App.ErrorColour);
                    errorText.Text         += "Sorry! That email address doesn't seem right.\r\n";
                }
                if (string.IsNullOrEmpty(passwordBox.Password))
                {
                    passwordBox.BorderBrush = new SolidColorBrush(App.ErrorColour);
                    errorText.Text         += "Enter a password you retard.\r\n";
                }

                if (string.IsNullOrEmpty(errorText.Text))
                {
                    bool   did2fa = false;
                    string token  = null;
                    using (HttpClient client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.32 Chrome/53.0.2785.143 Discord PTB/1.4.12 Safari/537.36");

                        string initialRequest = JsonConvert.SerializeObject(new LoginRequest()
                        {
                            EmailAddress = usernameBox.Text,
                            Password     = passwordBox.Password
                        });
                        StringContent       cont            = new StringContent(initialRequest, Encoding.UTF8, "application/json");
                        HttpResponseMessage initialResponse = await client.PostAsync("https://discordapp.com/api/v6/auth/login", cont);

                        string txtCont = await initialResponse.Content.ReadAsStringAsync();

                        try
                        {
                            initialResponse.EnsureSuccessStatusCode();
                            LoginResponse response = JsonConvert.DeserializeObject <LoginResponse>(txtCont);
                            if (response.TwoFactor)
                            {
                                did2fa = true;
                                Dialogs.TwoFactorAuthDialog dialog = new Dialogs.TwoFactorAuthDialog();
                                if (dialog.ShowDialog() == true)
                                {
                                    string twoFAString = dialog.Code;
                                    if (Int32.TryParse(twoFAString, out int dontneedthislol) || (twoFAString.Length == 9 && twoFAString[4] == '-'))
                                    {
                                        string twoFARequest = JsonConvert.SerializeObject(new Login2FARequest()
                                        {
                                            Code   = twoFAString,
                                            Ticket = response.Ticket
                                        });
                                        cont = new StringContent(twoFARequest, Encoding.UTF8, "application/json");

                                        HttpResponseMessage twoFAResponse = await client.PostAsync("https://discordapp.com/api/v6/auth/mfa/totp", cont);

                                        response = JsonConvert.DeserializeObject <LoginResponse>(await twoFAResponse.Content.ReadAsStringAsync());

                                        token = response.Token;
                                    }
                                }
                            }
                            else
                            {
                                token = response.Token;
                            }
                        }
                        catch
                        {
                            try
                            {
                                LoginResponseError errorResponse = JsonConvert.DeserializeObject <LoginResponseError>(txtCont);
                                if (errorResponse.EmailAddressErrors != null)
                                {
                                    usernameBox.BorderBrush = new SolidColorBrush(App.ErrorColour);
                                    errorText.Text         += string.Join("\r\n", errorResponse.EmailAddressErrors);
                                }
                            }
                            catch { }
                        }
                    }
                    if (token != null)
                    {
                        DiscordWindow window = new DiscordWindow(token);
                        if (botToken.IsChecked == true)
                        {
                            window.type = Discord.TokenType.Bot;
                        }
                        window.Show();
                        App.Current.MainWindow = window;

                        if (rememberMe.IsChecked == true)
                        {
                            App.Config.Token = token;
                            App.Config.Save();
                        }

                        Close();
                    }
                    else if (string.IsNullOrWhiteSpace(errorText.Text))
                    {
                        TaskDialog errorDialog = new TaskDialog();
                        errorDialog.MainIcon    = TaskDialogIcon.Error;
                        errorDialog.WindowTitle = "Unable to login.";
                        if (did2fa)
                        {
                            errorDialog.Content = $"An error occured while attempting to login! It's more than likely that your two factor auth code was incorrect. Please try again.";
                        }
                        else
                        {
                            errorDialog.Content = $"An error occured while attempting to login! It's more than likely that your email address/password are incorrect. Please try again.";
                        }
                        errorDialog.Buttons.Add(new TaskDialogButton(ButtonType.Ok));
                        errorDialog.Show();
                    }
                    else
                    {
                        errorText.Visibility = Visibility.Visible;
                    }
                }
                else
                {
                    errorText.Visibility = Visibility.Visible;
                }
            }
            IsEnabled = true;
        }