From 6affc44148f4704ea5a40ae346faf99b65f42f9f Mon Sep 17 00:00:00 2001 From: wongxy Date: Sun, 18 Oct 2020 12:46:59 +0800 Subject: [PATCH] feat(action): reply msg --- botoy/__version__.py | 2 +- botoy/action.py | 67 ++++++++++++++++++++++++++++++++++++ botoy/async_action.py | 67 ++++++++++++++++++++++++++++++++++++ botoy/decorators/__init__.py | 2 +- docs/action.md | 2 ++ 5 files changed, 138 insertions(+), 2 deletions(-) diff --git a/botoy/__version__.py b/botoy/__version__.py index 156d6f9a..eead3198 100644 --- a/botoy/__version__.py +++ b/botoy/__version__.py @@ -1 +1 @@ -__version__ = '0.0.4' +__version__ = '0.0.5' diff --git a/botoy/action.py b/botoy/action.py index 998b47b3..36d75fb3 100644 --- a/botoy/action.py +++ b/botoy/action.py @@ -1,3 +1,4 @@ +import time import traceback from typing import List, Union @@ -247,6 +248,72 @@ def sendPhoneText(self, content: str): {"SendToType": 2, "SendMsgType": "PhoneMsg", "Content": content}, ) + def replyGroupMsg( + self, + group: int, + content: str, + msgSeq: int, + msgTime: int = None, + user: int = 0, + rawContent: str = '', + ): + """发送回复消息, 回复群消息 + 下面的原消息表示需要回复的消息 + :param group: 原消息的群号 + :param content: 回复内容 + :param msgSeq: 原消息的msgSeq, 点击跳转到该条消息位置 + :param msgTime: 原消息的msgTime, 如果不指定,默认为当前时间戳 + :param user: 原消息的人的qq号,也可以是其他人,该用户收到消息会提示“有新回复”, 默认为0 + :param rawContent: 原消息内容,可以任意指定,默认为空 + """ + return self.post( + "SendMsg", + { + "toUser": group, + "sendToType": 2, + "sendMsgType": "ReplayMsg", + "content": content, + "replayInfo": { + "MsgSeq": msgSeq, + "MsgTime": msgTime or int(time.time()), + "UserID": user, + "RawContent": rawContent, + }, + }, + ) + + def replyFriendMsg( + self, + user: int, + content: str, + msgSeq: int, + msgTime: int = None, + rawContent: str = '', + ): + """发送回复消息, 回复好友消息 + 下面的原消息表示需要回复的消息 + :param user: 原消息发送人 + :param content: 回复内容 + :param msgSeq: 原消息的msgSeq, 点击跳转到该条消息位置 + :param msgTime: 原消息的msgTime, 如果不指定,默认为当前时间戳 + :param rawContent: 原消息内容,可以任意指定,默认为空 + """ + return self.post( + "SendMsg", + { + "toUser": user, + "sendToType": 1, + "sendMsgType": "ReplayMsg", + "content": content, + "replayInfo": { + "MsgSeq": msgSeq, + "MsgTime": msgTime or int(time.time()), + "UserID": user, + "RawContent": rawContent, + }, + }, + ) + ############获取############ def getCookies(self): """获取QQ相关cookie""" diff --git a/botoy/async_action.py b/botoy/async_action.py index d12e8e3d..e62933c1 100644 --- a/botoy/async_action.py +++ b/botoy/async_action.py @@ -1,3 +1,4 @@ +import time import traceback from typing import List, Union @@ -247,6 +248,72 @@ async def sendPhoneText(self, content: str) -> dict: {"SendToType": 2, "SendMsgType": "PhoneMsg", "Content": content}, ) + async def replyGroupMsg( + self, + group: int, + content: str, + msgSeq: int, + msgTime: int = None, + user: int = 0, + rawContent: str = '', + ): + """发送回复消息, 回复群消息 + 下面的原消息表示需要回复的消息 + :param group: 原消息的群号 + :param content: 回复内容 + :param msgSeq: 原消息的msgSeq, 点击跳转到该条消息位置 + :param msgTime: 原消息的msgTime, 如果不指定,默认为当前时间戳 + :param user: 原消息的人的qq号,也可以是其他人,该用户收到消息会提示“有新回复”, 默认为0 + :param rawContent: 原消息内容,可以任意指定,默认为空 + """ + return await self.post( + "SendMsg", + { + "toUser": group, + "sendToType": 2, + "sendMsgType": "ReplayMsg", + "content": content, + "replayInfo": { + "MsgSeq": msgSeq, + "MsgTime": msgTime or int(time.time()), + "UserID": user, + "RawContent": rawContent, + }, + }, + ) + + async def replyFriendMsg( + self, + user: int, + content: str, + msgSeq: int, + msgTime: int = None, + rawContent: str = '', + ): + """发送回复消息, 回复好友消息 + 下面的原消息表示需要回复的消息 + :param user: 原消息发送人 + :param content: 回复内容 + :param msgSeq: 原消息的msgSeq, 点击跳转到该条消息位置 + :param msgTime: 原消息的msgTime, 如果不指定,默认为当前时间戳 + :param rawContent: 原消息内容,可以任意指定,默认为空 + """ + return await self.post( + "SendMsg", + { + "toUser": user, + "sendToType": 1, + "sendMsgType": "ReplayMsg", + "content": content, + "replayInfo": { + "MsgSeq": msgSeq, + "MsgTime": msgTime or int(time.time()), + "UserID": user, + "RawContent": rawContent, + }, + }, + ) + async def setUniqueTitle(self, user: int, group: int, title: str): """设置群头衔""" return await self.post( diff --git a/botoy/decorators/__init__.py b/botoy/decorators/__init__.py index 104507a9..69b314e8 100644 --- a/botoy/decorators/__init__.py +++ b/botoy/decorators/__init__.py @@ -1,4 +1,5 @@ """一些用于接收函数的装饰器""" +from ._ensure_tempMsg import ensure_tempMsg from ._equal_content import equal_content from ._from_botself import from_botself from ._from_these_groups import from_these_groups @@ -10,4 +11,3 @@ from ._startswith import startswith from ._these_msgtypes import these_msgtypes from ._with_pattern import with_pattern -from ._ensure_tempMsg import ensure_tempMsg diff --git a/docs/action.md b/docs/action.md index 3357d76c..d02a969e 100644 --- a/docs/action.md +++ b/docs/action.md @@ -83,6 +83,8 @@ port 和 host 的含义和 Botoy 实例中的一致 | setGroupAnnounce | 设置群公告 | | toggleGroupAdmin | 设置或取消群管理员 | | revokeGroupMsg | 撤回群消息 | +| replyGroupMsg | 发送回复消息,回复群消息 | +| replyFriendMsg | 发送回复消息,回复好友消息,不好用 | | | 搜索群组 | | | 获取群管理列表 | | | 获取包括群主在内的所有管理员列表 |