From ae91f5262cc8f59f45407147a59a55bcc4414a3b Mon Sep 17 00:00:00 2001 From: Victor Phan Date: Thu, 23 Jul 2026 14:02:14 +0700 Subject: [PATCH] feat: add facebook automation bot logic and UI dump templates --- serverPython/facebook_bot.py | 26 +- .../{ => xml_ui}/error_fb_no_comment_btn.xml | 396 +++++----- .../{ => xml_ui}/error_fb_no_edittext.xml | 326 ++++----- .../{ => xml_ui}/fb_step1_open_group.xml | 396 +++++----- .../{ => xml_ui}/fb_step2_scrolling.xml | 396 +++++----- serverPython/{ => xml_ui}/ui_dump.xml | 674 +++++++++--------- 6 files changed, 1115 insertions(+), 1099 deletions(-) rename serverPython/{ => xml_ui}/error_fb_no_comment_btn.xml (99%) rename serverPython/{ => xml_ui}/error_fb_no_edittext.xml (99%) rename serverPython/{ => xml_ui}/fb_step1_open_group.xml (99%) rename serverPython/{ => xml_ui}/fb_step2_scrolling.xml (99%) rename serverPython/{ => xml_ui}/ui_dump.xml (99%) diff --git a/serverPython/facebook_bot.py b/serverPython/facebook_bot.py index 191b60a..76f506e 100644 --- a/serverPython/facebook_bot.py +++ b/serverPython/facebook_bot.py @@ -40,6 +40,13 @@ class FacebookBot: time.sleep(8) # Đợi load giao diện group self.dump_ui_for_debug("fb_step1_open_group.xml") + # Kiểm tra xem Group có bị lỗi "Không hiển thị" (Do sai ID, group chết, group kín) hay không + err_msg1 = self.d(descriptionContains="Nội dung này không hiển thị") + err_msg2 = self.d(descriptionContains="chỉ hiển thị với một số người") + if err_msg1.exists or err_msg2.exists: + logging.warning(f"Group {group_id} không tồn tại hoặc bạn không có quyền truy cập.") + return {"status": "error", "message": "Group không tồn tại hoặc không có quyền truy cập."} + # Quét nút Bình luận, nếu không thấy thì vuốt xuống (vì ảnh bìa group che mất) logging.info("Tìm nút Bình luận của bài viết đầu tiên...") comment_btn = None @@ -70,15 +77,24 @@ class FacebookBot: time.sleep(4) - # Gõ nội dung - logging.info("Đang nhập nội dung comment...") + # Tìm ô nhập liệu "Viết bình luận công khai..." + logging.info("Nhập nội dung text...") + # Facebook có thể dùng EditText hoặc một class khác tùy phiên bản edit_box = self.d(className="android.widget.EditText") + if not edit_box.exists: + # Fallback: Tìm ô chứa chữ "Viết bình luận" hoặc "Write a comment" + edit_box = self.d(descriptionMatches="(?i).*viết bình luận.*") + if not edit_box.exists: + edit_box = self.d(textMatches="(?i).*viết bình luận.*") + if edit_box.exists: - edit_box.set_text(content) + edit_box.click() time.sleep(1) + edit_box.set_text(content) + self.dump_ui_for_debug("fb_step7_text_entered.xml") else: - self.dump_ui_for_debug("error_fb_no_edittext.xml") - return {"status": "error", "message": "Không tìm thấy ô nhập chữ."} + self.dump_ui_for_debug("error_fb_no_edit_box.xml") + return {"status": "error", "message": "Không tìm thấy ô gõ chữ. Có thể bạn bị cấm comment ở Group này."} # Chọn ảnh nếu có if has_image: diff --git a/serverPython/error_fb_no_comment_btn.xml b/serverPython/xml_ui/error_fb_no_comment_btn.xml similarity index 99% rename from serverPython/error_fb_no_comment_btn.xml rename to serverPython/xml_ui/error_fb_no_comment_btn.xml index 8a43d71..b36d6df 100644 --- a/serverPython/error_fb_no_comment_btn.xml +++ b/serverPython/xml_ui/error_fb_no_comment_btn.xml @@ -1,199 +1,199 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/serverPython/error_fb_no_edittext.xml b/serverPython/xml_ui/error_fb_no_edittext.xml similarity index 99% rename from serverPython/error_fb_no_edittext.xml rename to serverPython/xml_ui/error_fb_no_edittext.xml index 08ccb6a..4c478a2 100644 --- a/serverPython/error_fb_no_edittext.xml +++ b/serverPython/xml_ui/error_fb_no_edittext.xml @@ -1,164 +1,164 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/serverPython/fb_step1_open_group.xml b/serverPython/xml_ui/fb_step1_open_group.xml similarity index 99% rename from serverPython/fb_step1_open_group.xml rename to serverPython/xml_ui/fb_step1_open_group.xml index 75640e3..01427a7 100644 --- a/serverPython/fb_step1_open_group.xml +++ b/serverPython/xml_ui/fb_step1_open_group.xml @@ -1,199 +1,199 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/serverPython/fb_step2_scrolling.xml b/serverPython/xml_ui/fb_step2_scrolling.xml similarity index 99% rename from serverPython/fb_step2_scrolling.xml rename to serverPython/xml_ui/fb_step2_scrolling.xml index 8a43d71..b36d6df 100644 --- a/serverPython/fb_step2_scrolling.xml +++ b/serverPython/xml_ui/fb_step2_scrolling.xml @@ -1,199 +1,199 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/serverPython/ui_dump.xml b/serverPython/xml_ui/ui_dump.xml similarity index 99% rename from serverPython/ui_dump.xml rename to serverPython/xml_ui/ui_dump.xml index 2bac089..3e6c30e 100644 --- a/serverPython/ui_dump.xml +++ b/serverPython/xml_ui/ui_dump.xml @@ -1,338 +1,338 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file