Merge pull request #27 from omg-xtao:omg-xtao-patch-1

feat(recall notice): support msg recall notice
This commit is contained in:
XYenon 2022-03-09 21:03:11 +08:00 committed by GitHub
commit 661dc91104
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,9 +26,10 @@ from ehforwarderbot.exceptions import (
EFBMessageError, EFBMessageError,
EFBOperationNotSupported, EFBOperationNotSupported,
) )
from ehforwarderbot.chat import GroupChat
from ehforwarderbot.message import MessageCommand, MessageCommands from ehforwarderbot.message import MessageCommand, MessageCommands
from ehforwarderbot.status import MessageRemoval from ehforwarderbot.status import MessageRemoval
from ehforwarderbot.types import ChatID from ehforwarderbot.types import ChatID, MessageID
from ehforwarderbot.utils import extra from ehforwarderbot.utils import extra
from PIL import Image from PIL import Image
from pkg_resources import resource_filename from pkg_resources import resource_filename
@ -236,13 +237,13 @@ class GoCQHttp(BaseClient):
if main_text != "": if main_text != "":
messages.append(self.msg_decorator.qq_text_simple_wrapper(main_text, at_dict)) messages.append(self.msg_decorator.qq_text_simple_wrapper(main_text, at_dict))
uid: str = str(uuid.uuid4())
coolq_msg_id = context["message_id"] coolq_msg_id = context["message_id"]
for i in range(len(messages)): for i in range(len(messages)):
if not isinstance(messages[i], Message): if not isinstance(messages[i], Message):
continue continue
efb_msg: Message = messages[i] efb_msg: Message = messages[i]
efb_msg.uid = uid + "_" + str(coolq_msg_id) + "_" + str(i) efb_msg.uid = f"{chat.uid.split('_')[-1]}_{coolq_msg_id}_{i}" if i > 0 else \
f"{chat.uid.split('_')[-1]}_{coolq_msg_id}"
efb_msg.chat = chat efb_msg.chat = chat
efb_msg.author = author efb_msg.author = author
# if qq_uid != '80000000': # if qq_uid != '80000000':
@ -358,6 +359,35 @@ class GoCQHttp(BaseClient):
context["message"] = text context["message"] = text
self.send_msg_to_master(context) self.send_msg_to_master(context)
@self.coolq_bot.on_notice("group_recall")
def handle_group_recall_msg(context):
coolq_msg_id = context["message_id"]
chat = GroupChat(channel=self.channel, uid=f"group_{context['group_id']}")
efb_msg = Message(
chat=chat,
uid=MessageID(f"{chat.uid.split('_')[-1]}_{coolq_msg_id}")
)
coordinator.send_status(MessageRemoval(source_channel=self.channel,
destination_channel=coordinator.master,
message=efb_msg))
@self.coolq_bot.on_notice("friend_recall")
def handle_friend_recall_msg(context):
coolq_msg_id = context["message_id"]
try:
chat: PrivateChat = self.chat_manager.build_efb_chat_as_private(context)
except:
return
efb_msg = Message(
chat=chat,
uid=MessageID(f"{chat.uid.split('_')[-1]}_{coolq_msg_id}")
)
coordinator.send_status(MessageRemoval(source_channel=self.channel,
destination_channel=coordinator.master,
message=efb_msg))
@self.coolq_bot.on_request("friend") # Add friend request @self.coolq_bot.on_request("friend") # Add friend request
def handle_add_friend_request(context): def handle_add_friend_request(context):
self.logger.debug(repr(context)) self.logger.debug(repr(context))
@ -736,7 +766,7 @@ class GoCQHttp(BaseClient):
def coolq_send_message(self, msg_type, uid, message): def coolq_send_message(self, msg_type, uid, message):
keyword = msg_type if msg_type != "private" else "user" keyword = msg_type if msg_type != "private" else "user"
res = self.coolq_api_query("send_msg", message_type=msg_type, **{keyword + "_id": uid}, message=message) res = self.coolq_api_query("send_msg", message_type=msg_type, **{keyword + "_id": uid}, message=message)
return str(uuid.uuid4()) + "_" + str(res["message_id"]) return str(uid) + "_" + str(res["message_id"])
def _coolq_api_wrapper(self, func_name, **kwargs): def _coolq_api_wrapper(self, func_name, **kwargs):
try: try: