Exemple #1
0
        private FriendPositionMessage[] GetPositionAccountNotAdded(Action <string[]> allPrrofiles)
        {
            var captureFiles = CaptureScreenNow();
            var names        = ZaloImageProcessing.GetListFriendName(captureFiles, Screen);

            var t = names.Where(v => DbContext.LogRequestAddFriendSet.FirstOrDefault(x => x.Name == v.Name && x.Account == Settings.User.Username) == null).ToArray();

            allPrrofiles(names.Select(x => x.Name).ToArray());
            return(t.ToArray());
        }
        private void SendMessageToFriendWithNames(Filter filter)
        {
            var stack = new Stack <string>(filter.IncludedPeopleNames.ZaloSplitText());

            while (stack.Count > 0)
            {
                Delay(1000);
                TouchAtIconBottomLeft();//Open search
                Delay(500);
                var name = stack.Pop();

                TouchAt(Screen.HomeScreenFriendTabSearchTextField);
                Delay(500);

                SendText(name);

                var rowFriends = ZaloImageProcessing.GetFriendProfileList(CaptureScreenNow(), Screen);
                if (!rowFriends.Any())
                {
                    ZaloHelper.Output("Không có kết quả");

                    TouchAtIconTopLeft();

                    continue;
                }

                TouchAt(Screen.HomeScreenFriendTabSearchFristItem);
                Delay(500);

                var request = new ChatRequest()
                {
                    Objective = ChatObjective.FriendInContactList, Profile = new ProfileMessage()
                };
                NavigateToProfileScreenFromChatScreenToGetInfoThenGoBack(request);

                string reason;
                if (!filter.IsValidProfile(request.Profile, out reason))
                {
                    ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);
                    TouchAtIconTopLeft(); //Touch to close side bar
                    Delay(400);
                }
                else
                {
                    Chat(request, filter);

                    TouchAtIconTopLeft();//GO BACK PROFILE
                }
            }

            //Search in contact
        }
Exemple #3
0
        private bool ProcessIfShowDialogWaitRequestedFriendConfirm()
        {
            var file      = CaptureScreenNow();
            var hasDialog = ZaloImageProcessing.IsShowDialogWaitAddedFriendConfirmWhenRequestAdd(file, Screen);

            if (hasDialog)
            {
                TouchAt(Screen.AddFriendScreenWaitFriendConfirmDialog);

                return(true);
            }

            return(false);
        }
Exemple #4
0
        public void Login(User user)
        {
            try
            {
                var count  = 0;
                var finish = false;
                while (!finish && count < 5)
                {
                    EnableAbdKeyoard();
                    var account  = user.Username;
                    var password = user.Password;
                    var region   = user.Region;

                    ZaloHelper.Output("Đóng ZALO trước đó");
                    InvokeProc("/c adb shell am force-stop com.zing.zalo");
                    Delay(Settings.Delay.WaitForceCloseApp);

                    //InvokeProc("/c adb shell am start -n com.zing.zalo/.MainActivity");

                    ZaloHelper.Output("Tiến hành đăng nhập vào tài khoản: " + account);
                    GotoPage(Activity.LoginUsingPw);

                    Delay(Settings.Delay.WaitLoginScreenOpened);
                    if (!region.Equals("Vietnam"))
                    {
                        ZaloHelper.Output("Chọn khu vực trong cửa sổ mới" + region);
                        TouchAt(Screen.LoginScreenCountryCombobox);
                        Delay(1000);
                        TouchAt(Screen.IconTopRight);
                        Delay(1100);
                        SendText(region);
                        Delay(1200);
                        TouchAt(Screen.LoginScreenFirstCountryItem);
                        Delay(500);
                    }

                    ZaloHelper.Output("Đang gửi tên đăng nhập");
                    TouchAt(Screen.LoginScreenPhoneTextField);
                    Delay(200);
                    TouchAt(Screen.LoginScreenPhoneTextField);
                    Delay(200);

                    DeleteWordInFocusedTextField();

                    SendText(account);

                    ZaloHelper.Output("Đang gửi mật khẩu");
                    Delay(100);
                    TouchAt(Screen.LoginScreenPasswordTextField);
                    Delay(500);
                    SendText(password);
                    TouchAt(Screen.LoginScreenOkButton);
                    //SendKey(KeyCode.AkeycodeEnter, 2);

                    Delay(Settings.Delay.WaitLogin);
                    ZaloHelper.Output("Đang gửi thông tin đăng nhập");

                    if (ZaloImageProcessing.HasLoginButton(CaptureScreenNow(), Settings.Screen))
                    {
                        ZaloHelper.Output("Đăng nhập thất bại, đang thử lại");
                    }
                    else
                    {
                        finish = true;
                    }
                    count++;
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                ZaloHelper.Output("Có lỗi xảy ra");
            }
        }
Exemple #5
0
        public void AddFriendByPhone(Filter filter)
        {
            try
            {
                var canAddedFriendToday = (Settings.MaxFriendAddedPerDay - DbContext.GetAddedFriendCount(Settings.User.Username));
                var numberOfAction      = filter.NumberOfAction > canAddedFriendToday ? canAddedFriendToday : filter.NumberOfAction;
                if (numberOfAction == 0)
                {
                    ZaloHelper.Output("Kết bạn tối đa trong ngày rồi");

                    return;
                }

                var countSuccess = 0;
                var phonelist    = new Stack <string>(filter.IncludePhoneNumbers.Split(";,|".ToArray()));
                while (countSuccess < numberOfAction)
                {
                    ZaloHelper.Output("Đang mở trang kết bạn qua số điện thoại");
                    GotoPage(Activity.FindFriendByPhoneNumber);

                    var success = false;
                    while (!success)
                    {
                        if (phonelist.Count == 0)
                        {
                            return;
                        }

                        var phoneNumber = phonelist.Pop();
                        if (DbContext.LogRequestAddFriendSet.FirstOrDefault(x => x.PhoneNumber == phoneNumber && x.Account == Settings.User.Username) != null)
                        {
                            ZaloHelper.Output($"Bỏ qua. Số điện thoại {phoneNumber} đã có tên trong danh sách");

                            continue;
                        }

                        Thread.Sleep(800);
                        ZaloHelper.Output($"Đang xóa ô nhập chữ");
                        DeleteWordInFocusedTextField();
                        ZaloHelper.Output($"Đang nhập số điện thoại :{phoneNumber}");

                        SendText(phoneNumber);
                        SendKey(KeyCode.AkeycodeEnter);
                        Thread.Sleep(4000);

                        //check is not available
                        ZaloHelper.Output("!Kiểm tra thông báo");

                        if (ZaloImageProcessing.HasFindButton(CaptureScreenNow(), Screen))
                        {
                            ZaloHelper.Output("!Lỗi, Số đt chưa có tài khoản ZALO");
                        }
                        else
                        {
                            var profile = GrabProfileInfo();

                            profile.PhoneNumber = phoneNumber;
                            string reason;
                            if (!filter.IsValidProfile(profile, out reason))
                            {
                                ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);
                                TouchAtIconTopLeft();
                                continue;
                            }
                            else
                            {
                                var addSuccess = AddFriendViaIconButton(profile, filter);
                                ZaloHelper.Output($"!Thêm bạn bằng số đt: {phoneNumber} thành công.");
                                if (addSuccess)
                                {
                                    countSuccess++;
                                    success = true;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
            finally
            {
                ZaloHelper.SendCompletedTaskSignal();
            }
        }
        public void SearchFriendInContactList()
        {
            try
            {
                GotoPage(Activity.MainTab);

                Delay(1000);

                TouchAt(Screen.HomeScreenFriendTab);

                Delay(1000);
                ZaloHelper.Output("Đang phân tích dữ liệu");

                var fileCapture = CaptureScreenNow();
                var friends     = ZaloImageProcessing.GetFriendProfileList(fileCapture, Screen);

                ZaloHelper.OutputLine();
                friends.ToList().ForEach(x => ZaloHelper.Output(x.Name));
                ZaloHelper.OutputLine();

                var stack         = new Stack <FriendPositionMessage>(friends.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderByDescending(x => x.Point.Y));
                var profilesPage1 = stack.Select(x => x.Name).ToArray();
                while (true)
                {
                    while (stack.Count == 0)
                    {
                        ScrollList(9);

                        ZaloHelper.Output("Đang phân tích dữ liệu màn hình");
                        fileCapture = CaptureScreenNow();
                        friends     = ZaloImageProcessing.GetFriendProfileList(fileCapture, Screen);

                        ZaloHelper.OutputLine();
                        friends.ToList().ForEach(x => ZaloHelper.Output(x.Name));
                        ZaloHelper.OutputLine();

                        stack = new Stack <FriendPositionMessage>(friends.OrderByDescending(x => x.Point.Y));
                        var profilesPage2 = stack.Select(x => x.Name).ToArray();
                        if (!profilesPage2.Except(profilesPage1).Any())
                        {
                            ZaloHelper.Output("Hết danh sách");

                            return;
                        }

                        profilesPage1 = profilesPage2;
                    }

                    Delay(2000);

                    var rowFriend = stack.Pop();

                    if (DbContext.ProfileSet.FirstOrDefault(x => x.Name == rowFriend.Name && x.Account == Settings.User.Username) != null)
                    {
                        ZaloHelper.Output($"Thu nhập thông tin bạn {rowFriend.Name} rồi");

                        continue;
                    }

                    if (!Screen.InfoRect.Contains(rowFriend.Point))
                    {
                        continue;
                    }

                    TouchAt(rowFriend.Point);
                    Delay(2000);

                    //GrabInfomation
                    TouchAtIconTopRight();
                    Delay(1000);
                    TouchAt(Screen.ChatScreenProfileAvartar);
                    Delay(2000);

                    var profile = new ProfileMessage()
                    {
                        Name = rowFriend.Name
                    };

                    var infoGrab = GrabProfileInfo(profile.Name);

                    ZaloHelper.CopyProfile(ref profile, infoGrab);

                    TouchAtIconTopLeft(); //Back to chat screen
                    Delay(400);
                    TouchAtIconTopLeft(); //Close sidebar
                    Delay(400);
                    TouchAtIconTopLeft(); //Goback friend list
                    Delay(400);
                    DbContext.AddProfile(profile, Settings.User.Username, true);
                    Delay(400);
                }
            }
            catch (Exception ex) { _log.Error(ex); }
            finally
            {
                ZaloHelper.SendCompletedTaskSignal();
            }
        }
        public void SendMessageToFriendInContactList(Filter filter)
        {
            try
            {
                var countSuccess = 0;

                GotoPage(Activity.MainTab);

                Delay(1000);

                TouchAt(Screen.HomeScreenFriendTab);

                if (!string.IsNullOrWhiteSpace(filter.IncludedPeopleNames))
                {
                    SendMessageToFriendWithNames(filter);

                    return;
                }

                Delay(1000);
                ZaloHelper.Output("Đang phân tích dữ liệu");

                var fileCapture = CaptureScreenNow();
                var friends     = ZaloImageProcessing.GetFriendProfileList(fileCapture, Screen);

                ZaloHelper.OutputLine();
                friends.ToList().ForEach(x => ZaloHelper.Output(x.Name));
                ZaloHelper.OutputLine();

                var stack         = new Stack <FriendPositionMessage>(friends.Where(x => !string.IsNullOrWhiteSpace(x.Name)).OrderByDescending(x => x.Point.Y));
                var profilesPage1 = stack.Select(x => x.Name).ToArray();

                while (countSuccess <= filter.NumberOfAction)
                {
                    while (stack.Count == 0)
                    {
                        ScrollList(9);

                        ZaloHelper.Output("Đang phân tích dữ liệu màn hình");
                        fileCapture = CaptureScreenNow();
                        friends     = ZaloImageProcessing.GetFriendProfileList(fileCapture, Screen);

                        ZaloHelper.OutputLine();
                        friends.ToList().ForEach(x => ZaloHelper.Output(x.Name));
                        ZaloHelper.OutputLine();

                        stack = new Stack <FriendPositionMessage>(friends.OrderByDescending(x => x.Point.Y));
                        var profilesPage2 = stack.Select(x => x.Name).ToArray();
                        if (!profilesPage2.Except(profilesPage1).Any())
                        {
                            ZaloHelper.Output("Hết danh sách");
                            return;
                        }

                        profilesPage1 = profilesPage2;
                    }

                    Delay(2000);

                    var rowFriend = stack.Pop();

                    if (DbContext.LogMessageSentToFriendSet.FirstOrDefault(x => x.Name == rowFriend.Name && x.Account == Settings.User.Username) != null)
                    {
                        ZaloHelper.Output($"Đã gửi tin cho bạn {rowFriend.Name} rồi");

                        continue;
                    }

                    var profile = DbContext.ProfileSet.FirstOrDefault(x => x.Name == rowFriend.Name);
                    var request = new ChatRequest
                    {
                        Profile = new ProfileMessage
                        {
                            Name        = rowFriend.Name,
                            Location    = profile?.Location,
                            PhoneNumber = profile?.PhoneNumber
                        },
                        Objective = ChatObjective.FriendInContactList
                    };

                    if (Screen.InfoRect.Contains(rowFriend.Point))
                    {
                        TouchAt(rowFriend.Point);
                        Delay(2000);

                        NavigateToProfileScreenFromChatScreenToGetInfoThenGoBack(request);

                        string reason;
                        if (!filter.IsValidProfile(request.Profile, out reason))
                        {
                            ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);
                            TouchAtIconTopLeft(); //Touch to close side bar
                            Delay(400);
                        }
                        else
                        {
                            if (Chat(request, filter))
                            {
                                countSuccess++;
                                if (profile == null)
                                {
                                    DbContext.AddProfile(request.Profile, Settings.User.Username);
                                }
                            }

                            TouchAtIconTopLeft();//GO BACK PROFILE
                        }
                    }
                }
            }
            catch (Exception ex) { _log.Error(ex); }
            finally
            {
                ZaloHelper.SendCompletedTaskSignal();
            }
        }
        public void SendMessageByPhoneNumber(Filter filter)
        {
            try
            {
                var canSentToday   = Settings.MaxMessageStrangerPerDay - DbContext.GetMessageToStragerCount(Settings.User.Username);
                var numberOfAction = filter.NumberOfAction > canSentToday ? canSentToday : filter.NumberOfAction;
                if (numberOfAction <= 0)
                {
                    ZaloHelper.Output("đã gửi hết số bạn trong ngày rồi");

                    return;
                }

                var phonelist = filter.IncludePhoneNumbers.Split(";,|".ToArray()).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();

                var countSuccess = 0;
                var stack        = new Stack <string>(phonelist);

                while (countSuccess < numberOfAction)
                {
                    GotoPage(Activity.FindFriendByPhoneNumber);
                    var success = false;

                    while (!success)
                    {
                        if (stack.Count == 0)
                        {
                            return;
                        }
                        var phoneNumber = stack.Pop();
                        ZaloHelper.Output($"Tiến hành gửi tin qua số đt {phoneNumber}");
                        if (DbContext.LogMessageSentToStrangerSet.FirstOrDefault(x => x.PhoneNumber == phoneNumber && x.Account == Settings.User.Username) != null)
                        {
                            ZaloHelper.Output($"Đã gửi tin cho số đt '{phoneNumber}' rồi");

                            continue;
                        }

                        Thread.Sleep(100);

                        DeleteWordInFocusedTextField();
                        SendText(phoneNumber);

                        SendKey(KeyCode.AkeycodeEnter);
                        Thread.Sleep(4000);

                        ZaloHelper.Output("!đang kiểm tra số điện thoại khả dụng");
                        if (ZaloImageProcessing.HasFindButton(CaptureScreenNow(), Screen))
                        {
                            ZaloHelper.Output("!Lỗi, số đt không có");
                        }
                        else
                        {
                            var profile = GrabProfileInfo();
                            profile.PhoneNumber = phoneNumber;

                            string reason;
                            if (!filter.IsValidProfile(profile, out reason))
                            {
                                ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);

                                TouchAtIconTopLeft(); //Go back to phone Entry
                                Delay(400);
                            }
                            else
                            {
                                var request = new ChatRequest {
                                    Profile = profile, Objective = ChatObjective.StrangerByPhone
                                };

                                TouchAt(Screen.IconBottomLeft);
                                Delay(800);

                                if (Chat(request, filter))
                                {
                                    countSuccess++;
                                    DbContext.AddProfile(request.Profile, Settings.User.Username);

                                    success = true;
                                }

                                TouchAtIconTopLeft();//GO BACK FRIENDLIST
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
            finally
            {
                ZaloHelper.SendCompletedTaskSignal();
            }
        }
Exemple #9
0
        private static void Main(string[] args)
        {
            if (args[1] == "last-filter")
            {
                var directory = Directory.GetDirectories($@".\{WorkingFolderPath}\").OrderByDescending(Directory.GetCreationTime).First();

                args[1] = directory.Split("\\".ToArray()).Last();
            }

            Console.OutputEncoding = System.Text.Encoding.UTF8;

            var sessionId = args[1];
            SessionId = sessionId;
            ZaloHelper.Output($"Request:{args[0]} .SessionId:{sessionId}.");

            var settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText($@".\{WorkingFolderPath}\{sessionId}\setting.json"));
            Func<Filter> getFilter = () => JsonConvert.DeserializeObject<Filter>(File.ReadAllText($@".\{WorkingFolderPath}\{sessionId}\filter.json"));

            var zaloImageProcessing = new ZaloImageProcessing();
            var databaseContext = new DatabaseContext();
            var zaloAdbRequest = new ZaloAdbRequest(settings);
            if (!zaloAdbRequest.StartAvd(settings.DeviceNumber))
            {
                ZaloHelper.Output("Không tìm thấy thiết bị android.");
                return;
            }

            if (!settings.IgnoreLogin)
            {
                var zaloLoginService = new ZaloLoginService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                zaloLoginService.Login(settings.User);
            }
            switch (args[0])
            {
                case RunnerConstants.addfriendnearby:
                case "ket-ban-gan-day":

                    var zaloAddFriendService = new ZaloAddFriendService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloAddFriendService.AddFriendNearBy(getFilter());

                    break;

                case RunnerConstants.addfriendbyphone:
                case "ket-ban-qua-dien-thoai":
                    zaloAddFriendService = new ZaloAddFriendService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloAddFriendService.AddFriendByPhone(getFilter());

                    break;

                case RunnerConstants.sendmessagenearby:
                case "gui-tin-nhan-gan-day":
                    var zaloMessageToFriendService = new ZaloMessageService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloMessageToFriendService.SendMessageNearBy(getFilter());

                    break;

                case RunnerConstants.sendmessagebyphonenumber:
                case "gui-tin-nhan-qua-so-dien-thoai":
                    zaloMessageToFriendService = new ZaloMessageService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloMessageToFriendService.SendMessageByPhoneNumber(getFilter());

                    break;

                case RunnerConstants.sendmessagetofriendsincontacts:
                case "gui-tin-nhan-trong-danh-ba":
                    zaloMessageToFriendService = new ZaloMessageService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloMessageToFriendService.SendMessageToFriendInContactList(getFilter());

                    break;

                case RunnerConstants.searchallfriendsincontacts:
                case "tim-tat-ca-cac-ban-trong-danh-ba":
                    var zaloSearchFriendService = new ZaloSearchFriendService(settings, databaseContext, zaloImageProcessing, zaloAdbRequest);
                    zaloSearchFriendService.SearchFriendInContactList();

                    break;
            }
        }