Skip to content

Commit

Permalink
fix: 修复部分字段未更新导致的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulter committed Aug 10, 2024
1 parent 0360279 commit 7fb7114
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions model/platform/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
18 changes: 15 additions & 3 deletions model/platform/qq_nakuru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion model/platform/qq_official.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7fb7114

Please sign in to comment.