Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool success = NewApi.getKernelAuth().setAuthCode(VerfyCodeT.Text);

            if (success)
            {
                BotStatus = LoginStatus.ALREADYLOGGED;
            }

            if (BotStatus == LoginStatus.ALREADYLOGGED)
            {
                IsConnected = true;
                TLNearestDc dcInfo = (TLNearestDc)NewApi.Api().doRpcCallNonAuth(new TLRequestHelpGetNearestDc());
                NewApi.Api().switchToDc(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;
            }
            else
            {
                NotifyBar.Text      = "شکست در فعالسازی (" + BotStatus + ")";
                NotifyBar.ForeColor = Color.Red;
                IsConnected         = false;
                //throw new Exception("Failed to log in: " + BotStatus);
            }
        }
Esempio n. 2
0
        public async Task <MTObject> Handle(IMessageContext <TLGetNearestDc> context)
        {
            await Task.CompletedTask;
            var result = new TLNearestDc
            {
                NearestDc = 1,
                ThisDc    = 1,
                Country   = "IR"
            };

            return(result);
        }
Esempio n. 3
0
 public override void DeserializeResponse(BinaryReader br)
 {
     Response = (TLNearestDc)ObjectUtils.DeserializeObject(br);
 }
Esempio n. 4
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;
            }
        }