Beispiel #1
0
 /// <summary>
 ///     Clean up the client that is given as parameter
 /// </summary>
 /// <param name="selfBot">Client to clean</param>
 private void ConnectionFailed(SelfBot selfBot)
 {
     selfBot.Dispose();
     connectButton.Text      = Resources.LoginForm_connectButton_Click_Connect;
     connectButton.TextAlign = ContentAlignment.MiddleCenter;
     connectButton.Enabled   = true;
 }
Beispiel #2
0
        /// <summary>
        ///     This method is called when the connect button is pressed, if the connection was successfull the application will
        ///     move itself to the background.
        /// </summary>
        /// <param name="sender">the object the called this method</param>
        /// <param name="e">event arguments</param>
        private void connectButton_Click(object sender, EventArgs e)
        {
            connectButton.Enabled = false;
            Update();
            var  selfBot       = new SelfBot(tokenBox.Text.Replace("\"", ""), this);
            var  discordClient = selfBot.Start();
            uint count         = 0;

            connectButton.TextAlign = ContentAlignment.MiddleLeft;
            do
            {
                connectButton.Text = Resources.LoginForm_connectButton_Click_Connecting_waitState1;
                Update();
                Thread.Sleep(333);
                connectButton.Text = Resources.LoginForm_connectButton_Click_Connecting_waitState2;
                Update();
                Thread.Sleep(333);
                connectButton.Text = Resources.LoginForm_connectButton_Click_Connecting_waitState3;
                Update();
                Thread.Sleep(334);
                count++;
            } while ((count < 5) || ((discordClient.ConnectionState == ConnectionState.Connecting) && (count < 15)));
            //only check connectionstate after 5 seconds for slower computers/networks

            if (discordClient.ConnectionState == ConnectionState.Connected)
            {
                Hide();
                notifyIcon.Visible = true;
                notifyIcon.ShowBalloonTip(500);
                //MessageBox.Show(Resources.LoginForm_loginOk, Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (_exceptionThrown)
            {
                ConnectionFailed(selfBot);
                _exceptionThrown = false;
            }
            else
            {
                ConnectionFailed(selfBot);
                MessageBox.Show(Resources.LoginForm_loginNotOk, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }