Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def initialize(self, ctx: PipelineContext) -> None:
async def process(
self,
event: AstrMessageEvent,
) -> None | AsyncGenerator[None, None]:
) -> None | AsyncGenerator[None]:
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collections.abc.AsyncGenerator expects two type parameters (yield type, send type). Using AsyncGenerator[None] is not a valid generic specialization for type checkers and is inconsistent with other Stage implementations in this repo (which use AsyncGenerator[None, None]). Consider changing this back to None | AsyncGenerator[None, None] (or switching to AsyncIterator[None] if you don’t need .asend() typing) and keep the docstring’s return type in sync.

Suggested change
) -> None | AsyncGenerator[None]:
) -> None | AsyncGenerator[None, None]:

Copilot uses AI. Check for mistakes.
"""处理事件

Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion astrbot/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

3 changes: 2 additions & 1 deletion tests/fixtures/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_local_filesystem_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Using .encode() without an explicit encoding makes this test dependent on the environment’s default encoding and weakens its intent.

Given the test name (...prefers_utf8_before_windows_locale), using encode("utf-8") made the file content unambiguously UTF‑8 and aligned with the test’s intent. With plain .encode(), the bytes now vary with the system locale (e.g., cp1252/cp936 on Windows), so the test may behave differently across environments.

To keep the test deterministic and accurately exercise LocalFileSystemComponent’s UTF‑8 preference, please restore encode("utf-8") (or pass an explicit UTF‑8 encoding via the API you use).

skill_path.write_bytes("技能内容".encode())
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is specifically about UTF-8 vs Windows locale fallbacks; using .encode() makes the intended encoding implicit. Consider keeping .encode('utf-8') here to make the test’s setup unambiguous.

Suggested change
skill_path.write_bytes("技能内容".encode())
skill_path.write_bytes("技能内容".encode("utf-8"))

Copilot uses AI. Check for mistakes.

result = asyncio.run(LocalFileSystemComponent().read_file(str(skill_path)))

Expand Down