74 lines
3.2 KiB
Python
74 lines
3.2 KiB
Python
from wechat_ipad import UserLoggedOut
|
|
from wechat_ipad.provider_base import WechatProviderBase
|
|
from wechat_ipad.providers.legacy_855.friend_circle import FriendCircleMixin
|
|
from wechat_ipad.providers.legacy_855.friends import FriendMixin
|
|
from wechat_ipad.providers.legacy_855.group import ChatroomMixin
|
|
from wechat_ipad.providers.legacy_855.login import LoginMixin
|
|
from wechat_ipad.providers.legacy_855.message import MessageMixin
|
|
from wechat_ipad.providers.legacy_855.runtime import Legacy855RuntimeMixin
|
|
from wechat_ipad.providers.legacy_855.tools import ToolMixin
|
|
from wechat_ipad.providers.legacy_855.user import UserMixin
|
|
from wechat_ipad.providers.legacy_855.base import WechatAPIClientBase
|
|
|
|
|
|
class Legacy855WechatClient(
|
|
LoginMixin,
|
|
MessageMixin,
|
|
FriendCircleMixin,
|
|
FriendMixin,
|
|
ChatroomMixin,
|
|
UserMixin,
|
|
ToolMixin,
|
|
Legacy855RuntimeMixin,
|
|
WechatProviderBase,
|
|
):
|
|
"""855/859 风格 server 的独立 Provider。
|
|
|
|
说明:
|
|
1. 这里不再直接依赖旧 `wechat_ipad/client/` 目录,而是将当前现网协议实现收口到独立 provider 目录;
|
|
2. 对外仍继续暴露与旧 `WechatAPIClient` 基本兼容的方法名,减少第一阶段替换成本;
|
|
3. 第二阶段接入 864 时,会新增独立 provider,而不是继续向本类堆条件分支。
|
|
"""
|
|
|
|
provider_name = "legacy_855"
|
|
server_type = "legacy_855"
|
|
|
|
def __init__(self, ip: str, port: int, **kwargs):
|
|
"""初始化 855 provider。
|
|
|
|
说明:
|
|
1. 旧 `wechat_ipad/client` 的多继承结构没有显式构造入口,迁移后这里补一个稳定初始化点;
|
|
2. 基础连接信息仍写入 `WechatAPIClientBase`,消息发送队列继续沿用 `MessageMixin` 的实现;
|
|
3. 运行时状态由 `Legacy855RuntimeMixin` 单独初始化,便于后续 864 provider 走自己的模型。
|
|
"""
|
|
del kwargs
|
|
WechatAPIClientBase.__init__(self, ip, port)
|
|
MessageMixin.__init__(self)
|
|
self._init_runtime_state()
|
|
|
|
async def run_login_health_check(self) -> bool:
|
|
"""执行 855 provider 的登录态巡检。"""
|
|
# 855 仍然保留“二次自动校验登录”的历史运维动作:
|
|
# 1. 这项逻辑本来就属于 855 provider 的登录模型,不应该继续挂在 Robot 上;
|
|
# 2. 这里直接复用 provider 内部现有 `twice_auto_auth` 能力,避免重新拆一套重复逻辑;
|
|
# 3. 上层系统任务只需要调用统一入口,不再关心底层到底是 855 还是别的 server。
|
|
return bool(await self.twice_auto_auth())
|
|
|
|
async def send_at_message(self, wxid: str, content: str, at: list[str]) -> tuple[int, int, int]:
|
|
"""发送 @ 消息,兼容现有插件调用方式。"""
|
|
if not self.wxid:
|
|
raise UserLoggedOut("请先登录")
|
|
|
|
output = ""
|
|
if wxid.endswith("@chatroom"):
|
|
for at_id in at:
|
|
nickname = await self.get_chatroom_nickname(at_id, wxid)
|
|
output += f"@{nickname}\u2005"
|
|
|
|
output += "\n"
|
|
output += content
|
|
else:
|
|
output = content
|
|
|
|
return await self.send_text_message(wxid, output, at)
|