fix:saka.py无法启动
This commit is contained in:
14
saka.py
14
saka.py
@@ -10,21 +10,19 @@ MaiSaka - 程序入口
|
||||
ENABLE_THINKING - 是否启用思考模式 (可选, true/false, 不设置则不发送该参数)
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目根目录和 src/maisaka 到 Python 路径
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
_root = Path(__file__).parent
|
||||
_maisaka_path = _root / "src" / "maisaka"
|
||||
if str(_root) not in sys.path:
|
||||
sys.path.insert(0, str(_root))
|
||||
if str(_maisaka_path) not in sys.path:
|
||||
sys.path.insert(0, str(_maisaka_path))
|
||||
|
||||
from src.cli.console import console # noqa: E402
|
||||
from src.cli.maisaka_cli import BufferCLI # noqa: E402
|
||||
from src.prompt.prompt_manager import prompt_manager # noqa: E402
|
||||
from src.maisaka.cli import BufferCLI # noqa: E402
|
||||
from src.maisaka.config import console # noqa: E402
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -170,6 +170,38 @@ def _migrate_expression_learning_list(expr: dict[str, Any]) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _migrate_chat_talk_value_rules(chat: dict[str, Any]) -> bool:
|
||||
"""
|
||||
将旧版 target 字段迁移为当前运行时使用的 platform/item_id/rule_type 结构。
|
||||
"""
|
||||
talk_value_rules = _as_list(chat.get("talk_value_rules"))
|
||||
if talk_value_rules is None:
|
||||
return False
|
||||
|
||||
migrated = False
|
||||
for rule in talk_value_rules:
|
||||
rule_item = _as_dict(rule)
|
||||
if rule_item is None or "target" not in rule_item:
|
||||
continue
|
||||
|
||||
target_raw = rule_item.get("target")
|
||||
target = "" if target_raw is None else str(target_raw).strip()
|
||||
if not target:
|
||||
parsed = {"platform": "", "item_id": "", "rule_type": "group"}
|
||||
else:
|
||||
parsed = _parse_triplet_target(target)
|
||||
if parsed is None:
|
||||
continue
|
||||
|
||||
rule_item["platform"] = parsed["platform"]
|
||||
rule_item["item_id"] = parsed["item_id"]
|
||||
rule_item["rule_type"] = parsed["rule_type"]
|
||||
rule_item.pop("target", None)
|
||||
migrated = True
|
||||
|
||||
return migrated
|
||||
|
||||
|
||||
def _migrate_expression_groups(expr: dict[str, Any]) -> bool:
|
||||
"""
|
||||
将旧版 expression.expression_groups 转成当前结构。
|
||||
@@ -316,6 +348,11 @@ def try_migrate_legacy_bot_config_dict(data: dict[str, Any]) -> MigrationResult:
|
||||
migrated_any = True
|
||||
reasons.append("bot.qq_account_empty")
|
||||
|
||||
chat = _as_dict(data.get("chat"))
|
||||
if chat is not None and _migrate_chat_talk_value_rules(chat):
|
||||
migrated_any = True
|
||||
reasons.append("chat.talk_value_rules_target")
|
||||
|
||||
expr = _as_dict(data.get("expression"))
|
||||
if expr is not None:
|
||||
if _migrate_expression_learning_list(expr):
|
||||
|
||||
Reference in New Issue
Block a user