diff --git a/monitor.py b/monitor.py index 3c6ea7d..9db7d53 100644 --- a/monitor.py +++ b/monitor.py @@ -492,6 +492,9 @@ class MessageHistory: if not content or not content.strip(): return False + # 防御性编程:确保表存在 + self._ensure_user_messages_table() + cleaned_current = self._clean_text_for_dedup(content) if len(cleaned_current) < 2: # 太短无法比对 return False @@ -661,6 +664,9 @@ class MessageHistory: user_msg_time: 用户消息的时间戳(Unix时间),如果晚于最后bot回复时间,则视为新消息不跳过 """ + # 防御性编程:确保表存在 + self._ensure_bot_messages_table() + content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest() conn = self._get_conn() try: @@ -722,6 +728,9 @@ class MessageHistory: def last_bot_reply_time(self, platform: str) -> float: """获取该平台最近一次bot回复的时间戳(Unix时间)""" + # 防御性编程:确保表存在 + self._ensure_bot_messages_table() + conn = self._get_conn() try: cursor = conn.execute( @@ -746,6 +755,9 @@ class MessageHistory: Args: within_minutes: 只返回最近N分钟内的回复,None表示不过滤时间 """ + # 防御性编程:确保表存在 + self._ensure_bot_messages_table() + conn = self._get_conn() try: if within_minutes is not None and within_minutes > 0: @@ -821,6 +833,9 @@ class MessageHistory: def has_ocr_message_record(self, platform: str, content: str) -> bool: """检查OCR暂存表中是否已存在该消息的记录(用于时间戳新鲜度评分逻辑)""" + # 防御性编程:确保表存在 + self._ensure_ocr_staging_table() + content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest() conn = self._get_conn() try: