-
-
Notifications
You must be signed in to change notification settings - Fork 968
标准化AstrBot api #2594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
标准化AstrBot api #2594
Conversation
…strbot.api.star.register
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好 - 我已审阅了你的更改,它们看起来很棒!
AI 代理提示
请处理此代码审查中的评论:
## 独立评论
### 评论 1
<location> `astrbot/core/message/components.py:657` </location>
<code_context>
+ QQ 戳一戳
+ """
+
type: str = ""
id: T.Optional[int] = 0
qq: T.Optional[int] = 0
</code_context>
<issue_to_address>
戳一戳类型被定义为 str 而不是 ComponentType。
这种不一致可能会影响类型检查和序列化。除非有特定原因,否则请更新“type”字段以使用“ComponentType”来匹配其他组件。
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
type: str = ""
=======
type: ComponentType = "Poke"
>>>>>>> REPLACE
</suggested_fix>
### 评论 2
<location> `astrbot/core/message/components.py:452` </location>
<code_context>
+ """
+
type: ComponentType = "Contact"
_type: str # type 字段冲突
id: T.Optional[int] = 0
</code_context>
<issue_to_address>
'_type' 字段可能存在命名冲突。
建议重命名 '_type' 或添加清晰的文档,以防止混淆和潜在的序列化问题。
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
_type: str # type 字段冲突
=======
contact_type: str # 原字段名为 _type,为避免与 type 冲突已重命名。用于标识推荐的好友或群类型。
>>>>>>> REPLACE
</suggested_fix>
### 评论 3
<location> `astrbot/core/message/components.py:987` </location>
<code_context>
+# 匹配消息用字典
ComponentTypes = {
"plain": Plain,
"text": Plain,
</code_context>
<issue_to_address>
ComponentTypes 字典可能需要规范化键的大小写。
规范化字典键和输入值为一致的大小写,以防止因大小写差异导致的查找失败。
建议的实现:
```python
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,
```
```python
# 用于安全查找组件类型,自动规范化输入键为小写
def get_component_type(key: str):
return ComponentTypes.get(key.lower())
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,
```
1. 将代码库中任何直接查找(如 `ComponentTypes[some_key]`)替换为 `get_component_type(some_key)` 以确保规范化。
2. 如果在其他地方向 `ComponentTypes` 添加键,请确保它们以小写形式添加。
</issue_to_address>
### 评论 4
<location> `astrbot/core/platform/astr_message_event.py:29` </location>
<code_context>
@dataclass
class MessageSesion:
+ """
+ 消息会话
</code_context>
<issue_to_address>
类名拼写错误:'MessageSesion' 应为 'MessageSession'。
将类重命名为 'MessageSession' 以匹配其在其他地方的使用并保持一致性。
建议的实现:
```python
class MessageSession:
"""
消息会话
用于统一标识一个消息会话
"""
platform_name: str
message_type: MessageType
session_id: str
```
如果代码库中存在任何 `MessageSesion` 的用法,也应将其更新为 `MessageSession` 以保持一致性。
</issue_to_address>
### 评论 5
<location> `astrbot/api/README.md:14` </location>
<code_context>
+astrbot.api.event: 包括了 AstrBot 事件以及相关类的导入
+astrbot.api.event.filter(将弃用): 包括了事件过滤器, 用于注册 Handler, 由 astrbot.api.star.register 统一注册来代替
+astrbot.api.event.message: 包括了 AstrBot 事件中, 所有有关消息的类
+astrbot.api.api.event.message.message_components: 包括了所有消息组件
+
+astrbot.api.platform: 包括了所有平台相关的导入
</code_context>
<issue_to_address>
可能存在拼写错误:'astrbot.api.api.event.message.message_components' 中 'api' 重复。
如果 'api' 的重复是无意的,请考虑将导入路径更新为 'astrbot.api.event.message.message_components'。
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
astrbot.api.api.event.message.message_components: 包括了所有消息组件
=======
astrbot.api.event.message.message_components: 包括了所有消息组件
>>>>>>> REPLACE
</suggested_fix>
### 评论 6
<location> `astrbot/api/provider/__init__.py:23` </location>
<code_context>
)
+from astrbot.core.provider.manager import ProviderManager
+
+from astrbot.core.provider.sources.anthropic_source import ProviderAnthropic # Claude
+from astrbot.core.provider.sources.azure_tts_source import (
+ OTTSProvider,
</code_context>
<issue_to_address>
考虑动态发现和导入提供者类,以避免手动样板导入。
您可以通过动态发现和导入提供者来消除几乎所有样板代码。例如,将 `astrbot/core/provider/sources/` 转换为一个 proper package(带有自己的 `__init__.py`),然后执行以下操作:
```python
# astrbot/core/provider/sources/__init__.py
import pkgutil
import importlib
from astrbot.core.provider.provider import BaseProvider # or whatever your common parent is
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
module = importlib.import_module(f"{__name__}.{module_name}")
for obj in vars(module).values():
if isinstance(obj, type) and issubclass(obj, BaseProvider):
globals()[obj.__name__] = obj
__all__.append(obj.__name__)
```
然后您的顶级 `astrbot/api/provider/__init__.py` 可以简单地重新导出该子包中的所有内容:
```python
from astrbot.core.provider.provider import Provider, STTProvider, Personality, TTSProvider, EmbeddingProvider
from astrbot.core.provider.entities import (
ProviderRequest, ProviderType, ProviderMetaData, LLMResponse,
ToolCallsResult, AssistantMessageSegment, ToolCallMessageSegment,
)
from astrbot.core.provider.manager import ProviderManager
# pull in all providers dynamically
from astrbot.core.provider.sources import *
__all__ = [
"Provider", "STTProvider", "Personality", "TTSProvider", "EmbeddingProvider",
"ProviderRequest", "ProviderType", "ProviderMetaData", "LLMResponse",
"ToolCallsResult", "AssistantMessageSegment", "ToolCallMessageSegment",
"ProviderManager",
] + __all__ # append all the dynamically discovered provider class names
```
这使得每个提供者都在 `__all__` 中,但您不再需要手动维护数十行导入代码。
</issue_to_address>帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进您的评论。
Original comment in English
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `astrbot/core/message/components.py:657` </location>
<code_context>
+ QQ 戳一戳
+ """
+
type: str = ""
id: T.Optional[int] = 0
qq: T.Optional[int] = 0
</code_context>
<issue_to_address>
Poke type is defined as str instead of ComponentType.
This inconsistency may affect type checking and serialization. Please update to use 'ComponentType' for 'type' to match other components, unless there's a specific reason for using 'str'.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
type: str = ""
=======
type: ComponentType = "Poke"
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `astrbot/core/message/components.py:452` </location>
<code_context>
+ """
+
type: ComponentType = "Contact"
_type: str # type 字段冲突
id: T.Optional[int] = 0
</code_context>
<issue_to_address>
Potential naming conflict with '_type' field.
Renaming '_type' or adding clear documentation is recommended to prevent confusion and potential serialization problems.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
_type: str # type 字段冲突
=======
contact_type: str # 原字段名为 _type,为避免与 type 冲突已重命名。用于标识推荐的好友或群类型。
>>>>>>> REPLACE
</suggested_fix>
### Comment 3
<location> `astrbot/core/message/components.py:987` </location>
<code_context>
+# 匹配消息用字典
ComponentTypes = {
"plain": Plain,
"text": Plain,
</code_context>
<issue_to_address>
ComponentTypes dictionary may need normalization for key casing.
Normalize dictionary keys and input values to a consistent case to prevent lookup failures due to casing differences.
Suggested implementation:
```python
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,
```
```python
# 用于安全查找组件类型,自动规范化输入键为小写
def get_component_type(key: str):
return ComponentTypes.get(key.lower())
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,
```
1. Replace any direct lookup like `ComponentTypes[some_key]` elsewhere in the codebase with `get_component_type(some_key)` to ensure normalization.
2. If there are other places where keys are added to `ComponentTypes`, ensure they are added in lowercase.
</issue_to_address>
### Comment 4
<location> `astrbot/core/platform/astr_message_event.py:29` </location>
<code_context>
@dataclass
class MessageSesion:
+ """
+ 消息会话
</code_context>
<issue_to_address>
Typo in class name: 'MessageSesion' should be 'MessageSession'.
Rename the class to 'MessageSession' to match its usage elsewhere and maintain consistency.
Suggested implementation:
```python
class MessageSession:
"""
消息会话
用于统一标识一个消息会话
"""
platform_name: str
message_type: MessageType
session_id: str
```
If there are any usages of `MessageSesion` elsewhere in the codebase, those should also be updated to `MessageSession` for consistency.
</issue_to_address>
### Comment 5
<location> `astrbot/api/README.md:14` </location>
<code_context>
+astrbot.api.event: 包括了 AstrBot 事件以及相关类的导入
+astrbot.api.event.filter(将弃用): 包括了事件过滤器, 用于注册 Handler, 由 astrbot.api.star.register 统一注册来代替
+astrbot.api.event.message: 包括了 AstrBot 事件中, 所有有关消息的类
+astrbot.api.api.event.message.message_components: 包括了所有消息组件
+
+astrbot.api.platform: 包括了所有平台相关的导入
</code_context>
<issue_to_address>
Possible typo: 'astrbot.api.api.event.message.message_components' has 'api' twice.
Consider updating the import path to 'astrbot.api.event.message.message_components' if the repetition of 'api' is unintentional.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
astrbot.api.api.event.message.message_components: 包括了所有消息组件
=======
astrbot.api.event.message.message_components: 包括了所有消息组件
>>>>>>> REPLACE
</suggested_fix>
### Comment 6
<location> `astrbot/api/provider/__init__.py:23` </location>
<code_context>
)
+from astrbot.core.provider.manager import ProviderManager
+
+from astrbot.core.provider.sources.anthropic_source import ProviderAnthropic # Claude
+from astrbot.core.provider.sources.azure_tts_source import (
+ OTTSProvider,
</code_context>
<issue_to_address>
Consider dynamically discovering and importing provider classes to avoid manual boilerplate imports.
You can eliminate almost all of that boilerplate by discovering and importing your providers dynamically. For example, turn `astrbot/core/provider/sources/` into a proper package (with its own `__init__.py`), and do something like this:
```python
# astrbot/core/provider/sources/__init__.py
import pkgutil
import importlib
from astrbot.core.provider.provider import BaseProvider # or whatever your common parent is
__all__ = []
for finder, module_name, ispkg in pkgutil.iter_modules(__path__):
module = importlib.import_module(f"{__name__}.{module_name}")
for obj in vars(module).values():
if isinstance(obj, type) and issubclass(obj, BaseProvider):
globals()[obj.__name__] = obj
__all__.append(obj.__name__)
```
Then your top-level `astrbot/api/provider/__init__.py` can simply re-export everything in that subpackage:
```python
from astrbot.core.provider.provider import Provider, STTProvider, Personality, TTSProvider, EmbeddingProvider
from astrbot.core.provider.entities import (
ProviderRequest, ProviderType, ProviderMetaData, LLMResponse,
ToolCallsResult, AssistantMessageSegment, ToolCallMessageSegment,
)
from astrbot.core.provider.manager import ProviderManager
# pull in all providers dynamically
from astrbot.core.provider.sources import *
__all__ = [
"Provider", "STTProvider", "Personality", "TTSProvider", "EmbeddingProvider",
"ProviderRequest", "ProviderType", "ProviderMetaData", "LLMResponse",
"ToolCallsResult", "AssistantMessageSegment", "ToolCallMessageSegment",
"ProviderManager",
] + __all__ # append all the dynamically discovered provider class names
```
This keeps every provider on `__all__`, but you no longer have to hand-maintain dozens of import lines.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
astrbot/core/message/components.py
Outdated
| QQ 戳一戳 | ||
| """ | ||
|
|
||
| type: str = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: 戳一戳类型被定义为 str 而不是 ComponentType。
这种不一致可能会影响类型检查和序列化。除非有特定原因,否则请更新“type”字段以使用“ComponentType”来匹配其他组件。
| type: str = "" | |
| type: ComponentType = "Poke" |
Original comment in English
suggestion: Poke type is defined as str instead of ComponentType.
This inconsistency may affect type checking and serialization. Please update to use 'ComponentType' for 'type' to match other components, unless there's a specific reason for using 'str'.
| type: str = "" | |
| type: ComponentType = "Poke" |
| """ | ||
|
|
||
| type: ComponentType = "Contact" | ||
| _type: str # type 字段冲突 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: '_type' 字段可能存在命名冲突。
建议重命名 '_type' 或添加清晰的文档,以防止混淆和潜在的序列化问题。
| _type: str # type 字段冲突 | |
| contact_type: str # 原字段名为 _type,为避免与 type 冲突已重命名。用于标识推荐的好友或群类型。 |
Original comment in English
suggestion: Potential naming conflict with '_type' field.
Renaming '_type' or adding clear documentation is recommended to prevent confusion and potential serialization problems.
| _type: str # type 字段冲突 | |
| contact_type: str # 原字段名为 _type,为避免与 type 冲突已重命名。用于标识推荐的好友或群类型。 |
|
|
||
| # 匹配消息用字典 | ||
| ComponentTypes = { | ||
| "plain": Plain, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: ComponentTypes 字典可能需要规范化键的大小写。
规范化字典键和输入值为一致的大小写,以防止因大小写差异导致的查找失败。
建议的实现:
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,# 用于安全查找组件类型,自动规范化输入键为小写
def get_component_type(key: str):
return ComponentTypes.get(key.lower())
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,- 将代码库中任何直接查找(如
ComponentTypes[some_key])替换为get_component_type(some_key)以确保规范化。 - 如果在其他地方向
ComponentTypes添加键,请确保它们以小写形式添加。
Original comment in English
suggestion: ComponentTypes dictionary may need normalization for key casing.
Normalize dictionary keys and input values to a consistent case to prevent lookup failures due to casing differences.
Suggested implementation:
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,# 用于安全查找组件类型,自动规范化输入键为小写
def get_component_type(key: str):
return ComponentTypes.get(key.lower())
# 匹配消息用字典,所有键统一为小写
ComponentTypes = {
"plain": Plain,
"text": Plain,- Replace any direct lookup like
ComponentTypes[some_key]elsewhere in the codebase withget_component_type(some_key)to ensure normalization. - If there are other places where keys are added to
ComponentTypes, ensure they are added in lowercase.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors and improves the AstrBot API module structure with better organization, comprehensive documentation, and code quality improvements. The changes focus on restructuring import paths, adding docstrings, and standardizing code formatting.
Key changes:
- Reorganized API module structure with new submodules (tool, util, star.register, event.message, platform submodules)
- Added comprehensive Chinese docstrings to classes, modules, and enums throughout the codebase
- Standardized import patterns and deprecated old import paths while maintaining backward compatibility
- Minor formatting improvements (spacing in comments, line breaks for readability)
Reviewed Changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| astrbot/core/star/star_tools.py | Fixed import path from astrbot.api.platform to astrbot.core.platform; improved code formatting |
| astrbot/core/platform/sources/webchat/webchat_event.py | Updated import paths to use core modules directly instead of api modules |
| astrbot/core/platform/sources/discord/components.py | Added spacing to Chinese comments for consistency; minor whitespace cleanup |
| astrbot/core/platform/astrbot_message.py | Added docstrings to MessageMember and Group classes |
| astrbot/core/platform/astr_message_event.py | Added comprehensive docstring to AstrMessageEvent class |
| astrbot/core/message/components.py | Added docstrings to all component classes; reorganized ComponentType enum with categorization and deprecation notes |
| astrbot/api/util/init.py | Added module docstring and expanded exports |
| astrbot/api/tool/init.py | Created new module for LLM tool-related imports |
| astrbot/api/star/register/init.py | Created new module consolidating all plugin registration functions |
| astrbot/api/star/init.py | Added module docstring and simplified wildcard imports |
| astrbot/api/provider/init.py | Added module docstring and expanded provider source imports |
| astrbot/api/platform/*/init.py | Created platform-specific submodules with docstrings |
| astrbot/api/platform/init.py | Reorganized imports with explicit exports and categorization |
| astrbot/api/message_components.py | Added deprecation warning and explicit imports |
| astrbot/api/event/*/init.py | Created event submodules with proper organization |
| astrbot/api/all.py | Added deprecation warning and comprehensive imports |
| astrbot/api/init.py | Reorganized as main API entry point with comprehensive exports |
| astrbot/api/README.md | Created documentation for API structure |
Comments suppressed due to low confidence (3)
astrbot/api/provider/init.py:107
- The name 'ProviderEdgeTTS' is exported by all but is not defined.
"ProviderEdgeTTS",
astrbot/api/provider/init.py:120
- The name 'ProviderSenseVoiceSTTSelfHost' is exported by all but is not defined.
"ProviderSenseVoiceSTTSelfHost",
astrbot/api/provider/init.py:123
- The name 'ProviderOpenAIWhisperSelfHost' is exported by all but is not defined.
"ProviderOpenAIWhisperSelfHost",
| """ | ||
| 语音 | ||
| """ | ||
|
|
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace found on line 167. This should be removed for consistency with Python code style guidelines.
| "ProviderDashscope", | ||
| "ProviderDashscopeTTSAPI", | ||
| "ProviderDify", | ||
| "ProviderEdgeTTS", |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'ProviderEdgeTTS' is exported in all but the import statement on line 37 is commented out. This will cause an ImportError when users try to import it. Either uncomment the import or remove it from all.
| "ProviderEdgeTTS", |
| "OpenAIEmbeddingProvider", | ||
| "ProviderOpenAIOfficial", | ||
| "ProviderOpenAITTSAPI", | ||
| "ProviderSenseVoiceSTTSelfHost", |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'ProviderSenseVoiceSTTSelfHost' is exported in all but the corresponding import on lines 69-71 is commented out. This will cause an ImportError. Either uncomment the import or remove it from all.
| "ProviderSenseVoiceSTTSelfHost", |
| "ProviderSenseVoiceSTTSelfHost", | ||
| "ProviderVolcengineTTS", | ||
| "ProviderOpenAIWhisperAPI", | ||
| "ProviderOpenAIWhisperSelfHost", |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'ProviderOpenAIWhisperSelfHost' is exported in all but the corresponding import on lines 79-81 is commented out. This will cause an ImportError. Either uncomment the import or remove it from all.
| "ProviderOpenAIWhisperSelfHost", |
| DiscordButton, # Discord 引用组件 | ||
| DiscordReference, # Discord 视图组件 |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments for DiscordButton and DiscordReference are incorrect. Based on the actual class definitions, DiscordButton should be '按钮组件' (button component) and DiscordReference should be '引用组件' (reference component). Currently, DiscordButton's comment says '引用组件' and DiscordReference's comment says '视图组件'.
| DiscordButton, # Discord 引用组件 | |
| DiscordReference, # Discord 视图组件 | |
| DiscordButton, # Discord 按钮组件 | |
| DiscordReference, # Discord 引用组件 |
| from astrbot.core.star.register import ( | ||
| register_command as command, # 注册命令 | ||
| register_command_group as command_group, # 注册命令组 | ||
| register_event_message_type as event_message_type, # 注册监听器: 事件消息类型 | ||
| register_regex as regex, # 注册监听器: 正则表达式 | ||
| register_platform_adapter_type as platform_adapter_type, # 注册监听器: 平台适配器类型 | ||
| register_permission_type as permission_type, # 注册监听器: 权限类型 | ||
| register_custom_filter as custom_filter, # 注册监听器: 自定义过滤器 | ||
| register_on_astrbot_loaded as on_astrbot_loaded, # 注册触发器: AstrBot 加载完成时 | ||
| register_on_llm_request as on_llm_request, # 注册触发器: LLM 请求时 | ||
| register_on_llm_response as on_llm_response, # 注册触发器: LLM 响应时 | ||
| register_on_decorating_result as on_decorating_result, # 注册触发器: 装饰结果时 | ||
| register_after_message_sent as after_message_sent, # 注册触发器: 消息发送后 | ||
| register_llm_tool as llm_tool, # 注册 LLM 工具 | ||
| ) |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'command' is not used.
Import of 'command_group' is not used.
Import of 'event_message_type' is not used.
Import of 'regex' is not used.
Import of 'platform_adapter_type' is not used.
Import of 'permission_type' is not used.
Import of 'custom_filter' is not used.
Import of 'on_astrbot_loaded' is not used.
Import of 'on_llm_request' is not used.
Import of 'on_llm_response' is not used.
Import of 'on_decorating_result' is not used.
Import of 'after_message_sent' is not used.
Import of 'llm_tool' is not used.
| from astrbot.core.star.register import ( | |
| register_command as command, # 注册命令 | |
| register_command_group as command_group, # 注册命令组 | |
| register_event_message_type as event_message_type, # 注册监听器: 事件消息类型 | |
| register_regex as regex, # 注册监听器: 正则表达式 | |
| register_platform_adapter_type as platform_adapter_type, # 注册监听器: 平台适配器类型 | |
| register_permission_type as permission_type, # 注册监听器: 权限类型 | |
| register_custom_filter as custom_filter, # 注册监听器: 自定义过滤器 | |
| register_on_astrbot_loaded as on_astrbot_loaded, # 注册触发器: AstrBot 加载完成时 | |
| register_on_llm_request as on_llm_request, # 注册触发器: LLM 请求时 | |
| register_on_llm_response as on_llm_response, # 注册触发器: LLM 响应时 | |
| register_on_decorating_result as on_decorating_result, # 注册触发器: 装饰结果时 | |
| register_after_message_sent as after_message_sent, # 注册触发器: 消息发送后 | |
| register_llm_tool as llm_tool, # 注册 LLM 工具 | |
| ) | |
| # Removed unused imports: command, command_group, event_message_type, regex, platform_adapter_type, permission_type, custom_filter, on_astrbot_loaded, on_llm_request, on_llm_response, on_decorating_result, after_message_sent, llm_tool |
| from astrbot.core.platform.register import register_platform_adapter | ||
|
|
||
| from .message_components import * | ||
| from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'PermissionTypeFilter' is not used.
Import of 'PermissionType' is not used.
| from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType | |
| # from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType |
|
|
||
| from .message_components import * | ||
| from astrbot.core.star.filter.permission import PermissionTypeFilter, PermissionType | ||
| from astrbot.core.star.filter.custom_filter import CustomFilter |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'CustomFilter' is not used.
| from astrbot.core.star.filter.custom_filter import CustomFilter |
| from astrbot.core.message.components import ( | ||
| ComponentType, # 枚举所有消息类型名 | ||
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | ||
| # 常用消息组件 | ||
| Plain, # 纯文本消息 | ||
| Face, # QQ表情 | ||
| Record, # 语音 | ||
| Video, # 视频 | ||
| At, # @ | ||
| AtAll, # @全体成员 | ||
| Node, # 转发节点 | ||
| Nodes, # 多个转发节点 | ||
| Poke, # QQ 戳一戳 | ||
| Image, # 图片 | ||
| Reply, # 回复消息 | ||
| Forward, # 转发消息 | ||
| File, # 文件 | ||
| # 其他消息组件 | ||
| Music, # 音乐分享 | ||
| Json, # Json 消息 | ||
| TTS, # TTS | ||
| Unknown, # 未知类型 | ||
| # 特定平台消息组件 | ||
| Dice, # 骰子 | ||
| Contact, # 推荐好友/群 | ||
| RPS, # 猜拳魔法表情 | ||
| ## 微信 | ||
| WechatEmoji, # 微信表情 | ||
| # 仅接收 | ||
| Share, # 链接分享 | ||
| Shake, # 私聊窗口抖动 | ||
| ) |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'ComponentType' is not used.
Import of 'BaseMessageComponent' is not used.
Import of 'Plain' is not used.
Import of 'Face' is not used.
Import of 'Record' is not used.
Import of 'Video' is not used.
Import of 'At' is not used.
Import of 'AtAll' is not used.
Import of 'Node' is not used.
Import of 'Nodes' is not used.
Import of 'Poke' is not used.
Import of 'Image' is not used.
Import of 'Reply' is not used.
Import of 'Forward' is not used.
Import of 'File' is not used.
Import of 'Music' is not used.
Import of 'Json' is not used.
Import of 'TTS' is not used.
Import of 'Unknown' is not used.
Import of 'Dice' is not used.
Import of 'Contact' is not used.
Import of 'RPS' is not used.
Import of 'WechatEmoji' is not used.
Import of 'Share' is not used.
Import of 'Shake' is not used.
| from astrbot.core.message.components import ( | |
| ComponentType, # 枚举所有消息类型名 | |
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | |
| # 常用消息组件 | |
| Plain, # 纯文本消息 | |
| Face, # QQ表情 | |
| Record, # 语音 | |
| Video, # 视频 | |
| At, # @ | |
| AtAll, # @全体成员 | |
| Node, # 转发节点 | |
| Nodes, # 多个转发节点 | |
| Poke, # QQ 戳一戳 | |
| Image, # 图片 | |
| Reply, # 回复消息 | |
| Forward, # 转发消息 | |
| File, # 文件 | |
| # 其他消息组件 | |
| Music, # 音乐分享 | |
| Json, # Json 消息 | |
| TTS, # TTS | |
| Unknown, # 未知类型 | |
| # 特定平台消息组件 | |
| Dice, # 骰子 | |
| Contact, # 推荐好友/群 | |
| RPS, # 猜拳魔法表情 | |
| ## 微信 | |
| WechatEmoji, # 微信表情 | |
| # 仅接收 | |
| Share, # 链接分享 | |
| Shake, # 私聊窗口抖动 | |
| ) |
| from astrbot.core.message.components import ( | ||
| ComponentType, # 枚举所有消息类型名 | ||
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | ||
| # 常用消息组件 | ||
| Plain, # 纯文本消息 | ||
| Face, # QQ表情 | ||
| Record, # 语音 | ||
| Video, # 视频 | ||
| At, # @ | ||
| AtAll, # @全体成员 | ||
| Node, # 转发节点 | ||
| Nodes, # 多个转发节点 | ||
| Poke, # QQ 戳一戳 | ||
| Image, # 图片 | ||
| Reply, # 回复消息 | ||
| Forward, # 转发消息 | ||
| File, # 文件 | ||
| # 其他消息组件 | ||
| Music, # 音乐分享 | ||
| Json, # Json 消息 | ||
| TTS, # TTS | ||
| Unknown, # 未知类型 | ||
| # 特定平台消息组件 | ||
| Dice, # 骰子 | ||
| Contact, # 推荐好友/群 | ||
| RPS, # 猜拳魔法表情 | ||
| ## 微信 | ||
| WechatEmoji, # 微信表情 | ||
| # 仅接收 | ||
| Share, # 链接分享 | ||
| Shake, # 私聊窗口抖动 | ||
| ) |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'ComponentType' is not used.
Import of 'BaseMessageComponent' is not used.
Import of 'Plain' is not used.
Import of 'Face' is not used.
Import of 'Record' is not used.
Import of 'Video' is not used.
Import of 'At' is not used.
Import of 'AtAll' is not used.
Import of 'Node' is not used.
Import of 'Nodes' is not used.
Import of 'Poke' is not used.
Import of 'Image' is not used.
Import of 'Reply' is not used.
Import of 'Forward' is not used.
Import of 'File' is not used.
Import of 'Music' is not used.
Import of 'Json' is not used.
Import of 'TTS' is not used.
Import of 'Unknown' is not used.
Import of 'Dice' is not used.
Import of 'Contact' is not used.
Import of 'RPS' is not used.
Import of 'WechatEmoji' is not used.
Import of 'Share' is not used.
Import of 'Shake' is not used.
| from astrbot.core.message.components import ( | |
| ComponentType, # 枚举所有消息类型名 | |
| BaseMessageComponent, # 消息类型基类, 如果你需要适配新的消息类型, 可以选择继承此类 | |
| # 常用消息组件 | |
| Plain, # 纯文本消息 | |
| Face, # QQ表情 | |
| Record, # 语音 | |
| Video, # 视频 | |
| At, # @ | |
| AtAll, # @全体成员 | |
| Node, # 转发节点 | |
| Nodes, # 多个转发节点 | |
| Poke, # QQ 戳一戳 | |
| Image, # 图片 | |
| Reply, # 回复消息 | |
| Forward, # 转发消息 | |
| File, # 文件 | |
| # 其他消息组件 | |
| Music, # 音乐分享 | |
| Json, # Json 消息 | |
| TTS, # TTS | |
| Unknown, # 未知类型 | |
| # 特定平台消息组件 | |
| Dice, # 骰子 | |
| Contact, # 推荐好友/群 | |
| RPS, # 猜拳魔法表情 | |
| ## 微信 | |
| WechatEmoji, # 微信表情 | |
| # 仅接收 | |
| Share, # 链接分享 | |
| Shake, # 私聊窗口抖动 | |
| ) |
Motivation
之前的api有点乱, 并且命名和结构不是很规范(例如all里面并不是真的all)
因此进行api结构调整, 同时保留之前的全部api和结构以向后兼容
Modifications
去除了所有import *
加入大部分事件, 平台, 供应商api, 便于构造特定供应商的请求/特定平台的事件
提供了详尽的注释
正在慢慢撰写相应的api文档
Check
requirements.txt和pyproject.toml文件相应位置。Sourcery 总结
标准化并模块化 AstrBot API 表面,通过显式导出、子包组织和丰富组件定义,同时保持向后兼容性。
增强功能:
api.star.register下模块化插件注册和事件过滤README.md文档,说明新的 API 结构文档:
README概述标准化 API 布局Original summary in English
Summary by Sourcery
Standardize and modularize the AstrBot API surface with explicit exports, subpackage organization, and enriched component definitions while preserving backward compatibility
Enhancements:
Documentation: