feat: add facebook automation bot logic and UI dump templates

This commit is contained in:
Victor Phan
2026-07-23 14:02:14 +07:00
parent f558e00fb1
commit ae91f5262c
6 changed files with 1115 additions and 1099 deletions
+21 -5
View File
@@ -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: