コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        public DailyFriends(DataContext db, VkApi api, BotProcessor botProcessor) : base(db, api)
        {
            BotProcessor = botProcessor;

            UserParams = new CheckUserParams();
        }