Exemplo n.º 1
0
        private static async Task Main()
        {
            var ps = Process.GetCurrentProcess();

            ps.PriorityClass = ProcessPriorityClass.RealTime;

            ServiceInjector.ConfigureServices();

            InjectServices();

            FillConfigurations();

            System.Console.Clear();

            var blackListedUserIds = _userService.GetBannedIds().Distinct().ToList();

            var badUsers = GetGroupsMembersByGroupIds(_blackListGroupIds, blackListedUserIds);

            if (_blacklistMembersOfChatId != null)
            {
                var chatUsers = _messagesService.GeChatUsers(_blacklistMembersOfChatId.ToList(), true);
                System.Console.WriteLine($"chatUsers count is {chatUsers.Count}");
                badUsers.AddRange(chatUsers);
            }

            //var badUsers = GetCachedBlacklistUsers();

            System.Console.WriteLine($"About to prepare list badUsers.Count is {badUsers.Count}.");
            var cities         = _citiesService.GetCities(_cityIds, false);
            var totalUsersList = PrepareUserList(badUsers, blackListedUserIds, cities);

            System.Console.WriteLine($"List has been prepared, totalUsersList.Count is {totalUsersList.Count}.");

            BlackListUserList(totalUsersList);

            System.Console.WriteLine("Start collecting users for background work");
            var usersForBackgroundWork = await GetUsersForBackgroundWork(cities, blackListedUserIds, 1000);


            var friedsOfUserIds = new List <UserExtended>();

            if (_blacklistFriendsOfUserId.Any())
            {
                foreach (var userId in _blacklistFriendsOfUserId)
                {
                    var friends = _userService.GetFriends(userId);
                    friedsOfUserIds.AddRange(friends);
                }
            }

            friedsOfUserIds = friedsOfUserIds.Where(f => blackListedUserIds.Contains(f.Id)).Select(f => f).ToList();

            using (var api = _apiFactory.CreateVkApi())
            {
                foreach (var f in friedsOfUserIds)
                {
                    var needBlackList = SatisfyBySecondAlgorithm(f);
                    if (!needBlackList)
                    {
                        continue;
                    }

                    var message = string.Empty;

                    TimeSpan sleep;
                    try
                    {
                        var blackListResult = BlackListUser(f, api);
                        sleep = blackListResult
                            ? TimeSpan.FromMinutes(MinutesToSleepInBackgroundWork)
                            : TimeSpan.FromSeconds(0);
                        message = ActionResultLogMessage(f, blackListResult);
                    }
                    catch (Exception e)
                    {
                        sleep = HandleException(e, f, null, null, ref message);
                    }

                    System.Console.WriteLine(message);
                    System.Threading.Thread.Sleep(sleep);
                }


                foreach (var f in usersForBackgroundWork)
                {
                    var needBlackList = SatisfyBySecondAlgorithm(f);
                    if (!needBlackList)
                    {
                        continue;
                    }

                    var message = string.Empty;

                    TimeSpan sleep;
                    try
                    {
                        var blackListResult = BlackListUser(f, api);
                        sleep = blackListResult
                            ? TimeSpan.FromMinutes(MinutesToSleepInBackgroundWork)
                            : TimeSpan.FromSeconds(0);
                        message = ActionResultLogMessage(f, blackListResult);
                    }
                    catch (Exception e)
                    {
                        sleep = HandleException(e, f, null, null, ref message);
                    }

                    System.Console.WriteLine(message);
                    System.Threading.Thread.Sleep(sleep);
                }
            }
        }
Exemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            ServiceInjector.ConfigureServices();
            InjectServices();

            var instApi = await _instApiFactory.Login();

            var blockedUsersResult = await instApi.UserProcessor.GetBlockedUsersAsync(PaginationParameters.Empty);

            var alreadyBlockedUsers = new List <string>();

            if (blockedUsersResult.Succeeded && blockedUsersResult.Value?.BlockedList != null)
            {
                alreadyBlockedUsers =
                    blockedUsersResult.Value.BlockedList.Select(x => x.UserName).Select(x => x).ToList();
            }


            var bannedIds   = _userService.GetBannedIds();
            var bannedUsers = _userService.GetUsersByIds(bannedIds, ProfileFields.All);

            var bannedUserInsts = bannedUsers.Where(x => x.Connections != null).Select(x => x).ToList()
                                  .Where(x => !string.IsNullOrWhiteSpace(x.Connections.Instagram)).Select(x => x).ToList()
                                  .Select(x => x.Connections.Instagram).ToList();

            bannedUserInsts = bannedUserInsts.Where(x => !alreadyBlockedUsers.Contains(x)).Select(x => x).ToList();


            // var insUserName = "******";
            // var userInfo = await instApi.UserProcessor.GetUserAsync(insUserName);
            // var blockRes = await instApi.UserProcessor.BlockUserAsync(userInfo.Value.Pk);

            var count   = bannedUserInsts.Count;
            var counter = 1;

            foreach (var insUserName in bannedUserInsts)
            {
                try
                {
                    var userInfo = await instApi.UserProcessor.GetUserAsync(insUserName);

                    if (userInfo.Succeeded && userInfo?.Value?.Pk != null)
                    {
                        var blockRes = await instApi.UserProcessor.BlockUserAsync(userInfo.Value.Pk);

                        if (blockRes.Succeeded)
                        {
                            Console.WriteLine(
                                $"https://www.instagram.com/{insUserName} has been blocked; {counter} out of {count}");

                            counter++;
                        }
                        else
                        {
                            Console.WriteLine($"https://www.instagram.com/{insUserName}  {blockRes.Info}");
                        }
                    }

                    var sleep = TimeSpan.FromSeconds(30);
                    System.Threading.Thread.Sleep(sleep);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 3
0
        private static async Task Main()
        {
            var ps = Process.GetCurrentProcess();

            ps.PriorityClass = ProcessPriorityClass.RealTime;

            ServiceInjector.ConfigureServices();
            InjectServices();
            FillConfigurations();

            Console.Clear();
            Console.WriteLine("Get user ids...");

            var blackListedUserIds = _userService.GetBannedIds().Distinct().ToList();

            var filteredUsers = await _likeClickerService.GetUserIdsByStrategyAsync(_strategy,
                                                                                    _groupNames, new AgeRange(_minAge, _maxAge), _cityIds, MinDateForPosts, blackListedUserIds);

            using (var api = _apiFactory.CreateVkApi())
            {
                var counter = 0;
                var count   = filteredUsers.Count - 1;
                do
                {
                    if (!filteredUsers.Any())
                    {
                        break;
                    }

                    var user = filteredUsers[counter];

                    var wait = (counter % 2 > 0) ? 3 : 4;
                    if (user.Age % 2 > 0)
                    {
                        wait = (counter % 2 > 0) ? 2 : new Random().Next(1, 5);
                    }

                    try
                    {
                        var profilePhotos = _photoService.GetProfilePhotos(user.Id);
                        var skip          = SkipRecentlyLiked(profilePhotos);
                        var result        = false;

                        if (!skip)
                        {
                            result = LikeProfilePhotos(profilePhotos, api, user);
                        }

                        counter++;

                        var message =
                            $"vk.com/{user.Domain} - {(result ? "liked" : "passed")}.{Environment.NewLine}Last activity date: {user.LastActivityDate}, age: {user.Age}, has child: {user.HasChildrens.ToString().ToLower()}.{Environment.NewLine}Time {DateTime.Now}. {counter} out of {count}";

                        Console.WriteLine(message);

                        if (result)
                        {
                            api.Account.SetOffline();
                            System.Threading.Thread.Sleep(TimeSpan.FromMinutes(wait));
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception:" + e.Message);
                        System.Threading.Thread.Sleep(TimeSpan.FromMinutes(5));
                    }
                } while (counter < count);
            }

            Console.ReadLine();
        }
Exemplo n.º 4
0
 private void InjectServices()
 {
     ServiceInjector.ConfigureServices();
     _productService  = ServiceInjector.Retrieve <IProductService>();
     _documentService = ServiceInjector.Retrieve <IDocumentService>();
 }