feat: implement FacebookBot class for automated group commenting using uiautomator2

This commit is contained in:
Victor Phan
2026-07-23 13:38:06 +07:00
parent 78bd883d3c
commit 7207afe50f
2 changed files with 19 additions and 6 deletions
+19 -6
View File
@@ -39,14 +39,27 @@ class FacebookBot:
self.d.shell(f'am start -a android.intent.action.VIEW -d "fb://group/{group_id}"')
time.sleep(8) # Đợi load giao diện group
# Tìm nút "Bình luận" của bài viết đầu tiên hiển thị
# 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...")
# Facebook dùng description hoặc text, thường là "Bình luận" hoặc "Comment"
comment_btn = self.d(descriptionContains="Bình luận")
if not comment_btn.exists:
comment_btn = self.d(descriptionContains="Comment")
comment_btn = None
for _ in range(7): # Thử vuốt tối đa 7 lần
# Thử quét bằng Regex (Không phân biệt hoa thường) ở cả description và text
c_desc_vn = self.d(descriptionMatches="(?i).*bình luận.*")
c_text_vn = self.d(textMatches="(?i).*bình luận.*")
c_desc_en = self.d(descriptionMatches="(?i).*comment.*")
c_text_en = self.d(textMatches="(?i).*comment.*")
if comment_btn.exists:
if c_desc_vn.exists: comment_btn = c_desc_vn; break
if c_text_vn.exists: comment_btn = c_text_vn; break
if c_desc_en.exists: comment_btn = c_desc_en; break
if c_text_en.exists: comment_btn = c_text_en; break
# Vuốt lên một chút
self.d.swipe_ext("up", scale=0.5)
time.sleep(1.5)
if comment_btn and comment_btn.exists:
comment_btn[0].click() # Click vào bài đầu tiên tìm thấy
else:
self.dump_ui_for_debug("error_fb_no_comment_btn.xml")