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

@@ -4,6 +4,8 @@ import logging
import os
import sys
sys.path.insert(0, "/home/shoko/repositories/jigaido")
from telegram.ext import Application, CommandHandler, MessageHandler, filters
from commands import (
@@ -29,7 +31,9 @@ logging.basicConfig(
)
log = logging.getLogger(__name__)
BOT_TOKEN = os.environ.get("JIGAIDO_BOT_TOKEN", "")
from config import config
BOT_TOKEN = config.bot_token or ""
def build_app() -> Application:
@@ -74,6 +78,8 @@ async def post_init(app: Application) -> None:
def main() -> None:
import asyncio
if not BOT_TOKEN:
log.error("JIGAIDO_BOT_TOKEN environment variable not set.")
sys.exit(1)
@@ -82,6 +88,11 @@ def main() -> None:
app.post_init = post_init
log.info("JIGAIDO starting...")
# Python 3.14 compatibility: ensure event loop exists
try:
asyncio.get_event_loop()
except RuntimeError:
asyncio.set_event_loop(asyncio.new_event_loop())
app.run_polling(drop_pending_updates=True)