diff --git a/ai_chat.db b/ai_chat.db index 28aa0fe..4d26ed5 100644 Binary files a/ai_chat.db and b/ai_chat.db differ diff --git a/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.blacklisted_devices b/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.blacklisted_devices new file mode 100644 index 0000000..e69de29 diff --git a/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.ignored_devices b/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.ignored_devices new file mode 100644 index 0000000..e69de29 diff --git a/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.trusted_devices b/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.trusted_devices new file mode 100644 index 0000000..7c4b473 --- /dev/null +++ b/matrix_store/@tester:matrix.tphai.com_BDTRXIGPBE.trusted_devices @@ -0,0 +1,7 @@ +@tester:matrix.tphai.com AJFVRTHLJY matrix-ed25519 4mRjLhM8xbwjkwQP2T/iB3UZJoaADgP6cCVUiB8AtSk +@tester:matrix.tphai.com GVSFGGYNJL matrix-ed25519 8qV2own4G3m2nki+izFDBOrAxtbGl8RoneM3qUPkThU +@tester:matrix.tphai.com IMEQIQPXTR matrix-ed25519 6Yd4lmhP6jdkkNvh1rIw6TRK331ZUyiAt5G5hPeYqSE +@tester:matrix.tphai.com MIPPYHRVAS matrix-ed25519 s8Ol56sxLCjCOi0Gkv/Kj7LqVMp/8ZmuAJ6QA1rUi7o +@tester:matrix.tphai.com UKJGJYQQLT matrix-ed25519 opC9rhsz1nzrvQqNWMKTF5FxWIGuHTDfixx+q/Y8ea0 +@tester:matrix.tphai.com UPMZGRLESG matrix-ed25519 86c6XPCIYHgesq83C2k5xhXNa0EYMnqTq4jFrTwJX8I +@huangzhuang_bro:matrix.tphai.com BQHGFLQEPR matrix-ed25519 IrEHmvqotfHKLyx1JRJp4RthUVyBT8qQX72qBifRRyQ diff --git a/services/__pycache__/matrix_service.cpython-310.pyc b/services/__pycache__/matrix_service.cpython-310.pyc index 6fe022c..9f15698 100644 Binary files a/services/__pycache__/matrix_service.cpython-310.pyc and b/services/__pycache__/matrix_service.cpython-310.pyc differ diff --git a/services/matrix_service.py b/services/matrix_service.py index 45e0121..2cb4143 100644 --- a/services/matrix_service.py +++ b/services/matrix_service.py @@ -26,6 +26,7 @@ class MatrixBot: self.is_running: bool = False self.on_message_callback: Optional[Callable] = None self.last_room_id: str = "" + self.processed_events: set = set() # 已处理的事件ID,防止重复处理 async def init_from_config(self): """从数据库配置初始化""" @@ -171,6 +172,20 @@ class MatrixBot: async def _process_message(self, room, sender, message_text, event_id): """处理消息的核心逻辑""" + # 检查是否已处理过此事件(防止重复处理) + if event_id in self.processed_events: + logger.debug(f"忽略已处理的事件: {event_id}") + return + + # 标记为已处理 + self.processed_events.add(event_id) + logger.info(f"处理消息: event_id={event_id}") + + # 限制集合大小,保留最近的100个 + if len(self.processed_events) > 100: + # 清理旧的一半 + self.processed_events = set(list(self.processed_events)[-50:]) + # 忽略自己发送的消息 if sender == self.user_id: logger.debug(f"忽略自己发送的消息: {sender}")