Exemple #1
0
 private void PrepareChatsPics()
 {
     Log.Push($"[Поток {login}]: Загрузка на сервер аватаров бесед");
     Directory.GetFiles("Images");
     foreach (ChatsTarget current in chTargets)
     {
         string text = "Images\\" + current.setPhoto;
         if (text != null && !(text == "Ничего") && !(text == "Удалять"))
         {
             string str;
             if (Path.GetExtension(text) == ".png")
             {
                 str = "png";
             }
             else
             {
                 if (!(Path.GetExtension(text) == ".jpg") && !(Path.GetExtension(text) == ".jpeg"))
                 {
                     continue;
                 }
                 str = "jpeg";
             }
             string text2 = StrWrk.GetBetween(VKserver.APIRequest("photos.getChatUploadServer", "chat_id=" + current.chatID, token, ""), "\"upload_url\":\"", "\"");
             text2 = Network.HttpUploadFile(text2.Replace("\\/", "/"), text, "photo", "image/" + str);
             text2 = StrWrk.GetBetween(text2, "\"response\":\"", "\"");
             current.uploadedPhoto = text2;
         }
     }
 }
Exemple #2
0
        public void AsyncWorker()
        {
            id = VKserver.APIRequest("users.get", "", token, "");
            id = StrWrk.GetBetween(id, "\"id\":", ",");

            if (enabledAsAA)
            {
                new Task(() => WorkUntilStopAsAA()).Start();
            }

            if (enabledAsFL)
            {
                new Task(() => WorkUntilStopAsFLText()).Start();

                new Task(() => WorkUntilStopAsFLPic()).Start();
            }

            if (enabledAsCH)
            {
                PrepareChatsPics();
                new Task(() => WorkUntilStopAsCH()).Start();
            }

            if (enabledAsGE)
            {
                new Task(() => WorkUntilStopAsGE()).Start();
            }
        }
Exemple #3
0
        private void ProcGenerator()
        {
            string text = generatorTarget;

            if (text == "" || MainForm.generatorMessages.Length == 0)
            {
                Log.Push($"[{login}]: Генерация сообщений...");
                text = StrWrk.qSubstr(text, "im?sel=c", false);
                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                string        input = StrWrk.GetBetween(VKserver.APIRequest("messages.getChat", "chat_id=" + text, token, ""), "\"users\":", "]") + "]";
                List <string> list  = javaScriptSerializer.Deserialize <List <string> >(input);
                list.Remove(id);

                if (list.Count == 0)
                {
                    Log.Push("[" + login + "]: В чате нет людей");
                }
                else
                {
                    Random random = new Random();
                    string text2  = list[random.Next(0, list.Count)];
                    string text3  = VKserver.APIRequest("users.get", "user_ids=" + text2, token, "");
                    text3 = StrWrk.GetBetween(text3, "\"first_name\":\"", "\",");
                    string str = string.Format("*id{0} ({1})", text2, text3) + " - " + MainForm.generatorMessages[random.Next(0, MainForm.generatorMessages.Length)];
                    VKserver.APIRequest("messages.send", "chat_id=" + text + "&message=" + str, token, "");
                }
            }
        }
Exemple #4
0
        public void SendVoiceMessage(string dist, string message, string voice, string emotion, string speed)
        {
            Log.Push($"[Поток {login}]: Отправка голосового сообщения в " + dist);
            new WebClient().DownloadFile(string.Format("https://tts.voicetech.yandex.net/generate?text={0}&format=mp3&lang=ru-RU&speaker={1}&emotion={2}&speed={3}&key=9ae121de-59ba-4145-a0cb-bdbdec107297", new object[]
            {
                message,
                voice,
                emotion,
                speed
            }), "temp.mp3");
            string str  = Network.HttpUploadFile(StrWrk.GetBetween(VKserver.APIRequest("docs.getUploadServer", "type=audio_message", token, ""), "\"upload_url\":\"", "\"}").Replace("\\/", "/"), "temp.mp3", "file", "audio/MP3");
            string text = VKserver.APIRequest("docs.save", "file=" + StrWrk.GetBetween(str, "\"file\":\"", "\"}"), token, "");
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();

            text = StrWrk.GetBetween(text, "\"resplonse\":\"[", "]}");
            UploadResult uploadResult = javaScriptSerializer.Deserialize <UploadResult>(text);

            if (dist.StartsWith("im?sel=c"))
            {
                string arg = StrWrk.qSubstr(dist, "im?sel=c", false);
                VKserver.APIRequest("messages.send", string.Format("chat_id={0}&attachment=doc{1}_{2}", arg, uploadResult.owner_id, uploadResult.id), token, "");
            }
            else
            {
                if (dist.StartsWith("im?sel="))
                {
                    string arg2 = StrWrk.qSubstr(dist, "im?sel=", false);
                    VKserver.APIRequest("messages.send", string.Format("user_id={0}&attachment=doc{1}_{2}", arg2, uploadResult.owner_id, uploadResult.id), token, "");
                }
                else
                {
                    Log.Push(string.Concat(new string[]
                    {
                        "[Поток ",
                        login,
                        "]: ",
                        dist,
                        " - неверный формат"
                    }));
                }
            }
        }
Exemple #5
0
        public int GetToken()
        {
            int num;
            int result;

            if (CheckToken() == 0)
            {
                num = 0;
            }
            else
            {
                CookieContainer cc   = new CookieContainer();
                string          text = Network.GET("https://vk.com/", cc);
                text = StrWrk.GetBetween(text, "action=\"", "\"");
                string url = text;
                text = Network.POST(url, "email=" + login + "&pass="******"_logout"))
                {
                    if (!text.Contains("captcha_img"))
                    {
                        result = -1;
                        return(result);
                    }
                    Log.Push("Капча при получении токена " + login + ", переключитесь на ручной ввод капчи");
                    string text2 = StrWrk.qSubstr(text, "captcha.php", false);
                    text2 = StrWrk.GetBetween(text2, "sid=", "\"");
                    string arg = VkCaptchaWorks.SolveManual("https://m.vk.com/captcha.php?s=0&sid=" + text2, text2);
                    text = Network.POST(url, string.Concat(new string[]
                    {
                        "email=",
                        login,
                        "&pass="******"&captcha_sid={0}&captcha_key={1}", text2, arg)
                    }), cc);

                    if (!text.Contains("_logout"))
                    {
                        result = -1;
                        return(result);
                    }
                }
                string text3;
                text = Network.GET("https://oauth.vk.com/authorize?client_id=2685278&scope=1073737727&redirect_uri=https://api.vk.com/blank.html&display=page&response_type=token&revoke=1')", out text3, cc);                 //Вставить ссылку авторизации

                if (text3 == null)
                {
                    text = StrWrk.GetBetween(text, "form method=\"post\" action=\"", "\"");
                }
                else
                {
                    text = text3;
                }
                Network.GET(text, out text3, cc);

                if (!text3.Contains("access_token="))
                {
                    Log.Push($"[{login}]: Ошибка авторизации, включена двуфакторная авторизация?");
                    num = -1;
                }
                else
                {
                    token        = StrWrk.GetBetween(text3, "access_token=", "&");
                    token_status = true;
                    num          = 0;
                }
            }
            result = num;
            return(result);
        }
Exemple #6
0
        public static string APIRequest(string method, string param, string token, string captcha_data = "")
        {
            if (captcha_data == "")
            {
                param = Uri.EscapeDataString(param);
                param = param.Replace("%3D", "=").Replace("%26", "&");
            }

            string text;
            int    randomId;

            while (true)
            {
                Random rnd = new Random();
                randomId = rnd.Next(100000, 1000000000);
                text     = Network.GET(string.Concat(new string[]
                {
                    "https://api.vk.com/method/",
                    method,
                    "?",
                    param,
                    "&access_token=",
                    token,
                    captcha_data,
                    "&v=5.92",
                    "&random_id=",
                    randomId.ToString()
                }), null);
                if (!text.Contains("\"error_code\":6"))
                {
                    break;
                }
                Thread.Sleep(333);
            }
            if (text.Contains("\"error_code\":14"))
            {
                string between = StrWrk.GetBetween(text, "\"captcha_sid\":\"", "\"");
                string url     = StrWrk.GetBetween(text, "\"captcha_img\":\"", "\"").Replace("\\", "");
                string str     = "";
                if (VkCaptchaWorks.Enabled)
                {
                    Log.Push("[captcha]: обработка капчи");
                    try
                    {
                        str = VkCaptchaWorks.Solve(url, between);
                    }
                    catch (RuCaptchaException ex)
                    {
                        Log.Push("[Ошибка обработки captcha]: " + ex.Message);
                    }
                    return(APIRequest(method, param, token, "&captcha_sid=" + between + "&captcha_key=" + str));
                }
                Log.Push("[captcha]: изображение поставлено в очередь на ручной ввод");
                str = VkCaptchaWorks.SolveManual(url, between);
                return(APIRequest(method, param, token, "&captcha_sid=" + between + "&captcha_key=" + str));
            }
            else
            {
                if (text.Contains("\"error_code\""))
                {
                    throw new Exception(StrWrk.GetBetween(text, "\"error_msg\":\"", "\""));
                }
                return(text);
            }
        }