Add HeXi bot codebase: custom plugins, web frontends, tests
- hexi core: message handling, rate limiting, cooldown, plugin manager - Custom plugins: BF stats, daily check-in, quotes, persona cards, etc. - Community plugins vendored under hexi/plugins with local fixes - Web admin frontends (learning-chat, persona-admin), unified hexi/web - Tests for rate_limit/cooldown/memes/persona; poetry.lock Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
"""Model 层的数据访问:唯一读写入口(此处用 JSON 文件示例)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Runtime data belongs under hexi/data, not beside importable plugin code.
|
||||
_DATA_DIR = Path(__file__).resolve().parents[2] / "data" / "nonebot_plugin_template"
|
||||
_STORE = _DATA_DIR / "store.json"
|
||||
|
||||
|
||||
def _load() -> dict:
|
||||
if _STORE.exists():
|
||||
try:
|
||||
return json.loads(_STORE.read_text("utf-8"))
|
||||
except json.JSONDecodeError:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
|
||||
def _save(data: dict) -> None:
|
||||
_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
tmp = _STORE.with_suffix(".tmp")
|
||||
tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2), "utf-8")
|
||||
os.replace(tmp, _STORE) # 原子写
|
||||
|
||||
|
||||
def get_record(key: str):
|
||||
return _load().get(key)
|
||||
|
||||
|
||||
def save_record(key: str, value) -> None:
|
||||
data = _load()
|
||||
data[key] = value
|
||||
_save(data)
|
||||
Reference in New Issue
Block a user