From 193a15d54e6fa7928fa7d60e1e0c3945271a7e21 Mon Sep 17 00:00:00 2001 From: Victor Phan Date: Thu, 23 Jul 2026 15:39:36 +0700 Subject: [PATCH] feat: implement base Facebook bot logic in facebook_bot.py --- serverPython/facebook_bot.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/serverPython/facebook_bot.py b/serverPython/facebook_bot.py index c160fcd..e2b2e05 100644 --- a/serverPython/facebook_bot.py +++ b/serverPython/facebook_bot.py @@ -193,15 +193,38 @@ class FacebookBot: if send_btn.exists: send_btn.click() - time.sleep(3) + + # Chờ trạng thái "Đang đăng..." biến mất (tối đa 20 giây) + logging.info("Đang chờ Facebook xử lý đăng bình luận...") + for _ in range(20): + if not self.d(textContains="Đang đăng").exists and not self.d(descriptionContains="Đang đăng").exists and not self.d(textContains="Posting").exists: + break + time.sleep(1) + + # Chờ thêm 2 giây để giao diện cập nhật kết quả cuối cùng + time.sleep(2) + self.dump_ui_for_debug("fb_step8_post_result.xml") # Dọn dẹp bộ nhớ cho điện thoại: xóa file ảnh ngay lập tức sau khi post xong if has_image: logging.info("Đang dọn dẹp file ảnh tạm trên điện thoại...") self.d.shell("rm -f /sdcard/Pictures/n8n_fb_*.jpg") - # Cập nhật lại thư viện ảnh để nó xóa hẳn khỏi Gallery self.d.shell('am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file:///sdcard/Pictures/') + # Kiểm tra xem bình luận có bị đánh spam hoặc cấm không + if self.d(textContains="Đã từ chối").exists or self.d(descriptionContains="Đã từ chối").exists: + logging.error("THẤT BẠI: Bình luận bị Facebook TỪ CHỐI (có thể do link spam hoặc vi phạm tiêu chuẩn).") + return {"status": "error", "message": "Bình luận bị Facebook từ chối (Spam/Vi phạm)."} + + if self.d(textContains="Không thể đăng").exists or self.d(descriptionContains="Không thể đăng").exists: + logging.error("THẤT BẠI: Facebook chặn, không thể đăng bình luận.") + return {"status": "error", "message": "Facebook chặn không cho đăng bình luận."} + + if self.d(textContains="Phê duyệt").exists or self.d(textContains="phê duyệt").exists: + logging.info("THÀNH CÔNG (NHƯNG CHỜ DUYỆT): Bình luận đã gửi và đang chờ Quản trị viên duyệt.") + return {"status": "success", "message": "Đã gửi bình luận (Đang chờ duyệt)."} + + logging.info("THÀNH CÔNG: Đã đăng bình luận hoàn tất!") return {"status": "success", "message": "Đã comment thành công!"} else: self.dump_ui_for_debug("error_fb_no_send_btn.xml")