全局geweclient
This commit is contained in:
20
robot.py
20
robot.py
@@ -10,6 +10,7 @@ from base.func_epic import is_friday, get_free
|
||||
from base.func_news import News
|
||||
from configuration import Config
|
||||
from gewechat.call_back_message.message import WxMessage, MessageType
|
||||
from gewechat.client import gewe_client
|
||||
from utils.json_converter import json_to_object
|
||||
from utils.wechat.message_to_db import MessageStorage
|
||||
from plugin_common.event_system import EventType, EventSystem
|
||||
@@ -37,9 +38,8 @@ class Robot(Job):
|
||||
"""个性化自己的机器人
|
||||
"""
|
||||
|
||||
def __init__(self, config: Config, app_id: str, client: GewechatClient, chat_type: int) -> None:
|
||||
self.app_id = app_id
|
||||
self.client = client
|
||||
def __init__(self, config: Config) -> None:
|
||||
self.client = gewe_client
|
||||
self.config = config
|
||||
self.LOG = logging.getLogger("Robot")
|
||||
|
||||
@@ -62,14 +62,14 @@ class Robot(Job):
|
||||
self.contact_manager.set_contacts(self.allContacts)
|
||||
|
||||
# 获取个人信息
|
||||
obj = json_to_object(self.client.get_profile(self.app_id))
|
||||
obj = json_to_object(self.client.get_profile(self.client.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()
|
||||
self.groups = {} # 存储按group_id分组的消息列表,每个group_id最多保留10条消息
|
||||
GroupBotManager.load_local_cache()
|
||||
|
||||
@@ -85,7 +85,7 @@ class Robot(Job):
|
||||
# 设置插件系统上下文
|
||||
self.system_context = {
|
||||
"config": config,
|
||||
"client": client,
|
||||
"client": gewe_client,
|
||||
"event_system": self.event_system,
|
||||
"plugin_registry": self.plugin_registry,
|
||||
"db_pool": self.db_pool,
|
||||
@@ -151,8 +151,6 @@ class Robot(Job):
|
||||
# 设置ROBOT功能为启用状态
|
||||
GroupBotManager.set_group_permission(msg.roomid, Feature.ROBOT, PermissionStatus.ENABLED)
|
||||
# 更新联系人信息
|
||||
# 如果是加入新群,则拉取群用户信息,并且将群加入联系人
|
||||
self.client.get_chatroom_info(self.app_id, msg.roomid)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"加入新群,自动添加并开启机器人功能 error: {e}")
|
||||
|
||||
@@ -468,7 +466,7 @@ class Robot(Job):
|
||||
batch_wxids = wxids[i:i + batch_size]
|
||||
|
||||
# 批量获取联系人详细信息
|
||||
contact_info = self.client.get_detail_info(self.app_id, batch_wxids)
|
||||
contact_info = self.client.get_detail_info(self.client.app_id, batch_wxids)
|
||||
self.LOG.info(f"获取联系人详细信息响应: {contact_info}")
|
||||
# 处理返回的数据
|
||||
if contact_info and contact_info.get("ret") == 200 and "data" in contact_info:
|
||||
@@ -507,7 +505,7 @@ class Robot(Job):
|
||||
"""更新群成员详细信息"""
|
||||
try:
|
||||
# 首先获取群成员列表
|
||||
members_response = self.client.get_chatroom_member_list(self.app_id, chatroom_id)
|
||||
members_response = self.client.get_chatroom_member_list(self.client.app_id, chatroom_id)
|
||||
if members_response and members_response.get('ret') == 200:
|
||||
member_list = members_response.get('data', {}).get('memberList', [])
|
||||
|
||||
@@ -517,7 +515,7 @@ class Robot(Job):
|
||||
if member_wxids:
|
||||
# 按照官方接口格式传递参数
|
||||
details_response = self.client.get_chatroom_member_detail(
|
||||
self.app_id,
|
||||
self.client.app_id,
|
||||
chatroom_id,
|
||||
member_wxids # 直接传递列表,不需要转换为集合
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user