Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c530489
chore(cli): ruff rewrite
Dt8333 Oct 28, 2025
8b6d235
chore(cli): add missing type annotations
Dt8333 Oct 28, 2025
ffc535f
chore(core.agent): ruff rewrite
Dt8333 Oct 28, 2025
1e59225
chore(core.agent): add missing type annotations
Dt8333 Oct 28, 2025
a60d6fe
fix(core): 重命名__dict__方法避免类型冲突
Dt8333 Oct 28, 2025
5ea6e13
chore(core.config): ruff rewrite
Dt8333 Oct 28, 2025
c414039
chore(core.config): add missing type annotations
Dt8333 Oct 28, 2025
27c815d
chore(core.convmgr): ruff rewrite
Dt8333 Oct 28, 2025
d575969
chore(core.convmgr): add missing type annotations
Dt8333 Oct 28, 2025
b17f50f
chore(core.db): ruff rewrite
Dt8333 Oct 28, 2025
504c6d8
chore(core.db): add missing type annotations
Dt8333 Oct 28, 2025
4a54442
chore(core.kb): ruff rewrite
Dt8333 Oct 28, 2025
556cf55
chore(core.kb): add missing type annotations
Dt8333 Oct 28, 2025
a6bd814
chore(core.db): ruff rewrite missing file
Dt8333 Oct 29, 2025
f0b8020
chore(core.message): ruff rewrite
Dt8333 Oct 29, 2025
ef631ee
chore(core.message): add missing type annotations
Dt8333 Oct 29, 2025
9a6dd40
chore(core.pipeline): ruff rewrite
Dt8333 Oct 29, 2025
d85a395
chore(core.pipeline): add missing type annotations
Dt8333 Oct 29, 2025
9da5d1d
chore(core.platform): ruff rewrite
Dt8333 Oct 29, 2025
b71ba19
chore(core.provider): ruff rewrite
Dt8333 Oct 30, 2025
28d70db
chore(core.star): ruff rewrite
Dt8333 Oct 30, 2025
595f766
chore(core.message): ruff rewrite
Dt8333 Oct 30, 2025
932d76d
chore(core.utils): ruff rewrite
Dt8333 Oct 30, 2025
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
14 changes: 8 additions & 6 deletions astrbot/cli/commands/cmd_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import click
import hashlib
import zoneinfo
from typing import Any, Callable
from typing import Any

from collections.abc import Callable
from ..utils import get_astrbot_root, check_astrbot_root


Expand Down Expand Up @@ -100,7 +102,7 @@ def _save_config(config: dict[str, Any]) -> None:
)


def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
def _set_nested_item(obj: dict[str, Any], path: str, value: object) -> None:
"""设置嵌套字典中的值"""
parts = path.split(".")
for part in parts[:-1]:
Expand All @@ -114,7 +116,7 @@ def _set_nested_item(obj: dict[str, Any], path: str, value: Any) -> None:
obj[parts[-1]] = value


def _get_nested_item(obj: dict[str, Any], path: str) -> Any:
def _get_nested_item(obj: dict[str, Any], path: str) -> object:
"""获取嵌套字典中的值"""
parts = path.split(".")
for part in parts:
Expand All @@ -123,7 +125,7 @@ def _get_nested_item(obj: dict[str, Any], path: str) -> Any:


@click.group(name="conf")
def conf():
def conf() -> None:
"""配置管理命令

支持的配置项:
Expand All @@ -146,7 +148,7 @@ def conf():
@conf.command(name="set")
@click.argument("key")
@click.argument("value")
def set_config(key: str, value: str):
def set_config(key: str, value: str) -> None:
"""设置配置项的值"""
if key not in CONFIG_VALIDATORS.keys():
raise click.ClickException(f"不支持的配置项: {key}")
Expand Down Expand Up @@ -175,7 +177,7 @@ def set_config(key: str, value: str):

@conf.command(name="get")
@click.argument("key", required=False)
def get_config(key: str = None):
def get_config(key: str | None = None) -> None:
"""获取配置项的值,不提供key则显示所有可配置项"""
config = _load_config()

Expand Down
4 changes: 3 additions & 1 deletion astrbot/cli/commands/cmd_init.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import asyncio

import click
Expand All @@ -6,7 +8,7 @@
from ..utils import check_dashboard, get_astrbot_root


async def initialize_astrbot(astrbot_root) -> None:
async def initialize_astrbot(astrbot_root: Path) -> None:
"""执行 AstrBot 初始化逻辑"""
dot_astrbot = astrbot_root / ".astrbot"

Expand Down
22 changes: 13 additions & 9 deletions astrbot/cli/commands/cmd_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@click.group()
def plug():
def plug() -> None:
"""插件管理"""
pass

Expand All @@ -30,7 +30,11 @@ def _get_data_path() -> Path:
return (base / "data").resolve()


def display_plugins(plugins, title=None, color=None):
def display_plugins(
plugins: list[dict],
title: str | None = None,
color: int | tuple[int, int, int] | str | None = None,
) -> None:
if title:
click.echo(click.style(title, fg=color, bold=True))

Expand All @@ -47,7 +51,7 @@ def display_plugins(plugins, title=None, color=None):

@plug.command()
@click.argument("name")
def new(name: str):
def new(name: str) -> None:
"""创建新插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins" / name
Expand Down Expand Up @@ -86,7 +90,7 @@ def new(name: str):
f.write(f"# {name}\n\n{desc}\n\n# 支持\n\n[帮助文档](https://astrbot.app)\n")

# 重写 main.py
with open(plug_path / "main.py", "r", encoding="utf-8") as f:
with open(plug_path / "main.py", encoding="utf-8") as f:
content = f.read()

new_content = content.replace(
Expand All @@ -102,7 +106,7 @@ def new(name: str):

@plug.command()
@click.option("--all", "-a", is_flag=True, help="列出未安装的插件")
def list(all: bool):
def list(all: bool) -> None:
"""列出插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
Expand Down Expand Up @@ -143,7 +147,7 @@ def list(all: bool):
@plug.command()
@click.argument("name")
@click.option("--proxy", help="代理服务器地址")
def install(name: str, proxy: str | None):
def install(name: str, proxy: str | None) -> None:
"""安装插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins"
Expand All @@ -166,7 +170,7 @@ def install(name: str, proxy: str | None):

@plug.command()
@click.argument("name")
def remove(name: str):
def remove(name: str) -> None:
"""卸载插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
Expand All @@ -189,7 +193,7 @@ def remove(name: str):
@plug.command()
@click.argument("name", required=False)
@click.option("--proxy", help="Github代理地址")
def update(name: str, proxy: str | None):
def update(name: str, proxy: str | None) -> None:
"""更新插件"""
base_path = _get_data_path()
plug_path = base_path / "plugins"
Expand Down Expand Up @@ -227,7 +231,7 @@ def update(name: str, proxy: str | None):

@plug.command()
@click.argument("query")
def search(query: str):
def search(query: str) -> None:
"""搜索插件"""
base_path = _get_data_path()
plugins = build_plug_list(base_path / "plugins")
Expand Down
2 changes: 1 addition & 1 deletion astrbot/cli/commands/cmd_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..utils import check_dashboard, check_astrbot_root, get_astrbot_root


async def run_astrbot(astrbot_root: Path):
async def run_astrbot(astrbot_root: Path) -> None:
"""运行 AstrBot"""
from astrbot.core import logger, LogManager, LogBroker, db_helper
from astrbot.core.initial_loader import InitialLoader
Expand Down
2 changes: 1 addition & 1 deletion astrbot/cli/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PluginStatus(str, Enum):
NOT_PUBLISHED = "未发布"


def get_git_repo(url: str, target_path: Path, proxy: str | None = None):
def get_git_repo(url: str, target_path: Path, proxy: str | None = None) -> None:
"""从 Git 仓库下载代码并解压到指定路径"""
temp_dir = Path(tempfile.mkdtemp())
try:
Expand Down
4 changes: 2 additions & 2 deletions astrbot/cli/utils/version_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def compare_version(v1: str, v2: str) -> int:
v1 = v1.lower().replace("v", "")
v2 = v2.lower().replace("v", "")

def split_version(version):
def split_version(version: str) -> tuple[list[int], list[int | str] | None]:
match = re.match(
r"^([0-9]+(?:\.[0-9]+)*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+(.+))?$",
version,
Expand Down Expand Up @@ -79,7 +79,7 @@ def split_version(version):
return 0 # 数字部分和预发布标签都相同

@staticmethod
def _split_prerelease(prerelease):
def _split_prerelease(prerelease: str) -> list[int | str] | None:
if not prerelease:
return None
parts = prerelease.split(".")
Expand Down