49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from wechat_ipad import UserLoggedOut
|
|
from wechat_ipad.client.friend_circle import FriendCircleMixin
|
|
from wechat_ipad.client.firends import FriendMixin
|
|
from wechat_ipad.client.group import ChatroomMixin
|
|
from wechat_ipad.client.login import LoginMixin
|
|
from wechat_ipad.client.message import MessageMixin
|
|
from wechat_ipad.client.tools import ToolMixin
|
|
from wechat_ipad.client.user import UserMixin
|
|
|
|
|
|
class WechatAPIClient(LoginMixin, MessageMixin, FriendCircleMixin, FriendMixin, ChatroomMixin, UserMixin,
|
|
ToolMixin):
|
|
|
|
# 这里都是需要结合多个功能的方法
|
|
|
|
async def send_at_message(self, wxid: str, content: str, at: list[str]) -> tuple[int, int, int]:
|
|
"""发送@消息
|
|
|
|
Args:
|
|
wxid (str): 接收人
|
|
content (str): 消息内容
|
|
at (list[str]): 要@的用户ID列表
|
|
|
|
Returns:
|
|
tuple[int, int, int]: 包含以下三个值的元组:
|
|
- ClientMsgid (int): 客户端消息ID
|
|
- CreateTime (int): 创建时间
|
|
- NewMsgId (int): 新消息ID
|
|
|
|
Raises:
|
|
UserLoggedOut: 用户未登录时抛出
|
|
BanProtection: 新设备登录4小时内操作时抛出
|
|
"""
|
|
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)
|