-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eb1846
commit 543ca25
Showing
1 changed file
with
41 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
from pydantic import BaseModel | ||
from typing import List, Dict, Optional | ||
import yaml | ||
import os | ||
|
||
class config: | ||
def __init__(self, **kwargs): | ||
for key, value in kwargs.items(): | ||
if isinstance(value, dict): | ||
value = config(**value) | ||
setattr(self, key, value) | ||
class BotBasic(BaseModel): | ||
bot_name: str = "" | ||
bot_name_argument: str = "" | ||
bot_owner: List[str] = [] | ||
bot_repo: str = "" | ||
bot_notice: Dict[str, str] = {} # 键是 Bot 的 QQ 号,值是通知的群号 | ||
proxy: Optional[str] = None | ||
|
||
def yaml_to_class(yaml_str, cls): | ||
config_data = yaml.safe_load(yaml_str) | ||
return cls(**config_data) | ||
class GithubConfig(BaseModel): | ||
web_path: str = "" | ||
github_personal_token: str = "" | ||
|
||
class Jx3APIConfig(BaseModel): | ||
token: str = "" | ||
token_v2: str = "" | ||
ticket: str = "" | ||
url: str = "" | ||
|
||
class Jx3WSConfig(BaseModel): | ||
url: str = "" | ||
token: str = "" | ||
|
||
class Jx3Config(BaseModel): | ||
api: Jx3APIConfig = Jx3APIConfig() | ||
ws: Jx3WSConfig = Jx3WSConfig() | ||
|
||
class HiddenConfig(BaseModel): | ||
offcial_token: Optional[str] = None | ||
|
||
class Config(BaseModel): | ||
bot_basic: BotBasic = BotBasic() | ||
github: GithubConfig = GithubConfig() | ||
jx3: Jx3Config = Jx3Config() | ||
hidden: HiddenConfig = HiddenConfig() | ||
|
||
def load_config(yaml_file_path: str) -> Config: | ||
with open(yaml_file_path, "r", encoding="utf8") as f: | ||
config_data = yaml.safe_load(f) | ||
return Config(**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="utf8") as f: | ||
Config = yaml_to_class(f.read(), config) | ||
config = load_config(yaml_file_path) |