Пример #1
0
        private async Task RunAsync()
        {
            _api = await VkLogin.SimpleLoginAndGetApi(_app, _login, _pas, VkScope.Friends);

            var resolver = new Antigate(_antigate);
            var items    = new List <GroupFriendsFileLine>(File.ReadAllLines(_in).Select(_ => new GroupFriendsFileLine(_)));
            var current  = 0;

            foreach (var item in items.Where(_ => _.State == State.Wait))
            {
                try
                {
                    var res = await _api.Friends.Add(resolver, item.UserId, _message);

                    switch (res)
                    {
                    case VkAddFriendsResultEnum.SuccessRequest:
                        item.State = State.SuccessRequest;
                        current++;
                        break;

                    case VkAddFriendsResultEnum.SucessAdd:
                        item.State = State.SuccessAdd;
                        current++;
                        break;

                    case VkAddFriendsResultEnum.AlreadyRequest:
                        item.State = State.AlreadyExist;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                catch (Exception ex)
                {
                    Logger.ErrorException("add friend exception", ex);
                    item.Comment = ex.Message.Replace('\n', ' ').Replace('|', ' ');
                    item.State   = State.Error;
                }
                item.Comment += " Complete:" + DateTime.Now.ToLongDateString();
                if (current >= _count)
                {
                    break;
                }
            }


            if (File.Exists(_out))
            {
                File.Delete(_out);
            }
            using (var outFile = new StreamWriter(File.OpenWrite(_out)))
            {
                foreach (var item in items)
                {
                    outFile.WriteLine(item.Serialize());
                }
            }
        }
Пример #2
0
        private List<MediaDB> get(string GroupID, string MediaID, string token)
        {
            List<MediaDB> media = new List<MediaDB> { };
            XDocument xml = null;
            try
            {
                string captcha = "";
                Refresh: xml = XDocument.Load("https://api.vk.com/method/wall.getById.xml?posts=" + GroupID + "_" + MediaID + captcha + "&access_token=" + token);
                foreach (XElement el in xml.Root.Elements())
                {
                    if (el.Name.ToString() == "captcha_img")
                    {
                        Console.WriteLine("Разгадываем капчу в PhotoEdit.cs");
                        captcha = new Antigate().get(el.Value);
                        goto Refresh;
                    }
                    else if (el.Name.ToString() == "post")
                    {
                        foreach (XElement el_post in el.Elements())
                        {
                            if (el_post.Name == "attachments")
                            {
                                foreach (XElement el_attachments in el_post.Elements())
                                {
                                    foreach (XElement el_attachment in el_attachments.Elements())
                                    {
                                        if (el_attachment.Name == "photo")
                                        {
                                            MediaDB tmp = new MediaDB();
                                            foreach (XElement el_photo in el_attachment.Elements())
                                            {
                                                switch (el_photo.Name.ToString())
                                                {
                                                    case "pid": tmp.pid = el_photo.Value; break;
                                                    case "owner_id": tmp.owner_id = el_photo.Value; break;
                                                }
                                            }
                                            media.Add(tmp); tmp = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                captcha = null;
            }
            catch (Exception e)
            {
                if (e != null)
                    Console.WriteLine("Ошибка в PhotoEdit.cs, код ошибки: {1}{0}{1}{1}", e, Environment.NewLine);
            }

            //Воврат результата
            GroupID = null; MediaID = null; xml = null;
            return media;
        }
Пример #3
0
        private async Task RunAsync()
        {
            try
            {
                var api = await VkLogin.SimpleLoginAndGetApi(_app, _login, _pas, VkScope.Messages);

                var resolver = new Antigate(_antigate);

                await api.Messages.Send(resolver, _msg, int.Parse(_uid));
            }
            catch (Exception ex)
            {
                Logger.ErrorException("Error send message", ex);
            }
        }
Пример #4
0
        private MediaDB get(string video_id, string owner_id, string token)
        {
            MediaDB media = new MediaDB();
            XDocument xml = null;
            try
            {
                string captcha = "";
                Refresh: xml = XDocument.Load("https://api.vk.com/method/video.get.xml?owner_id=" + owner_id + "&videos=" + owner_id + "_" + video_id + "&access_token=" + token);
                foreach (XElement el in xml.Root.Elements())
                {
                    if (el.Name.ToString() == "captcha_img")
                    {
                        Console.WriteLine("Разгадываем капчу в VideoEdit.cs");
                        captcha = new Antigate().get(el.Value);
                        goto Refresh;
                    }
                    else if (el.Name.ToString().ToLower().Trim() == "video")
                    {
                        foreach (XElement el_video in el.Elements())
                        {
                            switch (el_video.Name.ToString().ToLower().Trim())
                            {
                                case "title": media.title = (el_video.Value.Trim() == "" ? null : el_video.Value); break;
                                case "description": media.description = (el_video.Value.Trim() == "" ? null : el_video.Value); break;
                            }
                        }

                        //Проверка на спам
                        if (media.title != null && new CheckSpam().get(media.title, null))
                        {
                            media.title = null;
                        }
                        if (media.description != null && new CheckSpam().get(media.description, null))
                        {
                            media.description = null;
                        }
                    }
                }
                captcha = null;
            }
            catch { }

            //Воврат результата
            owner_id = null; video_id = null; xml = null;
            return media;
        }
Пример #5
0
        public string post(string url, string data, string source_id, string post_id, string AccountID, string GroupID)
        {
            try
            {
                //Типа разделитель и данные для работы
                string captcha = "";
                Refresh: string captcha_img = null;
                HttpWebRequest request = null;
                Stream stream = null, StreamHTML = null;
                StreamReader Reader = null;
                WebClient wc = new WebClient();
                WebResponse response = null;
                string result = null;

                try
                {
                    //Создаем подключение с URL для загрузки картинок
                    request = (HttpWebRequest)WebRequest.Create(url);
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.Method = "POST";
                    request.KeepAlive = true;
                    request.MaximumAutomaticRedirections = 3;
                    request.ReadWriteTimeout = 1000 * 30;
                    request.Timeout = 1000 * 30;

                    //параметры
                    byte[] info = Encoding.UTF8.GetBytes(data + captcha);

                    //Записываем в поток все данные
                    stream = request.GetRequestStream();
                    stream.Write(info, 0, info.Length);
                    info = null;

                    //Возвращаем данные
                    response = request.GetResponse();
                    StreamHTML = response.GetResponseStream();
                    Reader = new StreamReader(StreamHTML);
                    result = Reader.ReadToEnd();
                    captcha_img = new Regex("captcha_img\":\"([^\"]+)\"").Match(result.Replace(" ", "").Replace(@"\", "").ToLower().Trim()).Groups[1].Value;
                }
                catch (Exception e)
                {
                    if ((source_id == null || post_id == null) && AccountID != null && GroupID != null)
                        Console.WriteLine("error: Ошибка во время запроса в PostAPI, ID аккаунта: {1}, группа: {2}", AccountID, GroupID);
                    else if (source_id != null && post_id != null && AccountID != null && GroupID != null)
                        Console.WriteLine("error: Ошибка во время публикации новости https://vk.com/wall{0}_{1} в PostAPI, ID аккаунта: {2}, группа: {3}", source_id, post_id, AccountID, GroupID);
                    else
                        Console.WriteLine("error: Ошибка во время запроса в PostAPI..");

                    if (e != null)
                        Console.WriteLine("Код ошибки: {1}{0}{1}{1}", e, Environment.NewLine);
                }
                finally
                {
                    //Чистим ресурсы
                    wc.Dispose(); wc = null;
                    if (Reader != null)
                    {
                        Reader.Close(); Reader.Dispose(); Reader = null;
                    }
                    if (StreamHTML != null)
                    {
                        StreamHTML.Close(); StreamHTML.Dispose(); StreamHTML = null;
                    }
                    if (response != null)
                    {
                        response.Close(); response.Dispose(); response = null;
                    }
                    if (stream != null)
                    {
                        stream.Close(); stream.Dispose(); stream = null;
                    }
                    if (request != null)
                    {
                        request.Abort(); request = null;
                    }
                }

                //Капча
                if (captcha_img != null && captcha_img.Replace(" ", "").Trim() != "")
                {
                    if (AccountID != null && GroupID != null)
                        Console.WriteLine("info: Разгадываем капчу в PostAPI.cs, ID аккаунта: {0}, группа {1}", AccountID, GroupID);
                    else
                        Console.WriteLine("info: Разгадываем капчу в PostAPI.cs..");
                    captcha = new Antigate().get(captcha_img);
                    captcha_img = null;
                    goto Refresh;
                }

                //Возвращаем результат
                url = null; data = null; source_id = null; post_id = null; AccountID = null; GroupID = null; captcha = null; captcha_img = null;
                return result.Trim() == "" ? null : result.Trim();
            }
            catch (Exception e)
            {
                if (e != null)
                    Console.WriteLine("Ошибка в PostAPI.cs, код ошибки: {1}{0}{1}{1}", e, Environment.NewLine);

                return (url = null);
            }
        }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            BrowserBot bb     = new BrowserBot(webBrowser1.Document);
            string     cookie = webBrowser1.Document.Cookie;

            HtmlElement el;

            el = bb.GetById("firstName");
            bb.SetValue(el, GetString());

            el = bb.GetById("lastName");
            bb.SetValue(el, GetString());

            _lastEmail = GetString() + "@asdasd.ru";
            el         = bb.GetById("email");
            bb.SetValue(el, _lastEmail);

            el = bb.GetById("city");
            bb.SetValue(el, GetString());

            _lastUser = GetString();
            el        = bb.GetById("username");
            bb.SetValue(el, _lastUser);

            _lastPwd = GetString() + "7";
            el       = bb.GetById("password");
            bb.SetValue(el, _lastPwd);

            el = bb.GetById("passwordConfirm");
            bb.SetValue(el, _lastPwd);

            HtmlElementCollection elc = webBrowser1.Document.GetElementsByTagName("img");

            foreach (HtmlElement item in elc)
            {
                string classAttr = new Regex(@"class=([^\s]*)").Match(item.OuterHtml).Groups[1].Value;
                if (classAttr == "oCaptchaImage")
                {
                    Uri           uri = new Uri(item.GetAttribute("src"));
                    DownloaderObj obj = new DownloaderObj(uri, null);
                    Downloader.DownloadSync(obj);
                    byte[] b = obj.Data;

                    Antigate.PostImage(b, ImgType.Jpg);
                }
            }



            #region GoogleAccounts

            /*
             * el = bb.FindById("GmailAddress");
             * bb.SetValue(el, Path.GetRandomFileName());
             *
             * string password = Path.GetRandomFileName();
             * el = bb.FindById("Passwd");
             * bb.SetValue(el, password);
             * el = bb.FindById("PasswdAgain");
             * bb.SetValue(el, password);
             *
             * el = bb.FindById("BirthDay");
             * int day = _rand.Next(1, 28);
             * bb.SetValue(el, day.ToString());
             *
             * el = bb.FindById("BirthMonth");
             * int month = _rand.Next(1, 13);
             * bb.SetComboBoxValue(el, month.ToString());
             *
             * el = bb.FindById("BirthYear");
             * int year = 1970 + _rand.Next(0, 30);
             * bb.SetValue(el, year.ToString());
             *
             * el = bb.FindById("Gender");
             * int gender = _rand.Next(0, 3);
             * string genderVal = string.Empty;
             * if (gender == 0)
             *  genderVal = "FEMALE";
             * else if (gender == 1)
             *          genderVal = "MALE";
             *  else if (gender == 2)
             *          genderVal = "OTHER";
             * bb.SetValue(el, genderVal);
             *
             * el = bb.FindById("CountryCode");
             * Regex country = new Regex("<OPTION value=(?<country>[^>]*)>");
             * MatchCollection contries = country.Matches(el.OuterHtml);
             * int i = _rand.Next(0, contries.Count);
             * bb.SetValue(el, contries[i].Groups["country"].Value);
             *
             * el = bb.FindById("HomepageSet");
             * el.OuterHtml = el.OuterHtml.Replace("CHECKED", "UNCHECKED");
             *
             * //el = bb.FindById("recaptcha_response_field");
             * //string capcha = "";
             * //bb.SetValue(el, capcha);
             *
             * el = bb.FindById("TermsOfService");
             * bb.SetCheckRadioBox(el, true);
             *
             * el = bb.FindById("submitbutton");
             * bb.Click(el);
             */
            #endregion
        }
Пример #7
0
        public List<InfoClass.news> get(InfoClass.account account, InfoClass.GroupList GroupList)
        {
            List<string> TempTag = new List<string> { };
            List<InfoClass.news> News = new List<InfoClass.news> { };

            try
            {
                string captcha = "";
                //XElement.Parse();
                Refresh: XDocument xml = XDocument.Load("https://api.vk.com/method/wall.get.xml?owner_id=" + GroupList.GroupID + captcha + "&count=10&filter=owner&access_token=" + account.token);
                foreach (XElement el in xml.Root.Elements())
                {
                    if (el.Name.ToString().ToLower() == "error_msg" && el.Value.ToLower().Replace(" ", "") == "userauthorizationfailed:invalidaccess_token.")
                    {
                        Console.WriteLine("error: XML news.cs вернул ошибку: {0}, UserID: {1}, ID: {2}, группа: {3}", el.Value, account.UserID, account.id, GroupList.GroupID);
                        break;
                    }
                    else if (el.Name.ToString().ToLower() == "captcha_img")
                    {
                        Console.WriteLine("info: Разгадываем капчу в news.cs, ID аккаунта: {0}, группа: {1}", account.UserID, GroupList.GroupID);
                        captcha = new Antigate().get(el.Value);
                        goto Refresh;
                    }
                    else if (el.Name.ToString().ToLower() == "post")
                    {
                        InfoClass.news tmp = new InfoClass.news();
                        foreach (XElement el_post in el.Elements())
                        {
                            if (el_post.Name.ToString().ToLower() == "from_id" || el_post.Name.ToString().ToLower() == "to_id")
                            {
                                if (int.Parse(el_post.Value) >= 0)
                                {
                                    tmp = null;
                                    break; //Переходим в следующий item
                                }
                                else
                                    tmp.source_id = el_post.Value;
                            }
                            if (el_post.Name.ToString().ToLower() == "post_id" || el_post.Name.ToString().ToLower() == "id")
                            {
                                tmp.post_id = el_post.Value;
                            }
                            else if (el_post.Name.ToString().ToLower() == "date")
                            {
                                tmp.Date = int.Parse(el_post.Value);
                                if (GroupList.LastTime > tmp.Date)
                                {
                                    tmp = null;
                                    break;  //Переходим в следующий item
                                }
                            }
                            else if (el_post.Name.ToString().ToLower() == "post_type" && el_post.Value.ToString().ToLower() != "post")
                            {
                                tmp = null;
                                break; //Переходим в следующий item
                            }
                            else if (el_post.Name.ToString().ToLower() == "message" || el_post.Name.ToString().ToLower() == "text")
                            {
                                //Проверяем текст
                                if (el_post.Value.Trim() != "")
                                    if (!new CheckSpam().get(el_post.Value, account.StopWords))
                                    {
                                        TempTag.Add(tmp.Text = el_post.Value.Replace("<br>", "\n").Replace("\r", "").Replace("&amp;", ""));
                                    }
                                    else
                                    {
                                        tmp = null;
                                        break; //Переходим в следующий item
                                    }
                            }
                            else if (el_post.Name.ToString().ToLower() == "attachments")
                            {
                                foreach (XElement el_attachments in el_post.Elements())
                                {
                                    InfoClass.Image img = new InfoClass.Image();
                                    foreach (XElement el_attachment in el_attachments.Elements())
                                    {
                                        if (el_attachment.Name.ToString().ToLower() == "photo")
                                        {
                                            foreach (XElement el_photo in el_attachment.Elements())
                                            {
                                                switch (el_photo.Name.ToString().ToLower())
                                                {
                                                    case "pid": img.pid = el_photo.Value; break;
                                                    case "owner_id": img.owner_id = el_photo.Value; break;
                                                    case "src": img.src = el_photo.Value; break;
                                                    case "src_big": img.src_big = el_photo.Value; break;
                                                    case "src_small": img.src_small = el_photo.Value; break;
                                                    case "src_xbig": img.src_xbig = el_photo.Value; break;
                                                    case "src_xxbig": img.src_xxbig = el_photo.Value; break;
                                                    case "text": TempTag.Add(img.text = el_photo.Value); break;
                                                }
                                            }
                                        }
                                        else if (el_attachment.Name.ToString().ToLower() == "poll")
                                        {
                                            foreach (XElement el_poll in el_attachment.Elements())
                                            {
                                                if (el_poll.Name.ToString().ToLower() == "poll_id" && tmp.source_id != null)
                                                {
                                                    tmp.Poll = "poll" + tmp.source_id + "_" + el_poll.Value + ",";
                                                }
                                            }
                                        }
                                        else if (el_attachment.Name.ToString().ToLower() == "video")
                                        {
                                            InfoClass.Video video = new InfoClass.Video();
                                            foreach (XElement el_video in el_attachment.Elements())
                                                switch (el_video.Name.ToString().ToLower())
                                                {
                                                    case "vid": video.media_id = el_video.Value; break;
                                                    case "owner_id": video.owner_id = el_video.Value; break;
                                                    case "image": video.img = el_video.Value; break;
                                                    case "description": TempTag.Add(el_video.Value); break;
                                                }

                                            //Добовляем видео
                                            if (video.img != null && video.media_id != null && video.owner_id != null)
                                            {
                                                tmp.Video.Add(new InfoClass.Video
                                                {
                                                    img = video.img,
                                                    media_id = video.media_id,
                                                    owner_id = video.owner_id
                                                });
                                            }
                                            video = null;
                                        }
                                        else if (el_attachment.Name.ToString().ToLower() == "audio")
                                        {
                                            string owner_id = null, media_id = null;
                                            foreach (XElement el_audio in el_attachment.Elements())
                                                switch (el_audio.Name.ToString().ToLower())
                                                {
                                                    case "aid": media_id = el_audio.Value; break;
                                                    case "owner_id": owner_id = el_audio.Value; break;
                                                }

                                            if (owner_id != null && media_id != null)
                                                tmp.Audio = (tmp.Audio == null ? "" : tmp.Audio) + "audio" + owner_id + "_" + media_id + ",";
                                            owner_id = null; media_id = null;
                                        }
                                        else if (el_attachment.Name.ToString().ToLower() != "type")
                                        {
                                            img = null; goto Break; //Бракуем новость если в ней есть неизвестная хрень
                                        }
                                    }
                                    tmp.img.Add(img);
                                    img = null;
                                }
                            }
                        }
                        if (tmp != null)
                            News.Add(tmp);
                    Break: tmp = null;
                    }
                }
                new ParserTAG().get(TempTag, account);
                TempTag = null; captcha = null; xml = null;
            }
            catch (FileNotFoundException) { }
            catch (Exception e)
            {
                Console.WriteLine("error: Ошибка получения новостей, UsreID: {0}, ID: {1}, группа: {2}", account.UserID, account.id, GroupList.GroupID);
                if (e != null)
                    Console.WriteLine("Код ошибки: {1}{0}{1}{1}", e, Environment.NewLine);
            }
            catch { }

            //Записываем LastTime
            string dir = conf.DirLastTime + account.id;
            if (News.Count != 0 && File.Exists(dir))
            {
                string s = File.ReadAllText(dir).Replace(" ", "");
                GroupList.LastTime = (News[0] as InfoClass.news).Date + 1;
                if (new Regex(GroupList.GroupID + ":[0-9]+").Match(s).Success)
                    File.WriteAllText(dir, Regex.Replace(s, (GroupList.GroupID + ":[0-9]+"), string.Format("{0}:{1}", GroupList.GroupID, GroupList.LastTime)));
                else
                    File.AppendAllText(dir, string.Format("{0}:{1}{2}", GroupList.GroupID, GroupList.LastTime, Environment.NewLine)); //Дописываем новые данные
                s = null;
            }
            else if (News.Count != 0 && !File.Exists(dir))
            {
                //Создаем новый файл и пишем в него данные
                Directory.CreateDirectory(conf.DirLastTime);
                GroupList.LastTime = (News[0] as InfoClass.news).Date + 1;
                File.WriteAllText(dir, string.Format("{0}:{1}", GroupList.GroupID, GroupList.LastTime) + Environment.NewLine);
            }

            //Чистим ресурсы
            account = null; GroupList = null; dir = null;
            return News;
        }