forked from HornCopper/Lagrange-Python.OneBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
32 lines (24 loc) · 787 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
31
32
import yaml
import os
from typing import Literal
from pydantic import BaseModel
from lagrange.utils.log import LoggerProvider, install_loguru
logger = LoggerProvider()
install_loguru()
class config(BaseModel):
uin: int = 0
protocol: Literal["windows", "macos", "linux"] = "linux"
sign_server: str = ""
ws_url: str = ""
http_host: str = ""
http_port: str = ""
log_level: str = "INFO"
v6: bool = False
ignore_self: bool = True
def yaml_to_class(yaml_str, cls):
config_data = yaml.safe_load(yaml_str)
return cls(**config_data)
script_dir = os.path.dirname(os.path.abspath(__file__))
yaml_file_path = os.path.join(script_dir, "config.yml")
with open(yaml_file_path, "r", encoding="utf-8") as f:
Config = yaml_to_class(f.read(), config)