Exemple #1
0
        private bool ClickToAddFriendAt(ProfileMessage profile, int x, int y, Filter filter)
        {
            ZaloHelper.Output($"!đã nhấn vào bạn: {profile.Name}");

            TouchAt(x, y);//TOUCH TO ROW_INDEX

            Delay(2000);
            //I''m on profile page

            var info = GrabProfileInfo(profile.Name);

            ZaloHelper.CopyProfile(ref profile, info);

            string reason;

            if (!filter.IsValidProfile(profile, out reason))
            {
                ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);
                TouchAtIconTopLeft(); //GoBack to friendList
                return(false);
            }

            if (!info.IsAddedToFriend)
            {
                return(AddFriendViaIconButton(profile, filter));
            }
            else
            {
                ZaloHelper.Output($"!yêu cầu kết bạn: {profile.Name} bị từ hủy. Lý do: đã có tên trong cơ sở dữ liệu");
                TouchAtIconTopLeft(); //GoBack to friendList
                return(false);
            }
        }
        public void NavigateToProfileScreenFromChatScreenToGetInfoThenGoBack(ChatRequest request)
        {
            //GrabInfomation
            TouchAtIconTopRight();
            Delay(1000);
            TouchAt(Screen.ChatScreenProfileAvartar);
            Delay(2000);

            var infoGrab = GrabProfileInfo(request.Profile.Name);

            var profileCopy = request.Profile;

            ZaloHelper.CopyProfile(ref profileCopy, infoGrab);

            TouchAtIconTopLeft(); //Back to chat screen
            TouchAtIconTopLeft(); //Close sidebar
            //End friend
        }
        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();
            }
        }
        private void ChatFriendNearBy(int maxFriendToday, Filter filter)
        {
            ZaloHelper.Output($"!bắt đầu gửi tin cho bạn gần đây. Số bạn yêu cầu tối đa trong ngày hôm nay là {maxFriendToday}");
            var countSuccess = 0;

            string[] profilesPage1 = null;
            string[] profilesPage2 = null;
            ZaloHelper.Output("!đang tìm thông tin các bạn");
            var friendNotAdded = (GetPositionAccountNotSent(x => profilesPage1 = x)).OrderByDescending(x => x.Point.Y);
            var points         = new Stack <FriendPositionMessage>(friendNotAdded);

            profilesPage1.ToList().ForEach(x => ZaloHelper.Output($"!tìm thấy bạn trên màn hình: {x}"));
            ZaloHelper.Output("!--------------------");
            friendNotAdded.ToList().ForEach(x => ZaloHelper.Output($"!các bạn chưa được gửi lời mời: {x.Name}"));
            while (countSuccess < maxFriendToday)
            {
                while (points.Count == 0)
                {
                    ZaloHelper.Output("!đang cuộn danh sách bạn");
                    ScrollList(9);

                    ZaloHelper.Output("!đang tìm thông tin các bạn");

                    friendNotAdded = GetPositionAccountNotSent(x => profilesPage2 = x).OrderByDescending(x => x.Point.Y);
                    points         = new Stack <FriendPositionMessage>(friendNotAdded);
                    profilesPage2.ToList().ForEach(x => ZaloHelper.Output($"!tìm thấy bạn trên màn hình: {x}"));

                    ZaloHelper.OutputLine();
                    friendNotAdded.ToList().ForEach(x => ZaloHelper.Output($"!bạn chưa được gửi tin nhắn: {x}"));
                    ZaloHelper.OutputLine();

                    if (!profilesPage2.Except(profilesPage1).Any())
                    {
                        ZaloHelper.Output("!hết bạn trong danh sách.");

                        return;
                    }

                    profilesPage1 = profilesPage2;
                }

                Delay(2000);

                var pointRowFriend = points.Pop();

                var request = new ChatRequest
                {
                    Profile = new ProfileMessage
                    {
                        Name     = pointRowFriend.Name,
                        Location = filter.Locations
                    },
                    Objective = ChatObjective.StrangerNearBy
                };

                if (Screen.InfoRect.Contains(pointRowFriend.Point))
                {
                    TouchAt(pointRowFriend.Point);
                    Delay(2000);//wait to navigate chat screen

                    var infoGrab = GrabProfileInfo(pointRowFriend.Name);
                    var profile  = request.Profile;
                    ZaloHelper.CopyProfile(ref profile, infoGrab);

                    string reason;
                    if (!filter.IsValidProfile(request.Profile, out reason))
                    {
                        ZaloHelper.Output("Bỏ qua bạn này, lý do: " + reason);
                        TouchAt(Screen.IconTopLeft);
                        Delay(300);
                    }
                    else
                    {
                        TouchAt(Screen.IconBottomLeft);
                        Delay(800);

                        if (Chat(request, filter))
                        {
                            DbContext.AddProfile(request.Profile, Settings.User.Username);
                            countSuccess++;
                            ZaloHelper.Output($"!gửi tin nhắn tới: {request.Profile.Name} thành công. Số bạn đã gửi thành công trong phiên này là: {countSuccess}");

                            TouchAtIconTopLeft(); //Go Back TO PROFILE

                            TouchAtIconTopLeft(); // GO BACK TO FRIENDLIST
                        }
                    }
                }
            }
        }