调整内容
This commit is contained in:
45
robot.py
45
robot.py
@@ -9,18 +9,12 @@ import random
|
||||
|
||||
from gewechat_client import GewechatClient
|
||||
|
||||
from base.func_doubao import Doubao
|
||||
from base.func_epic import is_friday, get_free
|
||||
from base.func_zhipu import ZhiPu
|
||||
|
||||
from base.func_chatgpt import ChatGPT
|
||||
from base.func_news import News
|
||||
from base.func_tigerbot import TigerBot
|
||||
from base.func_xinghuo_web import XinghuoWeb
|
||||
from base.func_claude import Claude
|
||||
from configuration import Config
|
||||
from constants import ChatType
|
||||
from gewechat.call_back_message.message import WxMessage, MessageType
|
||||
from utils.json_converter import json_to_object
|
||||
from utils.wechat.message_to_db import MessageStorage
|
||||
from plugin_common.event_system import EventType, EventSystem
|
||||
from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
@@ -56,6 +50,13 @@ class Robot(Job):
|
||||
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(
|
||||
@@ -216,7 +217,7 @@ class Robot(Job):
|
||||
self.message_count_to_db()
|
||||
if msg.content == "PDF":
|
||||
self.generate_sehuatang_pdf()
|
||||
if msg.content.startswith("清除群-"):
|
||||
if msg.content.raw_content.startswith("清除群-"):
|
||||
self.gbm.handle_command(msg.roomid, msg.content)
|
||||
else:
|
||||
self.toChitchat(msg) # 闲聊
|
||||
@@ -417,25 +418,25 @@ class Robot(Job):
|
||||
|
||||
# 初始化联系人数据库操作类
|
||||
contacts_db = ContactsDBOperator()
|
||||
|
||||
|
||||
# 将wxid列表分批处理,每批50个
|
||||
batch_size = 50
|
||||
for i in range(0, len(contacts_wxids), batch_size):
|
||||
batch_wxids = contacts_wxids[i:i + batch_size]
|
||||
|
||||
|
||||
# 批量获取联系人详细信息
|
||||
contact_info = self.client.get_detail_info(self.app_id, batch_wxids)
|
||||
|
||||
|
||||
# 处理返回的数据
|
||||
if contact_info and contact_info.get("ret") == 200 and "data" in contact_info:
|
||||
contact_data = contact_info.get("data", [])
|
||||
|
||||
|
||||
if contact_data:
|
||||
for contact in contact_data:
|
||||
user_name = contact.get("userName")
|
||||
if not user_name:
|
||||
continue
|
||||
|
||||
|
||||
try:
|
||||
# 判断联系人类型
|
||||
contact_type = "friends" # 默认为好友类型
|
||||
@@ -445,13 +446,13 @@ class Robot(Job):
|
||||
self.update_chatroom_member_details(user_name)
|
||||
elif user_name.startswith("gh_"):
|
||||
contact_type = "ghs"
|
||||
|
||||
|
||||
# 保存到数据库
|
||||
contacts_db.save_contacts([contact], contact_type)
|
||||
|
||||
|
||||
# 添加到返回字典
|
||||
contacts_dict[user_name] = contact.get("nickName") or user_name
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"处理联系人 {user_name} 失败: {e}")
|
||||
continue
|
||||
@@ -460,7 +461,7 @@ class Robot(Job):
|
||||
|
||||
self.LOG.info(f"成功获取并保存{len(contacts_dict)}个联系人信息")
|
||||
return contacts_dict
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"获取联系人信息失败: {e}")
|
||||
return {}
|
||||
@@ -472,10 +473,10 @@ class Robot(Job):
|
||||
members_response = self.client.get_chatroom_member_list(self.app_id, chatroom_id)
|
||||
if members_response and members_response.get('ret') == 200:
|
||||
member_list = members_response.get('data', {}).get('memberList', [])
|
||||
|
||||
|
||||
# 提取成员wxid列表
|
||||
member_wxids = [member.get('wxid') for member in member_list if member.get('wxid')]
|
||||
|
||||
|
||||
if member_wxids:
|
||||
# 按照官方接口格式传递参数
|
||||
details_response = self.client.get_chatroom_member_detail(
|
||||
@@ -483,17 +484,17 @@ class Robot(Job):
|
||||
chatroom_id,
|
||||
member_wxids # 直接传递列表,不需要转换为集合
|
||||
)
|
||||
|
||||
|
||||
# 使用ContactsDBOperator处理响应
|
||||
from db.contacts_db import ContactsDBOperator
|
||||
contacts_db = ContactsDBOperator()
|
||||
success = contacts_db.process_chatroom_member_detail_response(chatroom_id, details_response)
|
||||
|
||||
|
||||
if success:
|
||||
self.LOG.info(f"成功更新群聊{chatroom_id}的成员详细信息")
|
||||
else:
|
||||
self.LOG.error(f"更新群聊{chatroom_id}的成员详细信息失败")
|
||||
|
||||
|
||||
return success
|
||||
else:
|
||||
self.LOG.warning(f"群聊{chatroom_id}没有成员")
|
||||
|
||||
Reference in New Issue
Block a user