Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (PhoneNumT.Text.Trim() != "")
            {
                botConfig = new BotConfigImpl(PhoneNumT.Text.Trim().Replace(" ", ""));
                ikc       = new KernelComm(APIKEY, ApiStatus);
                ikc.setLANGUAGE(Lang);
                ikc.setBotName(Device);
                ikc.setBotVersion(AppVer);
                ikc.setUrandomFileName(Application.StartupPath + "//000000");

                if (ConnectB.Text == "قطع اتصال")
                {
                    if (MessageBox.Show("سکشن شما باطل شود؟", "هشدار", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        try
                        {
                            TLRequestAuthLogOut logout = new TLRequestAuthLogOut();
                            Api.doRpcCall(logout);
                            File.Delete((PhoneNumT.Text + ".auth").Trim());
                            IsConnected          = false;
                            NotifyBar.Text       = "غیرفعال";
                            NotifyBar.ForeColor  = Color.Red;
                            ConnectB.BackColor   = Color.LightGray;
                            ConnectB.Text        = "اتصال";
                            MessageTB.Enabled    = false;
                            SendMessageB.Enabled = false;
                        }
                        catch (RpcException ex)
                        {
                            NotifyBar.Text = ex.getMessage();
                        }
                    }
                }
                else
                {
                    try
                    {
                        NewApi    = new TelegramNewApi(APIKEY, APIHASH, botConfig, ikc);
                        BotStatus = NewApi.GetStatus();

                        switch (BotStatus.toString())
                        {
                        case "ALREADYLOGGED":
                            IsConnected = true;
                            TLNearestDc dcInfo = (TLNearestDc)NewApi.Api().doRpcCallNonAuth(new TLRequestHelpGetNearestDc());
                            NewApi.Api().switchToDc(dcInfo.getNearestDc());
                            NewApi.Api().getState().setPrimaryDc(dcInfo.getNearestDc());
                            Api                  = NewApi.Api();
                            NotifyBar.Text       = "فعال " + "(" + PhoneNumT.Text + ")";
                            NotifyBar.ForeColor  = Color.Green;
                            ConnectB.BackColor   = Color.Red;
                            ConnectB.Text        = "قطع اتصال";
                            MessageTB.Enabled    = true;
                            SendMessageB.Enabled = true;
                            VerfyCodeB.Enabled   = false;
                            VerfyCodeT.Enabled   = false;
                            break;

                        case "CODESENT":
                            IsConnected         = false;
                            NotifyBar.Text      = "کد ارسال شد. منتظر تایید...";
                            NotifyBar.ForeColor = Color.LightGoldenrodYellow;
                            VerfyCodeT.Enabled  = true;
                            VerfyCodeB.Enabled  = true;
                            break;

                        default:
                            IsConnected = false;
                            //NotifyBar.Text = BotStatus.toString();
                            NotifyBar.Text      = "غیرفعال : " + BotStatus.toString();
                            NotifyBar.ForeColor = Color.Red;
                            break;
                        }

                        /*
                         * if (BotStatus == LoginStatus.ALREADYLOGGED)
                         * {
                         * }
                         *
                         * if (BotStatus == LoginStatus.CODESENT)
                         * {
                         * }
                         */
                    }
                    catch (RpcException ex)
                    {
                        IsConnected    = false;
                        NotifyBar.Text = ex.getMessage();
                        BotLogger.severe("MAIN", ex);
                        NotifyBar.Text      = "غیرفعال";
                        NotifyBar.ForeColor = Color.Red;
                    }
                }
            }
            else
            {
                NotifyBar.Text      = "شمارهمراه صحیح وارد نمایید.";
                NotifyBar.ForeColor = Color.Red;
            }
        }