Пример #1
0
 private void Pusia_Load(object sender, EventArgs e)
 {
     string         request    = "https://api.vk.com/method/messages.getConversations?filter=unread&access_token=" + access_token + "&v=5.87";
     WebClient      stepagavno = new WebClient();
     string         papeimachi = Encoding.UTF8.GetString(stepagavno.DownloadData(request));
     UnreadMessages msg        = JsonConvert.DeserializeObject <UnreadMessages>(papeimachi);
     //foreach(UnreadMessages.Item itm in msg.response.items )
     // {
     //  listBox1.Items.Add(itm.last_message.text);
     //string request2 = "https://api.vk.com/method/messages.send?user_id="+ itm.last_message.from_id+"&message=О-ОтЛичНо&access_token=" + access_token + "&v=5.87";
     //WebClient cl = new WebClient();
     //string mess = Encoding.UTF8.GetString(cl.DownloadData(request2));
     //}
 }
Пример #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer1.Enabled = false;
            string         request    = "https://api.vk.com/method/messages.getConversations?filter=unread&access_token=" + access_token + "&v=5.87";
            WebClient      stepagavno = new WebClient();
            string         papeimachi = Encoding.UTF8.GetString(stepagavno.DownloadData(request));
            UnreadMessages msg        = JsonConvert.DeserializeObject <UnreadMessages>(papeimachi);

            foreach (UnreadMessages.Item itm in msg.response.items)
            {
                try
                {
                    if (itm.last_message.text.ToLower().Contains(textBox1.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox3.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox2.Text.ToLower()))
                    {
                        Random    ccc      = new Random();
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + answer2[ccc.Next(8)] + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox5.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox6.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox7.Text.ToLower()))
                    {
                        Random aaa = new Random();


                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + answer[aaa.Next(6)] + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox9.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox10.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox11.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox12.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }

                    listBox1.Items.Add(itm.last_message.text);
                    //string request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=О-ОтЛичНо&access_token=" + access_token + "&v=5.87";
                    //WebClient cl = new WebClient();
                    //string mess = Encoding.UTF8.GetString(cl.DownloadData(request2));
                    //timer1.Enabled = true;
                }
                catch (Exception)
                {
                    ErrorLabel.Text = "Возникла ошибка!";
                }
            }
        }
Пример #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox25.Text = "Оставь открытым это окно, и бот будет отвечать всем, кто пишет тебе, автоматом. Как только ты закроешь окно, бот перестанет отвечать." +
                             " Ты можешь изменить окна с ответами или оставить их по умолчанию.";
            listBox1.Items.Clear();
            //timer1.Enabled = false;
            string         request    = "https://api.vk.com/method/messages.getConversations?filter=unread&access_token=" + access_token + "&v=5.87";
            WebClient      stepagavno = new WebClient();
            string         papeimachi = Encoding.UTF8.GetString(stepagavno.DownloadData(request));
            UnreadMessages msg        = JsonConvert.DeserializeObject <UnreadMessages>(papeimachi);

            foreach (UnreadMessages.Item itm in msg.response.items)
            {
                try
                {
                    if (itm.last_message.text.ToLower().Contains(textBox1.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox3.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox2.Text.ToLower()))
                    {
                        Random    ccc      = new Random();
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + answer2[ccc.Next(8)] + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox5.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox6.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox7.Text.ToLower()))
                    {
                        Random aaa = new Random();


                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + answer[aaa.Next(6)] + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox9.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox10.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }
                    if (itm.last_message.text.ToLower().Contains(textBox11.Text.ToLower()))
                    {
                        string    request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=" + textBox12.Text + "&access_token=" + access_token + "&v=5.87";
                        WebClient cl       = new WebClient();
                        string    mess     = Encoding.UTF8.GetString(cl.DownloadData(request2));
                        if (mess.Contains("error"))
                        {
                            throw new Exception();
                        }
                    }

                    listBox1.Items.Add(itm.last_message.text);
                    //string request2 = "https://api.vk.com/method/messages.send?user_id=" + itm.last_message.from_id + "&message=О-ОтЛичНо&access_token=" + access_token + "&v=5.87";
                    //WebClient cl = new WebClient();
                    //string mess = Encoding.UTF8.GetString(cl.DownloadData(request2));
                    //timer1.Enabled = true;
                }
                catch (Exception)
                {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text    = "Возникла ошибка!";
                }
            }
        }