Пример #1
0
        public static void Auth()
        {
            using (var codeForm = new EnterTextForm("Разрешите приложению доступ и скопируйте ссылку из адресной строки.\r\n" +
                                                    "Пример: https://oauth.vk.com/blank.html#code=d4943b464ac2b8", "Авторизация пользователя"))
            {
                Process.Start(AuthUrlBuilder.User.CreateAuthUrl(VkApp.AppId, VkApp.Scope));
                codeForm.ShowDialog();
                try
                {
                    string code = codeForm.Result.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
                    VkApp.AuthUserByCode(code);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Проверьте правильность введённых данных. \n\n(Ошибка:{ex.Message})");
                    Application.Exit();
                }
            }

            using (var groupTokenForm = new EnterTextForm("Скопируйте access_token из адресной строки.\r\n" +
                                                          "Пример: 533bacf01e11f55b5b57531ad114461ae8736d6506a3", "Авторизация сообщества"))
            {
                Process.Start(AuthUrlBuilder.Group.CreateAuthUrl(VkApp.AppId, 179170080));

                groupTokenForm.ShowDialog();

                VkApp.GroupAccessToken = groupTokenForm.Result;
            }
        }
Пример #2
0
        private async void Main_Load(object sender, EventArgs e)
        {
            bool anticaptchaInitialized = AnticaptchaWorker.TryInitialize();

            if (anticaptchaInitialized)
            {
                this.Text = $"Главная | Баланс: {AnticaptchaWorker.Api.GetBalance()}";
            }

            VkApp.Auth();
            await WinFormsExt.LoadListsAsync();

            foreach (var friendList in VkApp.CurrentFriendlists)
            {
                this.lstFriendLists.Items.Add($"{friendList.Id}: {friendList.Name}");
                this.lstExclude.Items.Add($"{friendList.Id}: {friendList.Name}");
            }

            this.lstFriendLists.SetSelected(0, true);

            await this.UpdateMessagesSentCount();
        }
Пример #3
0
        private async Task <bool> TrySendMessage(string messageText, long userId)
        {
            while (true)
            {
                try
                {
                    VkApp.Api.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams
                    {
                        Message     = messageText,
                        UserId      = userId,
                        Attachments = Attachments,
                        RandomId    = VkApp.GetRandomId(),
                        CaptchaKey  = AnticaptchaWorker.LastCaptcha,
                        CaptchaSid  = AnticaptchaWorker.LastCaptchaSid,
                    });

                    return(true);
                }
                catch (CaptchaNeededException captcha)
                {
                    AnticaptchaWorker.LastCaptchaSid = captcha.Sid;
                    AnticaptchaWorker.LastCaptchaUri = captcha.Img.AbsoluteUri;

                    var anticaptchaBalance = AnticaptchaWorker.Api.GetBalance();                     // TODO: NullReferenceException.

                    if (AnticaptchaWorker.Api != null)
                    {
                        this.Text = $"Главная | Баланс: {anticaptchaBalance} | Решается капча";
                    }
                    else
                    {
                        this.Text = $"Главная | Баланс: --- | Решается капча";
                    }

                    using (var captchaForm = new CaptchaForm(captcha.Img.AbsoluteUri))
                    {
                        if (AnticaptchaWorker.Api == null && (true || anticaptchaBalance < 0.005))                         // TODO: чего нахуй
                        {
                            captchaForm.ShowDialog();
                        }

                        // Wait
                        while (AnticaptchaWorker.LastCaptcha == null)
                        {
                            continue;
                        }
                    }

                    if (AnticaptchaWorker.Api != null)
                    {
                        this.Text = $"Главная | Баланс: {AnticaptchaWorker.Api.GetBalance()} | {AnticaptchaWorker.LastCaptcha}";
                    }
                }
                catch (TooManyRequestsException)
                {
                    this.Text = $"Главная | Баланс: {AnticaptchaWorker.Api.GetBalance()} | Слишком много запросов в секунду.";
                    await Task.Delay(1000);
                }
                catch (TooMuchSentMessagesException ex)
                {
                    string errormessage = $"Лимит на рассылку исчерпан. Рассылка будет остановлена. \n\n" +
                                          $"  Код ошибки: {ex.ErrorCode}\n{ex.Message}";
                    MessageBoxExt.ShowInNewThread(errormessage);
                    return(false);
                }
                catch (AccessDeniedException ex)
                {
                    string errormessage = $"Отказано в доступе. \nПользователь ID: {userId}\n\n" +
                                          $"  Код ошибки: {ex.ErrorCode}\n{ex.Message}";

                    MessageBoxExt.ShowInNewThread(errormessage);
                    return(false);
                }
                catch (UnknownException ex)
                {
                    string errormessage = $"Неизвестная ошибка на стороне VK. \nПользователь ID: {userId}\n\n" +
                                          $"  Код ошибки: {ex.ErrorCode}\n{ex.Message}";

                    MessageBoxExt.ShowInNewThread(errormessage);
                    return(false);
                }
                catch (Exception ex)
                {
                    string errormessage = $"Неизвестная общая ошибка. \nПользователь ID: {userId}\n\n" +
                                          $"  {ex.Message}";

                    MessageBoxExt.ShowInNewThread(errormessage);
                    return(false);
                }
            }
        }