先初始化数据库
This commit is contained in:
28
robot.py
28
robot.py
@@ -47,18 +47,6 @@ class Robot(Job):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.LOG = logging.getLogger("Robot")
|
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.LOG.info(f"DB+REDIS 连接池开始初始化")
|
||||||
# 使用单例模式获取实例
|
# 使用单例模式获取实例
|
||||||
self.db_manager = DBConnectionManager.get_instance(
|
self.db_manager = DBConnectionManager.get_instance(
|
||||||
@@ -71,6 +59,19 @@ class Robot(Job):
|
|||||||
self.db_pool = self.db_manager.mysql_pool
|
self.db_pool = self.db_manager.mysql_pool
|
||||||
self.redis_pool = self.db_manager.redis_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.message_util = MessageUtil(app_id, client)
|
||||||
self.groups = {} # 存储按group_id分组的消息列表,每个group_id最多保留10条消息
|
self.groups = {} # 存储按group_id分组的消息列表,每个group_id最多保留10条消息
|
||||||
@@ -106,7 +107,6 @@ class Robot(Job):
|
|||||||
# 消息存档模块初始化,自动完成入库动作
|
# 消息存档模块初始化,自动完成入库动作
|
||||||
self.message_storage = MessageStorage(self.client)
|
self.message_storage = MessageStorage(self.client)
|
||||||
|
|
||||||
self.contacts_db = ContactsDBOperator(self.db_manager)
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def value_check(args: dict) -> bool:
|
def value_check(args: dict) -> bool:
|
||||||
if args:
|
if args:
|
||||||
@@ -425,7 +425,7 @@ class Robot(Job):
|
|||||||
friends = contact_data.get("friends", [])
|
friends = contact_data.get("friends", [])
|
||||||
for wxid in friends:
|
for wxid in friends:
|
||||||
contacts_dict[wxid] = wxid # 默认使用wxid作为昵称
|
contacts_dict[wxid] = wxid # 默认使用wxid作为昵称
|
||||||
|
|
||||||
# 处理群聊列表
|
# 处理群聊列表
|
||||||
chatrooms = contact_data.get("chatrooms", [])
|
chatrooms = contact_data.get("chatrooms", [])
|
||||||
for chatroom_id in chatrooms:
|
for chatroom_id in chatrooms:
|
||||||
|
|||||||
Reference in New Issue
Block a user