From 7fb711413a6e7ad45136f2d14334cade27222479 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sat, 10 Aug 2024 04:13:24 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=9C=AA=E6=9B=B4=E6=96=B0=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/platform/manager.py | 4 ++-- model/platform/qq_nakuru.py | 18 +++++++++++++++--- model/platform/qq_official.py | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/model/platform/manager.py b/model/platform/manager.py index 5ca21734..0f94765d 100644 --- a/model/platform/manager.py +++ b/model/platform/manager.py @@ -58,7 +58,7 @@ async def gocq_bot(self): try: qq_gocq = QQGOCQ(self.context, self.msg_handler) self.context.platforms.append(RegisteredPlatform( - platform_name="gocq", platform_instance=qq_gocq, origin="internal")) + platform_name="nakuru", platform_instance=qq_gocq, origin="internal")) await qq_gocq.run() except BaseException as e: logger.error("启动 nakuru 适配器时出现错误: " + str(e)) @@ -81,7 +81,7 @@ def qqchan_bot(self): from model.platform.qq_official import QQOfficial qqchannel_bot = QQOfficial(self.context, self.msg_handler) self.context.platforms.append(RegisteredPlatform( - platform_name="qqchan", platform_instance=qqchannel_bot, origin="internal")) + platform_name="qqofficial", platform_instance=qqchannel_bot, origin="internal")) return qqchannel_bot.run() except BaseException as e: logger.error("启动 QQ官方机器人适配器时出现错误: " + str(e)) diff --git a/model/platform/qq_nakuru.py b/model/platform/qq_nakuru.py index a40cb987..bf1b2419 100644 --- a/model/platform/qq_nakuru.py +++ b/model/platform/qq_nakuru.py @@ -195,14 +195,26 @@ async def _reply(self, source, message_chain: List[BaseMessageComponent]): message_chain = [Plain(text=message_chain), ] is_dict = isinstance(source, dict) - if source.type == "GuildMessage": + + typ = None + if is_dict: + if "group_id" in source: + typ = "GroupMessage" + elif "user_id" in source: + typ = "FriendMessage" + elif "guild_id" in source: + typ = "GuildMessage" + else: + typ = source.type + + if typ == "GuildMessage": guild_id = source['guild_id'] if is_dict else source.guild_id chan_id = source['channel_id'] if is_dict else source.channel_id await self.client.sendGuildChannelMessage(guild_id, chan_id, message_chain) - elif source.type == "FriendMessage": + elif typ == "FriendMessage": user_id = source['user_id'] if is_dict else source.user_id await self.client.sendFriendMessage(user_id, message_chain) - elif source.type == "GroupMessage": + elif typ == "GroupMessage": group_id = source['group_id'] if is_dict else source.group_id # 过长时forward发送 plain_text_len = 0 diff --git a/model/platform/qq_official.py b/model/platform/qq_official.py index dc28453b..a19b6024 100644 --- a/model/platform/qq_official.py +++ b/model/platform/qq_official.py @@ -112,7 +112,7 @@ def _parse_from_qqofficial(self, message: Union[botpy.message.Message, botpy.mes abm.timestamp = int(time.time()) abm.raw_message = message abm.message_id = message.id - abm.tag = "qqchan" + abm.tag = "qqofficial" msg: List[BaseMessageComponent] = [] if isinstance(message, botpy.message.GroupMessage) or isinstance(message, botpy.message.C2CMessage):