示例#1
0
 private void BTNStopBot_Click(object sender, EventArgs e)
 {
     BTNStartBot.Enabled  = true;
     BTNStopBot.Enabled   = false;
     MenuStartBot.Enabled = true;
     MenuStopBot.Enabled  = false;
     Bot.StopReceiving();
     TXTLog.AppendText($"[{DateTime.Now}]: Stopped bot.\n");
 }
示例#2
0
        private void BTNStartBot_Click(object sender, EventArgs e)
        {
            //Validate inputs
            if (TXTToken.Empty() || TXTPCName.Empty() || TXTHashedPassword.Empty())
            {
                MessageBox.Show("Please fill all required fields.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //At first save the settings
            Properties.Settings.Default.Token     = TXTToken.Text;
            Properties.Settings.Default.PCName    = PCName = TXTPCName.Text;
            Properties.Settings.Default.Password  = Password = TXTHashedPassword.Text.ToLower();
            Properties.Settings.Default.ProxyIP   = TXTProxyIP.Text;
            Properties.Settings.Default.ProxyUser = TXTProxyUsername.Text;
            Properties.Settings.Default.ProxyPass = TXTProxyPassword.Text;
            Properties.Settings.Default.Save();
            if (!TXTProxyPort.Empty())
            {
                try
                {
                    Properties.Settings.Default.ProxyPort = TXTProxyPort.Text;
                    Properties.Settings.Default.Save();
                }
                catch (Exception)
                {
                    MessageBox.Show("Error parsing your proxy port.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            SaveToJson();
            //Check proxy
            if (TXTProxyIP.Empty() && TXTProxyPort.Empty())
            {
                Bot = new TelegramBotClient(TXTToken.Text);
            }
            else if (TXTProxyUsername.Empty() && TXTProxyPassword.Empty())
            {
                Bot = new TelegramBotClient(TXTToken.Text, new WebProxy(TXTProxyIP.Text, Convert.ToInt32(TXTProxyPort.Text)));
            }
            else
            {
                ICredentials credentials = new NetworkCredential(TXTProxyUsername.Text, TXTProxyPassword.Text);
                WebProxy     proxy       = new WebProxy(TXTProxyIP.Text + ":" + TXTProxyPort.Text, true, null, credentials);
                Bot = new TelegramBotClient(TXTToken.Text, proxy);
            }
            BTNStartBot.Enabled  = false;
            BTNStopBot.Enabled   = true;
            MenuStartBot.Enabled = false;
            MenuStopBot.Enabled  = true;
            var me = Bot.GetMeAsync().Result;

            Bot.OnMessage += BotOnMessageReceived;
            Bot.StartReceiving(new UpdateType[0]);
            TXTLog.AppendText($"[{DateTime.Now}]: Starting @{me.Username} bot.\n");
        }
示例#3
0
        private async void BotOnMessageReceived(object sender, MessageEventArgs e)
        {
            Telegram.Bot.Types.Message message = e.Message;
            if (message == null || message.Type != MessageType.Text)
            {
                return;
            }
            string[] msg = message.Text.Split(' ');
            if (msg.Length != 2)
            {
                return;
            }
            string ToSend = "null";

            if (msg[0] == PCName && Helper.SHA256(msg[1]) == Password)
            {
                await Bot.SendTextMessageAsync(message.Chat.Id, "Receiving IP...");

                try
                {
                    WebRequest request = WebRequest.Create("http://api.ipify.org/");
                    //We bypass any proxy if it's configured in system
                    request.Proxy = null;
                    WebResponse      response = request.GetResponse();
                    System.IO.Stream data     = response.GetResponseStream();
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(data))
                    {
                        ToSend = sr.ReadToEnd();
                    }
                    if (LogSends)
                    {
                        TXTLog.Invoke(new Action(() => TXTLog.AppendText($"[{DateTime.Now}]: Send IP for @{message.From.Username}, UserID:{message.From.Id}, Name: {message.From.FirstName} {message.From.LastName}\n")));
                    }
                }
                catch (Exception ex)
                {
                    ToSend = ex.ToString();
                    TXTLog.Invoke(new Action(() => TXTLog.AppendText($"[{DateTime.Now}]: Error Getting IP: {ToSend}\n", Color.Red)));
                }
                await Bot.SendTextMessageAsync(message.Chat.Id, ToSend);
            }
            else if (msg[0] == PCName && LogFails)
            {
                TXTLog.Invoke(new Action(() => TXTLog.AppendText($"[{DateTime.Now}]: Failed login attempt from @{message.From.Username}, UserID:{message.From.Id}, Name: {message.From.FirstName} {message.From.LastName}, Entered password: {msg[1]}  for {msg[0]} computer.\n", Color.Red)));
            }
        }