看板内容进行优化,同时加入了用户管理模块,将用户信息全局开放,
This commit is contained in:
22
robot.py
22
robot.py
@@ -37,6 +37,7 @@ from robot_cmd.robot_command import PermissionStatus
|
||||
__version__ = "39.2.4.0"
|
||||
|
||||
from sehuatang.shehuatang import pdf_file_path
|
||||
from utils.wechat.contact_manager import ContactManager
|
||||
from xiuren.meitu_dl import meitu_dowload_pub_pic
|
||||
from xiuren.xiuren_pdf import generate_pdf_from_images
|
||||
|
||||
@@ -54,8 +55,11 @@ class Robot(Job):
|
||||
self.LOG = logging.getLogger("Robot")
|
||||
|
||||
self.wxid = self.wcf.get_self_wxid()
|
||||
# 初始化联系人管理器并设置联系人
|
||||
self.contact_manager = ContactManager.get_instance()
|
||||
self.allContacts = self.get_all_contacts()
|
||||
# 修改初始化方法中的这一部分
|
||||
self.contact_manager.set_contacts(self.allContacts)
|
||||
|
||||
self.LOG.info(f"DB+REDIS 连接池开始初始化")
|
||||
# 使用单例模式获取实例
|
||||
self.db_manager = DBConnectionManager.get_instance(
|
||||
@@ -68,8 +72,8 @@ class Robot(Job):
|
||||
self.db_pool = self.db_manager.mysql_pool
|
||||
self.redis_pool = self.db_manager.redis_pool
|
||||
|
||||
# 初始化消息工具类
|
||||
self.message_util = MessageUtil(wcf, self.allContacts)
|
||||
# 初始化消息工具类 - 使用联系人管理器
|
||||
self.message_util = MessageUtil(wcf, self.contact_manager)
|
||||
self.groups = {} # 存储按group_id分组的消息列表,每个group_id最多保留10条消息
|
||||
GroupBotManager.load_local_cache()
|
||||
|
||||
@@ -391,10 +395,11 @@ class Robot(Job):
|
||||
def say_hi_to_new_friend(self, msg: WxMsg) -> None:
|
||||
nickName = re.findall(r"你已添加了(.*),现在可以开始聊天了。", msg.content)
|
||||
if nickName:
|
||||
# 添加了好友,更新好友列表
|
||||
# 添加了好友,更新好友列表和联系人管理器
|
||||
self.allContacts[msg.sender] = nickName[0]
|
||||
self.contact_manager.update_contact(msg.sender, nickName[0])
|
||||
self.send_text_msg(f"Hi {nickName[0]},我自动通过了你的好友请求。", msg.sender)
|
||||
|
||||
|
||||
def send_group_txt_message(self, msg: str, feature: Feature):
|
||||
try:
|
||||
receivers = self.gbm.get_group_list()
|
||||
@@ -545,3 +550,10 @@ class Robot(Job):
|
||||
self.wcf.send_file(pub_path, "45317011307@chatroom")
|
||||
except Exception as e:
|
||||
self.LOG.error(f"xiu_ren_pdf_send error:{e}")
|
||||
|
||||
# 添加一个方法用于刷新联系人信息
|
||||
def refresh_contacts(self):
|
||||
"""刷新联系人信息"""
|
||||
self.allContacts = self.get_all_contacts()
|
||||
self.contact_manager.refresh_contacts(self.allContacts)
|
||||
self.LOG.info("联系人信息已刷新")
|
||||
|
||||
Reference in New Issue
Block a user