Skip to content
Closed
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
72 changes: 66 additions & 6 deletions astrbot/core/star/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
# 兼容导出: Provider 从 provider 模块重新导出
from astrbot.core.provider import Provider
"""Star package - Plugin system for AstrBot.

from .base import Star
from .context import Context
This module uses lazy imports to avoid circular dependencies.
Use TYPE_CHECKING for type hints and direct submodule imports at runtime.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

# Core data structures - safe to import at module level
from .star import StarMetadata, star_map, star_registry
from .star_manager import PluginManager
from .star_tools import StarTools

if TYPE_CHECKING:
# Type-only imports to avoid circular dependencies
from astrbot.core.provider import Provider

from .base import Star
from .context import Context
from .star_manager import PluginManager
from .star_tools import StarTools


# Lazy-loaded cached module references
_import_cache: dict[str, object] = {}


def __getattr__(name: str) -> object:
"""Lazy load heavy dependencies to avoid circular imports."""
if name in _import_cache:
return _import_cache[name]

if name == "Star":
from .base import Star as _Star

_import_cache[name] = _Star
return _Star
elif name == "Context":
from .context import Context as _Context

_import_cache[name] = _Context
return _Context
elif name == "PluginManager":
from .star_manager import PluginManager as _PluginManager

_import_cache[name] = _PluginManager
return _PluginManager
elif name == "StarTools":
from .star_tools import StarTools as _StarTools

_import_cache[name] = _StarTools
return _StarTools
elif name == "Provider":
from astrbot.core.provider import Provider as _Provider

_import_cache[name] = _Provider
return _Provider

raise AttributeError(
f"module {__name__!r} has no attribute {name!r}. "
f"Available: {', '.join(__all__)}"
)


def __dir__() -> list[str]:
"""Support IDE autocompletion by listing all available attributes."""
return list(globals().keys()) + list(__all__)


__all__ = [
"Context",
Expand Down
10 changes: 7 additions & 3 deletions astrbot/core/star/star_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@
然后使用 create_event 方法提交事件到指定平台
"""

from __future__ import annotations

import inspect
import os
import uuid
from collections.abc import Awaitable, Callable
from pathlib import Path
from typing import Any, ClassVar
from typing import TYPE_CHECKING, Any, ClassVar

from astrbot.api.platform import AstrBotMessage, MessageMember, MessageType
from astrbot.core.message.components import BaseMessageComponent
from astrbot.core.message.message_event_result import MessageChain
from astrbot.core.platform import AstrBotMessage, MessageMember, MessageType
from astrbot.core.platform.astr_message_event import MessageSesion
from astrbot.core.platform.sources.aiocqhttp.aiocqhttp_message_event import (
AiocqhttpMessageEvent,
)
from astrbot.core.platform.sources.aiocqhttp.aiocqhttp_platform_adapter import (
AiocqhttpAdapter,
)
from astrbot.core.star.context import Context
from astrbot.core.star.star import star_map
from astrbot.core.utils.astrbot_path import get_astrbot_data_path

if TYPE_CHECKING:
from .context import Context


class StarTools:
"""提供给插件使用的便捷工具函数集合
Expand Down
Loading