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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user