将应用端口从硬编码的8000改为从config.py读取PORT配置,提高配置灵活性 更新了README.md和keyring.example.yaml以说明端口配置 同时在standalone.py中也使用配置的端口值
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import yaml
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
_CONFIG_PATH = Path(__file__).parent / "keyring.yaml"
|
|
|
|
|
|
def _load() -> dict[str, Any]:
|
|
with open(_CONFIG_PATH, "r", encoding="utf-8") as f:
|
|
return yaml.safe_load(f) or {}
|
|
|
|
|
|
_cfg = _load()
|
|
|
|
FEISHU_APP_ID: str = _cfg["FEISHU_APP_ID"]
|
|
FEISHU_APP_SECRET: str = _cfg["FEISHU_APP_SECRET"]
|
|
OPENAI_BASE_URL: str = _cfg["OPENAI_BASE_URL"]
|
|
OPENAI_API_KEY: str = _cfg["OPENAI_API_KEY"]
|
|
OPENAI_MODEL: str = _cfg.get("OPENAI_MODEL", "glm-4.7")
|
|
WORKING_DIR: Path = Path(_cfg.get("WORKING_DIR", Path.home())).expanduser().resolve()
|
|
METASO_API_KEY: str = _cfg.get("METASO_API_KEY", "")
|
|
|
|
ROUTER_MODE: bool = _cfg.get("ROUTER_MODE", False)
|
|
ROUTER_SECRET: str = _cfg.get("ROUTER_SECRET", "")
|
|
|
|
# Server configuration
|
|
PORT: int = _cfg.get("PORT", 8000)
|
|
|
|
_allowed_open_ids_raw = _cfg.get("ALLOWED_OPEN_IDS", [])
|
|
ALLOWED_OPEN_IDS: list[str] = _allowed_open_ids_raw if isinstance(_allowed_open_ids_raw, list) else [str(_allowed_open_ids_raw)]
|
|
|
|
|
|
def is_user_allowed(open_id: str) -> bool:
|
|
"""Check if a user is allowed to use the bot."""
|
|
if not ALLOWED_OPEN_IDS:
|
|
return True
|
|
return open_id in ALLOWED_OPEN_IDS
|