feat: add facebook automation bot logic and UI dump templates
This commit is contained in:
@@ -40,6 +40,13 @@ class FacebookBot:
|
|||||||
time.sleep(8) # Đợi load giao diện group
|
time.sleep(8) # Đợi load giao diện group
|
||||||
self.dump_ui_for_debug("fb_step1_open_group.xml")
|
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)
|
# 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...")
|
logging.info("Tìm nút Bình luận của bài viết đầu tiên...")
|
||||||
comment_btn = None
|
comment_btn = None
|
||||||
@@ -70,15 +77,24 @@ class FacebookBot:
|
|||||||
|
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
|
|
||||||
# Gõ nội dung
|
# Tìm ô nhập liệu "Viết bình luận công khai..."
|
||||||
logging.info("Đang nhập nội dung comment...")
|
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")
|
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:
|
if edit_box.exists:
|
||||||
edit_box.set_text(content)
|
edit_box.click()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
edit_box.set_text(content)
|
||||||
|
self.dump_ui_for_debug("fb_step7_text_entered.xml")
|
||||||
else:
|
else:
|
||||||
self.dump_ui_for_debug("error_fb_no_edittext.xml")
|
self.dump_ui_for_debug("error_fb_no_edit_box.xml")
|
||||||
return {"status": "error", "message": "Không tìm thấy ô nhập chữ."}
|
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ó
|
# Chọn ảnh nếu có
|
||||||
if has_image:
|
if has_image:
|
||||||
|
|||||||
Reference in New Issue
Block a user