From 551b3a2a4d1e1e6b7693abb51fcf094b9ace0e5e Mon Sep 17 00:00:00 2001 From: harkerhand Date: Sun, 22 Mar 2026 18:50:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(init):=20=E9=87=8D=E6=9E=84=20init=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E4=BB=A5=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E9=85=8D=E7=BD=AE=E7=BB=93=E6=9E=84=20fix(de?= =?UTF-8?q?pendencies):=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E8=87=B3=205.2.11=20=E5=B9=B6=E6=B7=BB=E5=8A=A0=20httpx=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ncatbot/cli/commands/init.py | 59 +++++++++++++++++++++++++----------- pyproject.toml | 2 +- uv.lock | 4 ++- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/ncatbot/cli/commands/init.py b/ncatbot/cli/commands/init.py index feac73f7..7c75c808 100644 --- a/ncatbot/cli/commands/init.py +++ b/ncatbot/cli/commands/init.py @@ -29,24 +29,7 @@ def init(target_dir: str): bot_uin = click.prompt("请输入机器人 QQ 号", type=str) root = click.prompt("请输入管理员 QQ 号", type=str) - config_data = { - "bot_uin": bot_uin, - "root": root, - "debug": False, - "napcat": { - "ws_uri": "ws://localhost:3001", - "ws_token": "napcat_ws", - "webui_uri": "http://localhost:6099", - "webui_token": "napcat_webui", - "enable_webui": True, - }, - "plugin": { - "plugins_dir": "plugins", - "load_plugin": True, - "plugin_whitelist": [], - "plugin_blacklist": [], - }, - } + config_data = _build_default_config(bot_uin=bot_uin, root=root) target.mkdir(parents=True, exist_ok=True) with open(config_path, "w", encoding="utf-8") as f: @@ -65,6 +48,46 @@ def init(target_dir: str): click.echo(info("下一步: 运行 'ncatbot run' 启动机器人")) +def _build_default_config(bot_uin: str, root: str) -> dict: + """构建 init 命令的默认配置(新 adapters 结构)。""" + return { + "adapters": [ + { + "config": { + "enable_webui": True, + "webui_token": "napcat_webui", + "webui_uri": "http://localhost:6099", + "ws_token": "napcat_ws", + "ws_uri": "ws://localhost:3001", + }, + "enabled": True, + "platform": "qq", + "type": "napcat", + } + ], + "bot_uin": bot_uin, + "check_ncatbot_update": True, + "debug": False, + "enable_webui_interaction": True, + "logging": { + "event_log_levels": { + "meta_event": "NONE", + } + }, + "plugin": { + "auto_install_pip_deps": True, + "load_plugin": True, + "plugin_blacklist": [], + "plugin_configs": {}, + "plugin_whitelist": [], + "plugins_dir": "plugins", + }, + "root": root, + "skip_ncatbot_install_check": False, + "websocket_timeout": 15, + } + + def _ensure_plugins_dir(path: Path): if not path.exists(): path.mkdir(parents=True) diff --git a/pyproject.toml b/pyproject.toml index e7796ad1..3acf51d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ncatbot5" -version = "5.2.11" +version = "5.2.11.post1" description = "NcatBot, NapCat Python SDK" readme = "README.md" license = { text = "MIT" } diff --git a/uv.lock b/uv.lock index 08b02a54..65769575 100644 --- a/uv.lock +++ b/uv.lock @@ -1243,11 +1243,12 @@ wheels = [ [[package]] name = "ncatbot5" -version = "5.2.9" +version = "5.2.11" source = { editable = "." } dependencies = [ { name = "aiohttp" }, { name = "click" }, + { name = "httpx" }, { name = "packaging" }, { name = "pre-commit" }, { name = "pydantic" }, @@ -1289,6 +1290,7 @@ requires-dist = [ { name = "aiohttp", specifier = ">=3.9" }, { name = "build", marker = "extra == 'dev'", specifier = ">=1.4.0" }, { name = "click", specifier = ">=8.1" }, + { name = "httpx", specifier = ">=0.27" }, { name = "litellm", marker = "extra == 'test'", specifier = ">=1.40.0" }, { name = "mypy", marker = "extra == 'dev'" }, { name = "ncatbot5", extras = ["test"], marker = "extra == 'dev'" },