-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
30 lines (24 loc) · 877 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
from typing import List, Optional, Tuple
from pydantic import BaseModel
class GroupConfig(BaseModel):
group_id: str # 群聊ID
secret: str # Webhook Secret
organization: Optional[str] = None # 组织名称
repository: Optional[str] = None # 仓库名称
def load_group_configs(
config_file: str = "config.json",
) -> Tuple[List[GroupConfig], str]:
"""
从配置文件中加载群聊绑定信息。
"""
try:
with open(config_file, "r", encoding="utf-8") as file:
data = json.load(file)
return [GroupConfig(**group) for group in data.get("groups", [])], data.get(
"api_url", ""
)
except (FileNotFoundError, json.JSONDecodeError) as e:
raise RuntimeError(f"无法加载配置文件: {e}")
# 加载配置
GROUP_CONFIGS, API_URL = load_group_configs()