任务#1441: 修复bot自言自语和双重回复问题
**问题1: 自言自语** - OCR把bot自己的回复再读一遍,当成新消息触发二次回复 - 修复: 查库对比bot历史回复,重合率≥50%(高分消息)或≥70%(普通消息)则丢弃 **问题2: 双重回复** - 用户操作电脑打断bot回复发送时,_last_hash_replied标志被重置,下次轮询重复触发 - 修复: 新增_reply_in_progress标志,回复进行中时跳过所有轮询处理 **修改文件:** - monitor.py: 添加_reply_in_progress状态追踪+动态阈值bot消息过滤 - gui.py: 在回复执行前后设置/清除_reply_in_progress标志 - _keyword_scorer.py: 新增get_last_score()方法用于查询得分而不记录
This commit is contained in:
@@ -187,6 +187,23 @@ class KeywordScorer:
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def get_last_score(self, platform: str, text: str) -> int:
|
||||
"""获取指定文本最近一次的关键词得分(不记录新行)"""
|
||||
keywords = self.extract_keywords(text)
|
||||
if not keywords:
|
||||
return 0
|
||||
conn = sqlite3.connect(self.db_path, check_same_thread=False)
|
||||
try:
|
||||
cursor = conn.execute("""
|
||||
SELECT score FROM keyword_scores
|
||||
WHERE platform = ? AND message_text = ?
|
||||
ORDER BY id DESC LIMIT 1
|
||||
""", (platform, text.strip()))
|
||||
row = cursor.fetchone()
|
||||
return row[0] if row else 0
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def should_skip_message(self, text: str, platform: str,
|
||||
ocr_time: Optional[str] = None,
|
||||
threshold: int = 2) -> Tuple[bool, int, List[str]]:
|
||||
|
||||
Reference in New Issue
Block a user