| name | config-manager |
| description | 读取、搜索和修改 AstrBot 系统配置 |
| version | 2.0.0 |
| author | AstrBot Community |
| requires_admin | true |
| requires_computer_use | true |
Config Manager
管理 AstrBot 的系统配置。
使用场景
- "查看唤醒前缀配置" / "读取某个配置项"
- "搜索和数据库相关的配置"
- "把唤醒前缀改成 /" / "修改配置"
可用工具
1. 读取配置
async def get_config(context, key_path: str):
try:
config = context.get_astrbot_config()
keys = key_path.split(".")
value = config
for key in keys:
if isinstance(value, dict):
value = value.get(key)
else:
return f"❌ 配置路径「{key_path}」不存在。"
import json
return f"📋 配置「{key_path}」:\n```json\n{json.dumps(value, ensure_ascii=False, indent=2)}\n```"
except Exception as e:
return f"❌ 读取配置失败:{e}"
event = globals().get('event')
if not event.is_admin():
print("❌ 错误:仅管理员可用")
import sys; sys.exit(1)
context = globals().get('context')
result = await get_config(context, key_path="<配置路径>")
print(result)
2. 搜索配置
async def search_config(context, keyword: str):
try:
config = context.get_astrbot_config()
def search_dict(d, prefix=""):
results = []
for k, v in d.items():
path = f"{prefix}.{k}" if prefix else k
if keyword.lower() in k.lower() or keyword.lower() in str(v).lower():
results.append((path, v))
if isinstance(v, dict):
results.extend(search_dict(v, path))
return results
matches = search_dict(config)
if not matches:
return f"🔍 没有找到包含「{keyword}」的配置项。"
lines = [f"🔍 找到 {len(matches)} 个匹配项:\n"]
for path, value in matches[:20]:
value_str = str(value)[:50]
lines.append(f"- **{path}**: {value_str}")
if len(matches) > 20:
lines.append(f"\n...还有 个结果")
.join(lines)
Exception e:
result = search_config(context, keyword=)
(result)
3. 修改配置
async def set_config(context, updates: dict):
try:
config = context.get_astrbot_config()
old_config = config.copy()
for key_path, new_value in updates.items():
keys = key_path.split(".")
target = config
for key in keys[:-1]:
if key not in target:
target[key] = {}
target = target[key]
old_value = target.get(keys[-1])
if old_value is not None:
if isinstance(old_value, bool):
new_value = str(new_value).lower() in ["true", "1", "yes"]
elif isinstance(old_value, int):
new_value = int(new_value)
elif isinstance(old_value, float):
new_value = float(new_value)
target[keys[-1]] = new_value
try:
context.save_astrbot_config(config)
except Exception as e:
context.save_astrbot_config(old_config)
lines = []
key_path, new_value updates.items():
lines.append()
.join(lines)
Exception e:
result = set_config(context, updates={
: ,
})
(result)
注意事项
- 配置修改会立即生效
- 修改失败时会自动回滚
- 某些配置可能需要重启 AstrBot 才能生效
- 使用点号分隔的路径访问嵌套配置,如 "llm.model_name"