feat: bot reads JIGAIDO_BOT_TOKEN from config file

- config.py: Added _resolve_bot_token() to read from config file
- bot.py: Uses config.config.bot_token instead of env var directly
- test_config.py: Added test for config file token reading
This commit is contained in:
shokollm
2026-04-04 15:16:55 +00:00
parent 5502de96ad
commit 408318d323
3 changed files with 50 additions and 5 deletions

View File

@@ -13,7 +13,21 @@ class Config:
def __init__(self):
self.data_dir: Path = self._resolve_data_dir()
self.bot_token: Optional[str] = os.environ.get("JIGAIDO_BOT_TOKEN")
self.bot_token: Optional[str] = self._resolve_bot_token()
def _resolve_bot_token(self) -> Optional[str]:
env_token = os.environ.get("JIGAIDO_BOT_TOKEN")
if env_token:
return env_token
config_file = Path("~/.jigaido/config.json").expanduser()
if config_file.exists():
with open(config_file) as f:
config_data = json.load(f)
if "JIGAIDO_BOT_TOKEN" in config_data:
return config_data["JIGAIDO_BOT_TOKEN"]
return None
def _resolve_data_dir(self) -> Path:
env_dir = os.environ.get("JIGAIDO_DATA_DIR")
@@ -35,3 +49,6 @@ class Config:
config = Config()
config = Config()