From a2bc25c08b76e7e5719619ad80f204bffcda5442 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 24 Apr 2023 10:57:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=8E=9F=E6=B6=88=E6=81=AF=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/qqbot/sources/nakuru.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/qqbot/sources/nakuru.py b/pkg/qqbot/sources/nakuru.py index d7fae72..1525e42 100644 --- a/pkg/qqbot/sources/nakuru.py +++ b/pkg/qqbot/sources/nakuru.py @@ -50,11 +50,13 @@ class NakuruProjectMessageConverter(MessageConverter): return nakuru_msg_list @staticmethod - def target2yiri(message_chain: typing.Any) -> mirai.MessageChain: + def target2yiri(message_chain: typing.Any, message_id: int = -1) -> mirai.MessageChain: """将Yiri的消息链转换为YiriMirai的消息链""" assert type(message_chain) is list yiri_msg_list = [] + import datetime + yiri_msg_list.append(mirai.models.message.Source(id=message_id, time=datetime.datetime.now())) for component in message_chain: if type(component) is nkc.Plain: yiri_msg_list.append(mirai.Plain(text=component.text)) @@ -69,7 +71,8 @@ class NakuruProjectMessageConverter(MessageConverter): else: pass logging.debug("转换后的消息链: " + str(yiri_msg_list)) - return mirai.MessageChain(yiri_msg_list) + chain = mirai.MessageChain(yiri_msg_list) + return chain class NakuruProjectEventConverter(EventConverter): @@ -85,6 +88,7 @@ class NakuruProjectEventConverter(EventConverter): @staticmethod def target2yiri(event: typing.Any) -> mirai.Event: + yiri_chain = NakuruProjectMessageConverter.target2yiri(event.message, event.message_id) if type(event) is nakuru.FriendMessage: return mirai.FriendMessage( sender=mirai.models.entities.Friend( @@ -92,7 +96,7 @@ class NakuruProjectEventConverter(EventConverter): nickname=event.sender.nickname, remark=event.sender.nickname ), - message_chain=NakuruProjectMessageConverter.target2yiri(event.message), + message_chain=yiri_chain, time=event.time ) elif type(event) is nakuru.GroupMessage: @@ -119,7 +123,7 @@ class NakuruProjectEventConverter(EventConverter): last_speak_timestamp=0, mute_time_remaining=0, ), - message_chain=NakuruProjectMessageConverter.target2yiri(event.message), + message_chain=yiri_chain, time=event.time ) else: @@ -176,16 +180,23 @@ class NakuruProjectAdapter(MessageSourceAdapter): message: mirai.MessageChain, quote_origin: bool = False ): + message = self.message_converter.yiri2target(message) + if quote_origin: + # 在前方添加引用组件 + message.insert(0, nkc.Reply( + id=message_source.message_chain.message_id, + ) + ) if type(message_source) is mirai.GroupMessage: task = self.bot.sendGroupMessage( message_source.sender.group.id, - self.message_converter.yiri2target(message), + message, # quote=message_source.message_id if quote_origin else None ) elif type(message_source) is mirai.FriendMessage: task = self.bot.sendFriendMessage( message_source.sender.id, - self.message_converter.yiri2target(message), + message, # quote=message_source.message_id if quote_origin else None ) else: