remove hard-coded git-url & minor restructuring
This commit is contained in:
parent
d6519d5133
commit
9049b5e637
5 changed files with 12 additions and 6 deletions
0
lib/__init__.py
Normal file
0
lib/__init__.py
Normal file
28
lib/config.py
Normal file
28
lib/config.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import json
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Config(object):
|
||||
discord_token: str | None = None
|
||||
discord_guild_id: int | None = None
|
||||
git_branch: str | None = None
|
||||
git_url: str | None = None
|
||||
|
||||
def config_decoder(obj):
|
||||
if '__type__' in obj and obj['__type__'] == "Config":
|
||||
return Config(
|
||||
discord_token=obj['discord_token'],
|
||||
discord_guild_id=obj['discord_guild_id'],
|
||||
git_branch=obj['git_branch'],
|
||||
git_url=obj['git_url']
|
||||
)
|
||||
|
||||
def save_config(config: dict):
|
||||
with Path("config.json").open("w+", encoding="utf-8") as fp:
|
||||
json.dump(config, fp, indent=4)
|
||||
|
||||
def load_config():
|
||||
with Path("config.json").open("r", encoding="utf-8") as fp:
|
||||
config = json.load(fp, object_hook=config_decoder)
|
||||
return config
|
||||
Loading…
Add table
Add a link
Reference in a new issue