refactor: centralize Bot instantiation via create_bot() factory
Replace all ~45 direct Bot() calls across the codebase with a centralized create_bot() factory function that automatically configures SOCKS5 proxy session when PROXY_URL is set. This ensures proxy support applies uniformly to all Telegram API traffic. Key changes: - Add app/bot_factory.py with create_bot() factory - Replace direct Bot() instantiation in 33 files - Fix session leaks in cloudpayments.py and auth.py (async with) - Replace 2 direct httpx calls to api.telegram.org with bot.create_invoice_link() (balance.py, wheel.py) - Remove now-unused imports (Bot, DefaultBotProperties, ParseMode, httpx)
This commit is contained in:
@@ -964,11 +964,10 @@ async def _send_crash_notification_on_error(error: Exception) -> None:
|
||||
return
|
||||
|
||||
try:
|
||||
from aiogram import Bot
|
||||
|
||||
from app.bot_factory import create_bot
|
||||
from app.services.startup_notification_service import send_crash_notification
|
||||
|
||||
bot = Bot(token=settings.BOT_TOKEN)
|
||||
bot = create_bot()
|
||||
try:
|
||||
traceback_str = traceback.format_exc()
|
||||
await send_crash_notification(bot, error, traceback_str)
|
||||
|
||||
Reference in New Issue
Block a user