This commit is contained in:
HuangHai
2026-01-26 20:11:13 +08:00
parent 37b5d5c431
commit faf5787f39

View File

@@ -63,6 +63,7 @@ class ChatMonitorBot:
self.input_pos = None self.input_pos = None
self.last_screen_hash = None self.last_screen_hash = None
self.last_processed_msg_hash = None self.last_processed_msg_hash = None
self.first_run = True # 标记是否为首次运行
self.check_interval = 3 # 检查频率 (秒) self.check_interval = 3 # 检查频率 (秒)
self.persona = ( self.persona = (
@@ -312,7 +313,12 @@ class ChatMonitorBot:
# E. 判断是否需要回复 (对方发送且非重复消息) # E. 判断是否需要回复 (对方发送且非重复消息)
sender = last_msg.get('sender', '') sender = last_msg.get('sender', '')
if sender != "": if sender != "":
if current_msg_hash != self.last_processed_msg_hash: if self.first_run:
# 首次运行时,记录最后一条消息的哈希但不回复,防止重启后重复回复历史消息
logger.info(f"🚦 [启动] 首次扫描,忽略已存在的最后一条消息: {last_msg}")
self.last_processed_msg_hash = current_msg_hash
self.first_run = False
elif current_msg_hash != self.last_processed_msg_hash:
event_shot = WxUtil.get_next_debug_path("event_new_msg") event_shot = WxUtil.get_next_debug_path("event_new_msg")
self.device.screenshot(event_shot) self.device.screenshot(event_shot)
logger.info(f"💡 [监控] 发现新消息: {last_msg},保存现场截图: {event_shot}") logger.info(f"💡 [监控] 发现新消息: {last_msg},保存现场截图: {event_shot}")
@@ -345,7 +351,11 @@ class ChatMonitorBot:
pass pass
else: else:
# 最后一条是我发送的 # 最后一条是我发送的
if current_msg_hash != self.last_processed_msg_hash: if self.first_run:
logger.info(f"🚦 [启动] 首次扫描,最后一条是自己发的,标记为已处理: {last_msg}")
self.last_processed_msg_hash = current_msg_hash
self.first_run = False
elif current_msg_hash != self.last_processed_msg_hash:
logger.info(f"⚪ [监控] 最后一条消息是自己发的,跳过回复: {last_msg}") logger.info(f"⚪ [监控] 最后一条消息是自己发的,跳过回复: {last_msg}")
self.last_processed_msg_hash = current_msg_hash self.last_processed_msg_hash = current_msg_hash