feat: implement base Facebook bot logic in facebook_bot.py
This commit is contained in:
@@ -193,15 +193,38 @@ class FacebookBot:
|
|||||||
|
|
||||||
if send_btn.exists:
|
if send_btn.exists:
|
||||||
send_btn.click()
|
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
|
# 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:
|
if has_image:
|
||||||
logging.info("Đang dọn dẹp file ảnh tạm trên điện thoại...")
|
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")
|
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/')
|
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!"}
|
return {"status": "success", "message": "Đã comment thành công!"}
|
||||||
else:
|
else:
|
||||||
self.dump_ui_for_debug("error_fb_no_send_btn.xml")
|
self.dump_ui_for_debug("error_fb_no_send_btn.xml")
|
||||||
|
|||||||
Reference in New Issue
Block a user