diff --git a/astrbot/core/pipeline/stage.py b/astrbot/core/pipeline/stage.py index 74aca4ef19..380c072b9d 100644 --- a/astrbot/core/pipeline/stage.py +++ b/astrbot/core/pipeline/stage.py @@ -33,7 +33,7 @@ async def initialize(self, ctx: PipelineContext) -> None: async def process( self, event: AstrMessageEvent, - ) -> None | AsyncGenerator[None, None]: + ) -> None | AsyncGenerator[None]: """处理事件 Args: diff --git a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py index 8419c0ea01..ed72fc6083 100644 --- a/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py +++ b/astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py @@ -49,6 +49,7 @@ async def on_group_at_message_create( abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.GROUP_MESSAGE, + self.platform.appid, ) abm.group_id = cast(str, message.group_openid) abm.session_id = abm.group_id @@ -60,6 +61,7 @@ async def on_at_message_create(self, message: botpy.message.Message) -> None: abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.GROUP_MESSAGE, + self.platform.appid, ) abm.group_id = message.channel_id abm.session_id = abm.group_id @@ -73,6 +75,7 @@ async def on_direct_message_create( abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.FRIEND_MESSAGE, + self.platform.appid, ) abm.session_id = abm.sender.user_id self.platform.remember_session_scene(abm.session_id, "friend") @@ -83,6 +86,7 @@ async def on_c2c_message_create(self, message: botpy.message.C2CMessage) -> None abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.FRIEND_MESSAGE, + self.platform.appid, ) abm.session_id = abm.sender.user_id self.platform.remember_session_scene(abm.session_id, "friend") @@ -470,6 +474,7 @@ async def _parse_from_qqofficial( | botpy.message.DirectMessage | botpy.message.C2CMessage, message_type: MessageType, + appid: str, ) -> AstrBotMessage: abm = AstrBotMessage() abm.type = message_type @@ -486,14 +491,14 @@ async def _parse_from_qqofficial( if isinstance(message, botpy.message.GroupMessage): abm.sender = MessageMember(message.author.member_openid, "") abm.group_id = message.group_openid + msg.append(At(qq=appid)) else: abm.sender = MessageMember(message.author.user_openid, "") # Parse face messages to readable text abm.message_str = QQOfficialPlatformAdapter._parse_face_message( message.content.strip() ) - abm.self_id = "unknown_selfid" - msg.append(At(qq="qq_official")) + abm.self_id = appid msg.append(Plain(abm.message_str)) await QQOfficialPlatformAdapter._append_attachments( msg, message.attachments @@ -504,10 +509,7 @@ async def _parse_from_qqofficial( message, botpy.message.DirectMessage, ): - if isinstance(message, botpy.message.Message): - abm.self_id = str(message.mentions[0].id) - else: - abm.self_id = "" + abm.self_id = appid plain_content = QQOfficialPlatformAdapter._parse_face_message( message.content.replace( @@ -525,14 +527,13 @@ async def _parse_from_qqofficial( str(message.author.id), str(message.author.username), ) - msg.append(At(qq="qq_official")) + msg.append(At(qq=appid)) msg.append(Plain(plain_content)) if isinstance(message, botpy.message.Message): abm.group_id = message.channel_id else: raise ValueError(f"Unknown message type: {message_type}") - abm.self_id = "qq_official" return abm def run(self): diff --git a/astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py b/astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py index b4dbe36b0d..0249582728 100644 --- a/astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py +++ b/astrbot/core/platform/sources/qqofficial_webhook/qo_webhook_adapter.py @@ -34,6 +34,7 @@ async def on_group_at_message_create( abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.GROUP_MESSAGE, + self.platform.appid, ) abm.group_id = cast(str, message.group_openid) abm.session_id = abm.group_id @@ -45,6 +46,7 @@ async def on_at_message_create(self, message: botpy.message.Message) -> None: abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.GROUP_MESSAGE, + self.platform.appid, ) abm.group_id = message.channel_id abm.session_id = abm.group_id @@ -58,6 +60,7 @@ async def on_direct_message_create( abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.FRIEND_MESSAGE, + self.platform.appid, ) abm.session_id = abm.sender.user_id self.platform.remember_session_scene(abm.session_id, "friend") @@ -68,6 +71,7 @@ async def on_c2c_message_create(self, message: botpy.message.C2CMessage) -> None abm = await QQOfficialPlatformAdapter._parse_from_qqofficial( message, MessageType.FRIEND_MESSAGE, + self.platform.appid, ) abm.session_id = abm.sender.user_id self.platform.remember_session_scene(abm.session_id, "friend") diff --git a/astrbot/utils/__init__.py b/astrbot/utils/__init__.py index 8b13789179..e69de29bb2 100644 --- a/astrbot/utils/__init__.py +++ b/astrbot/utils/__init__.py @@ -1 +0,0 @@ - diff --git a/tests/fixtures/helpers.py b/tests/fixtures/helpers.py index 26edb761c5..8cc344afd5 100644 --- a/tests/fixtures/helpers.py +++ b/tests/fixtures/helpers.py @@ -6,7 +6,8 @@ import shutil from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Callable +from typing import Any +from collections.abc import Callable from unittest.mock import AsyncMock, MagicMock from astrbot.core.message.components import BaseMessageComponent diff --git a/tests/test_local_filesystem_component.py b/tests/test_local_filesystem_component.py index b8e1180c09..5c34d8d5ad 100644 --- a/tests/test_local_filesystem_component.py +++ b/tests/test_local_filesystem_component.py @@ -27,7 +27,7 @@ def test_local_file_system_component_prefers_utf8_before_windows_locale( skill_path = tmp_path / "skills" / "demo.txt" skill_path.parent.mkdir(parents=True, exist_ok=True) - skill_path.write_bytes("技能内容".encode("utf-8")) + skill_path.write_bytes("技能内容".encode()) result = asyncio.run(LocalFileSystemComponent().read_file(str(skill_path)))