public override async Task Work() { while (Running) { try { User nextUser = BotProcessor.GetNextUser(); if (nextUser == null) { return; } var userInfo = await Api.Users.GetAsync(new List <long> { nextUser.Pk }, ProfileFields.All); if (!userInfo.First().IsClosed.Value) { var friends = await Api.Friends.GetAsync(new VkNet.Model.RequestParams.FriendsGetParams { UserId = nextUser.Pk }); var checkFriends = await BotProcessor.CheckFriends(friends.Count, UserParams); if (!checkFriends) { await BotProcessor.Delay(1, 1, TokenSource.Token); continue; } } var checkResult = await BotProcessor.CheckUser(userInfo, UserParams); if (!checkResult) { await BotProcessor.Delay(1, 1, TokenSource.Token); continue; } AddFriendStatus friendStatus = await Api.Friends.AddAsync(nextUser.Pk); if (friendStatus == AddFriendStatus.Sended) { DB.Users.Where(p => p.Id == nextUser.Id).FirstOrDefault().FriendStatus = Model.FriendStatus.RequestSent; await DB.SaveChangesAsync(); } await BotProcessor.Delay(14, 15, TokenSource.Token); } catch (Exception e) { Console.WriteLine(e.Message);; Running = false; } } }
public void Add_WithCaptcha_NormalCase() { const string url = "https://api.vk.com/method/friends.add?user_id=242508&text=hello, user!&captcha_sid=1247329&captcha_key=hug2z&access_token=token"; const string json = @"{ 'response': 1 }"; FriendsCategory cat = GetMockedFriendsCategory(url, json); AddFriendStatus status = cat.Add(242508, "hello, user!", captchaSid: 1247329, captchaKey: "hug2z"); Assert.That(status, Is.EqualTo(AddFriendStatus.Sended)); }
public void Add_NormalCase() { const string url = "https://api.vk.com/method/friends.add?user_id=242508&text=hello, user!&access_token=token"; const string json = @"{ 'response': 1 }"; FriendsCategory cat = GetMockedFriendsCategory(url, json); AddFriendStatus status = cat.Add(242508, "hello, user!"); Assert.That(status, Is.EqualTo(AddFriendStatus.Sended)); }