Example #1
0
        ServiceCollection MockResolveScreenNameApi(VkObject resolveScreenNameFakeResponse = null)
        {
            if (resolveScreenNameFakeResponse == null)
            {
                resolveScreenNameFakeResponse = new VkObject()
                {
                    Type = VkNet.Enums.VkObjectType.Group, Id = 123456
                }
            }
            ;

            var di = new ServiceCollection();

            var mockRepo = new MockRepository(MockBehavior.Default);

            var vkMock    = mockRepo.Create <IVkApi>();
            var utilsMock = mockRepo.Create <IUtilsCategory>();

            vkMock.SetupGet(x => x.Utils).Returns(utilsMock.Object);
            utilsMock.Setup(x => x.ResolveScreenName(It.IsAny <string>())).Returns(resolveScreenNameFakeResponse);

            di.AddSingleton <IVkApi>(x => { return(vkMock.Object); });

            return(di);
        }
Example #2
0
 public static InternalVkApiObject ToInternal(this VkObject vkObject)
 {
     return(vkObject == null
                ? null
                : new InternalVkApiObject
     {
         Id = vkObject.Id,
         Type = ToInternal(vkObject.Type)
     });
 }
Example #3
0
        private void ResolveGroupId()
        {
            this.GroupUrl = Regex.Replace(this.GroupUrl, ".*/", "");
            VkObject result = this.Api.Utils.ResolveScreenName(this.GroupUrl);

            if (result.Type != VkObjectType.Group)
            {
                throw new VkApiException("GroupUrl не указывает на группу.");
            }
            this.GroupId = (ulong)result.Id;
            Console.WriteLine($"GroupId resolved. id: {this.GroupId}");
        }
Example #4
0
        public void VkBotCtor_PutFakeGroupId_ResolvedGroupIdShouldBeAsFake()
        {
            long expectedGroupId = 111222;
            var  resolveScreenNameFakeResponse = new VkObject()
            {
                Type = VkNet.Enums.VkObjectType.Group, Id = expectedGroupId
            };
            var di = MockResolveScreenNameApi(resolveScreenNameFakeResponse);

            var bot = new VkBot("test", "test", di);

            Assert.AreEqual(bot.GroupId, expectedGroupId);
        }
Example #5
0
        public void ResolveScreenName_BadScreenName()
        {
            const string url  = "https://api.vk.com/method/utils.resolveScreenName?screen_name=3f625aef-b285-4006-a87f-0367a04f1138&access_token=";
            const string json =
                @"{
                    'response': []
                  }";

            var utils = GetMockedUtilsCategory(url, json);

            VkObject obj = utils.ResolveScreenName("3f625aef-b285-4006-a87f-0367a04f1138");

            obj.ShouldBeNull();
        }
Example #6
0
 private static List <User> UsersSearch(VkObject searchGroup, ushort min, ushort max, string city,
                                        Sex sex)
 {
     return(Vk.Users.Search(
                new UserSearchParams
     {
         AgeFrom = min,
         AgeTo = max,
         Sort = 0,
         Count = 1000,
         Country = 1,
         Hometown = city,
         Sex = sex,
         Fields = ProfileFields.Photo100,
         // ReSharper disable once PossibleInvalidOperationException
         GroupId = (ulong)searchGroup.Id
     }).ToList());
 }
Example #7
0
        public void ResolveScreenName_Group()
        {
            const string url  = "https://api.vk.com/method/utils.resolveScreenName?screen_name=mdk&access_token=";
            const string json =
                @"{
                    'response': {
                      'type': 'group',
                      'object_id': 10639516.0
                    }
                  }";

            var utils = GetMockedUtilsCategory(url, json);

            VkObject obj = utils.ResolveScreenName("mdk");

            // assert
            obj.ShouldNotBeNull();
            obj.Type.ShouldEqual(VkObjectType.Group);
            obj.Id.ShouldEqual(10639516);
        }
Example #8
0
        public void ResolveScreenName_ObjectIdIsVeryBig_User()
        {
            const string url  = "https://api.vk.com/method/utils.resolveScreenName?screen_name=azhidkov&access_token=";
            const string json =
                @"{
                    'response': {
                      'type': 'user',
                      'object_id': 922337203685471.0
                    }
                  }";

            var utils = GetMockedUtilsCategory(url, json);

            VkObject obj = utils.ResolveScreenName("azhidkov");

            // assert
            obj.ShouldNotBeNull();
            obj.Id.ShouldEqual(922337203685471);
            obj.Type.ShouldEqual(VkObjectType.User);
        }
Example #9
0
        private long ResolveGroupId(string groupUrl)
        {
            this.FilteredGroupUrl = Regex.Replace(groupUrl, ".*/", "");

            VkObject result = this.Api.Utils.ResolveScreenName(this.FilteredGroupUrl);

            if (result == null || !result.Id.HasValue)
            {
                throw new GroupNotResolvedException($"группа '{groupUrl}' не существует.");
            }

            if (result.Type != VkObjectType.Group)
            {
                throw new GroupNotResolvedException("GroupUrl не указывает на группу.");
            }

            long groupId = result.Id.Value;

            this.Logger.LogInformation($"VkBot: GroupId resolved. id: {groupId}");
            return(groupId);
        }
Example #10
0
        public static void HandleNewMessage(VkObject objectMessage, IVkApi vkApi)
        {
            string text = objectMessage.Message.Text;

            vkApi.Messages.SetActivity(vkApi.UserId.ToString(), MessageActivityType.Typing, objectMessage.Message.PeerId);
            Thread.Sleep(1000);

            if (objectMessage.Message.Attachments.Length > 0)
            {
                text += "\nА еще ты прикрепил ";
                foreach (var atch in objectMessage.Message.Attachments)
                {
                    text += $"{atch.Type}, ";
                }
            }

            vkApi.Messages.Send(new MessagesSendParams {
                RandomId = new DateTime().Millisecond,
                PeerId   = objectMessage.Message.PeerId,
                Message  = text
            });
        }
Example #11
0
        private void StartPosting(string[] lines1, string[] lines2, string text1, string text2, string text3, string[] lines3, string text4, bool check1, decimal num1, decimal num2, decimal num3)
        {
            string capkey = text3;

            Rucaptcha.Key = capkey;
            string bal  = Rucaptcha.Balance();
            double bala = double.Parse(bal.Replace(".", ","));

            text1 = text1.Replace(" ", "");
            text3 = text3.Replace(" ", "");
            text4 = text4.Replace(" ", "");

            try
            {
                if ((text1 != "" && !text1.Contains("логин")) && (text2 != "" && !text2.Contains("Здесь Ваш текст.")) && (!bal.Contains("ERROR")))
                {
HERE:
                    if (!thread_stop)
                    {
                        for (int loo = 1; loo <= num3; loo++)
                        {
                            ko   = 0;
                            koko = 0;
                            if (bala < 10)
                            {
                                DateTime d      = DateTime.Now;
                                string   Textz  = string.Format("{0:t}", d);
                                string   Time   = Textz.ToString();
                                Action   action = () =>
                                {
                                    richTextBoxAccz.Text += "\n[" + Time + "] Баланс рукапчи не должен быть меньше 10-ти рублей. Пожалуйста, пополните. Текущий баланс: " + Rucaptcha.Balance() + ".\n";
                                };
                                Invoke(action);
                                thread_stop = true;
                                goto HERE;
                            }
                            if (!thread_stop)
                            {
                                if (num3 > 1)
                                {
                                    DateTime d22       = DateTime.Now;
                                    string   Textz22   = string.Format("{0:t}", d22);
                                    string   Time22    = Textz22.ToString();
                                    Action   action234 = () =>
                                    {
                                        richTextBoxAccz.Text += "\n[" + Time22 + "] Выполняемый цикл: " + loo + ".\n";
                                    };
                                    Invoke(action234);
                                }
                            }
                            for (int i = 0; i < lines1.Length; i++) // Count of Accs

                            {
                                lines1[i] = lines1[i].Replace(" ", "");

                                if (!lines1[i].Contains(';'))
                                {
                                    DateTime d      = DateTime.Now;
                                    string   Textz  = string.Format("{0:t}", d);
                                    string   Time   = Textz.ToString();
                                    Action   action = () =>
                                    {
                                        richTextBoxAccz.Text += "\n[" + Time + "] Пожалуйста, поставьте разделитель ';' на " + Convert.ToInt32(i + 1) + " строчке.\n";
                                    };
                                    Invoke(action);
                                }
                                else
                                {
                                    var s = lines1[i].Split(';');
                                    log  = s[0].ToString();
                                    pass = s[1].ToString();

                                    try
                                    {
                                        CountOfGr = 0;
                                        var vk = new VkApi();

                                        if (!thread_stop)
                                        {
                                            string result_auth = Auth(0, "", pass, log, i, vk, capkey); // Автоpизация
                                        }
                                        if (!thread_stop)
                                        {
                                            for (int k = koko; k < lines2.Length; k++) // Кол-во строк в тексбоксе групп.
                                            {
                                                lines2[k] = lines2[k].Replace(" ", "");

                                                koko = k;
                                                if (ko == num2)
                                                {
                                                    ko = 0;
                                                    break;
                                                }

                                                if (!thread_stop)
                                                {
                                                    if (text2.Contains(';'))
                                                    {
                                                        var te = text2.Split(';');
                                                        if (kaz == numericUpDown1.Value)
                                                        {
                                                            ka++;
                                                            kaz = numericUpDown1.Value - 1;
                                                        }
                                                        if (ka == te.Length)
                                                        {
                                                            ka  = 0;
                                                            kaz = 0;
                                                        }
                                                        texta = te[ka];
                                                        kaz++;
                                                    }
                                                    else
                                                    {
                                                        texta = text2;
                                                    }

                                                    firstIsVowel = (new Regex(@"club[0-9]{4,12}$").IsMatch(lines2[k]));

                                                    if (firstIsVowel && !lines2[k].Contains("группа"))
                                                    {
                                                        if (checkBox1.Checked == true)
                                                        {
                                                            prove = true;
                                                        }
                                                        else
                                                        {
                                                            prove = false;
                                                        }

                                                        var tro = lines2[k];
                                                        tro = tro.Replace("https://vk.com/club", "");
                                                        tro = tro.Replace("vk.com/club", "");
                                                        long id = long.Parse(tro);

                                                        Message(lines2, k, 0, "", prove, id, texta, vk, capkey, text4, check1, lines3, num1); // Оставить сообщение
                                                    }
                                                    else if (!firstIsVowel && !lines2[k].Contains("группа") && lines2[k].Contains("vk.com"))
                                                    {
                                                        if (checkBox1.Checked == true)
                                                        {
                                                            prove = true;
                                                        }
                                                        else
                                                        {
                                                            prove = false;
                                                        }
                                                        var tro = lines2[k];
                                                        tro = tro.Replace("https://vk.com/", "");
                                                        tro = tro.Replace("vk.com/", "");
                                                        VkObject obj = vk.Utils.ResolveScreenName(tro);
                                                        long?    ide = obj.Id;
                                                        string   ido = ide.ToString();
                                                        long     id  = long.Parse(ido);

                                                        Message(lines2, k, 0, "", prove, id, texta, vk, capkey, text4, check1, lines3, num1); // Оставить сообщение
                                                    }
                                                    else
                                                    {
                                                        DateTime di      = DateTime.Now;
                                                        string   Textza  = string.Format("{0:t}", di);
                                                        string   Timea   = Textza.ToString();
                                                        Action   action5 = () =>
                                                        {
                                                            richTextBoxAccz.Text += "\n[" + Timea + "] Пожалуйста, введите список групп в дополнительных настройках. В формате: vk.com/группа.\n";
                                                        };
                                                        Invoke(action5);
                                                    }
                                                }
                                                ko++;
                                            }
                                        }
                                    }
                                    catch (Exception eXa)
                                    {
                                        MessageBox.Show(eXa.ToString());
                                        DateTime di     = DateTime.Now;
                                        string   Textza = string.Format("{0:t}", di);
                                        string   Timea  = Textza.ToString();
                                        Action   action = () =>
                                        {
                                            richTextBoxAccz.Text += "\n[" + Timea + "] Ошибка, невозможно авторизоваться в аккаунт с логином: " + log + ".\n";
                                        };
                                        Invoke(action);
                                    }
                                }
                            } // accz
                        }     // Loop
                    }         // if thread_stop != true
                }
                else
                {
                    if (text1 == "" || text1.Contains("логин"))
                    {
                        DateTime d      = DateTime.Now;
                        string   Textz  = string.Format("{0:t}", d);
                        string   Time   = Textz.ToString();
                        Action   action = () =>
                        {
                            richTextBoxAccz.Text += "\n[" + Time + "] Пожалуйста, введите логин и пароль от аккаунта.\n";
                        };
                        Invoke(action);
                    }
                    if (text2 == "" || text2.Contains("Здесь Ваш текст."))
                    {
                        DateTime d         = DateTime.Now;
                        string   Textz     = string.Format("{0:t}", d);
                        string   Time      = Textz.ToString();
                        Action   action234 = () =>
                        {
                            richTextBoxAccz.Text += "\n[" + Time + "] Пожалуйста, введите текст в дополнительных настройках.\n";
                        };
                        Invoke(action234);
                    }
                    if (bal.Contains("ERROR"))
                    {
                        DateTime d        = DateTime.Now;
                        string   Textz    = string.Format("{0:t}", d);
                        string   Time     = Textz.ToString();
                        Action   action23 = () =>
                        {
                            richTextBoxAccz.Text += "\n[" + Time + "] Пожалуйста, введите API ключ от сервиса rucaptcha.com.\n";
                        };
                        Invoke(action23);
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
            }

            DateTime dp        = DateTime.Now;
            string   Textzp    = string.Format("{0:t}", dp);
            string   Timep     = Textzp.ToString();
            Action   actionaio = () =>
            {
                richTextBoxAccz.Text += "\n[" + Timep + "] Работа успешно завершена.\n";
                button2.Enabled       = true;
                thread_stop           = true;
                button1.Text          = "Запуск";
            };

            Invoke(actionaio);
        }