6b642d7674
* refactor: bundled webui static files into wheel and replace astrbot cli log with English - Translated and standardized log messages in cmd_conf.py for better clarity. - Updated initialization logic in cmd_init.py to provide clearer user prompts and error handling. - Improved plugin management commands in cmd_plug.py with consistent language and error messages. - Enhanced run command in cmd_run.py with clearer status messages and error handling. - Updated utility functions in basic.py and plugin.py to improve readability and maintainability. - Added version comparison logic in version_comparator.py with clearer comments. - Enhanced logging configuration in log.py to suppress noisy loggers. - Updated the updater logic in updator.py to provide clearer error messages for users. - Improved IO utility functions in io.py to handle dashboard versioning more effectively. - Enhanced dashboard server logic in server.py to prioritize bundled assets and improve user feedback. - Updated pyproject.toml to include bundled dashboard assets and custom build hooks. - Added a custom build script (hatch_build.py) to automate dashboard builds during package creation. * refactor: improve exception messages and formatting in CLI command validation * perf: change npm install to npm ci for consistent dependency installation * fix
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import asyncio
|
|
from pathlib import Path
|
|
|
|
import click
|
|
from filelock import FileLock, Timeout
|
|
|
|
from ..utils import check_dashboard, get_astrbot_root
|
|
|
|
|
|
async def initialize_astrbot(astrbot_root: Path) -> None:
|
|
"""Execute AstrBot initialization logic"""
|
|
dot_astrbot = astrbot_root / ".astrbot"
|
|
|
|
if not dot_astrbot.exists():
|
|
if click.confirm(
|
|
f"Install AstrBot to this directory? {astrbot_root}",
|
|
default=True,
|
|
abort=True,
|
|
):
|
|
dot_astrbot.touch()
|
|
click.echo(f"Created {dot_astrbot}")
|
|
|
|
paths = {
|
|
"data": astrbot_root / "data",
|
|
"config": astrbot_root / "data" / "config",
|
|
"plugins": astrbot_root / "data" / "plugins",
|
|
"temp": astrbot_root / "data" / "temp",
|
|
}
|
|
|
|
for name, path in paths.items():
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
click.echo(f"{'Created' if not path.exists() else 'Directory exists'}: {path}")
|
|
|
|
await check_dashboard(astrbot_root / "data")
|
|
|
|
|
|
@click.command()
|
|
def init() -> None:
|
|
"""Initialize AstrBot"""
|
|
click.echo("Initializing AstrBot...")
|
|
astrbot_root = get_astrbot_root()
|
|
lock_file = astrbot_root / "astrbot.lock"
|
|
lock = FileLock(lock_file, timeout=5)
|
|
|
|
try:
|
|
with lock.acquire():
|
|
asyncio.run(initialize_astrbot(astrbot_root))
|
|
click.echo("Done! You can now run 'astrbot run' to start AstrBot")
|
|
except Timeout:
|
|
raise click.ClickException(
|
|
"Cannot acquire lock file. Please check if another instance is running"
|
|
)
|
|
|
|
except Exception as e:
|
|
raise click.ClickException(f"Initialization failed: {e!s}")
|