From 6d3eca60da633e3bed44a553ee2edd3729c8c1e0 Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 22 Apr 2025 15:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/robot.py b/robot.py index f11d0d8..3e82b30 100644 --- a/robot.py +++ b/robot.py @@ -47,18 +47,6 @@ class Robot(Job): self.config = config self.LOG = logging.getLogger("Robot") - # 初始化联系人管理器并设置联系人 - self.contact_manager = ContactManager.get_instance() - self.allContacts = self.get_all_contacts() - self.contact_manager.set_contacts(self.allContacts) - - # 获取个人信息 - obj = json_to_object(self.client.get_profile(self.app_id)) - if obj.data.wxid is None: - self.LOG.info(f"获取个人信息失败,退出程序!") - return - self.wxid = obj.data.wxid - self.LOG.info(f"DB+REDIS 连接池开始初始化") # 使用单例模式获取实例 self.db_manager = DBConnectionManager.get_instance( @@ -71,6 +59,19 @@ class Robot(Job): self.db_pool = self.db_manager.mysql_pool self.redis_pool = self.db_manager.redis_pool + # 初始化联系人管理器并设置联系人 + self.contact_manager = ContactManager.get_instance() + self.allContacts = self.get_all_contacts() + self.contact_manager.set_contacts(self.allContacts) + + self.contacts_db = ContactsDBOperator(self.db_manager) + # 获取个人信息 + obj = json_to_object(self.client.get_profile(self.app_id)) + if obj.data.wxid is None: + self.LOG.info(f"获取个人信息失败,退出程序!") + return + self.wxid = obj.data.wxid + # 初始化消息工具类 - 使用联系人管理器 self.message_util = MessageUtil(app_id, client) self.groups = {} # 存储按group_id分组的消息列表,每个group_id最多保留10条消息 @@ -106,7 +107,6 @@ class Robot(Job): # 消息存档模块初始化,自动完成入库动作 self.message_storage = MessageStorage(self.client) - self.contacts_db = ContactsDBOperator(self.db_manager) @staticmethod def value_check(args: dict) -> bool: if args: @@ -425,7 +425,7 @@ class Robot(Job): friends = contact_data.get("friends", []) for wxid in friends: contacts_dict[wxid] = wxid # 默认使用wxid作为昵称 - + # 处理群聊列表 chatrooms = contact_data.get("chatrooms", []) for chatroom_id in chatrooms: