Spaces:
Runtime error
Runtime error
Upload main.py
Browse files
main.py
CHANGED
|
@@ -87,15 +87,25 @@ async def inline_query_handler(query: types.InlineQuery):
|
|
| 87 |
await query.answer(results[:50], cache_time=1)
|
| 88 |
|
| 89 |
async def main():
|
| 90 |
-
bot_info = await bot.get_me()
|
| 91 |
-
logger.info(f"Starting bot @{bot_info.username}")
|
| 92 |
-
|
| 93 |
app = web.Application()
|
| 94 |
app.router.add_get("/", health_check)
|
| 95 |
runner = web.AppRunner(app)
|
| 96 |
await runner.setup()
|
| 97 |
site = web.TCPSite(runner, "0.0.0.0", 7860)
|
| 98 |
await site.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
await dp.start_polling(bot)
|
| 101 |
|
|
|
|
| 87 |
await query.answer(results[:50], cache_time=1)
|
| 88 |
|
| 89 |
async def main():
|
|
|
|
|
|
|
|
|
|
| 90 |
app = web.Application()
|
| 91 |
app.router.add_get("/", health_check)
|
| 92 |
runner = web.AppRunner(app)
|
| 93 |
await runner.setup()
|
| 94 |
site = web.TCPSite(runner, "0.0.0.0", 7860)
|
| 95 |
await site.start()
|
| 96 |
+
|
| 97 |
+
max_retries = 10
|
| 98 |
+
for attempt in range(1, max_retries + 1):
|
| 99 |
+
try:
|
| 100 |
+
bot_info = await bot.get_me()
|
| 101 |
+
logger.info(f"Connected to Telegram! Starting bot @{bot_info.username}")
|
| 102 |
+
break
|
| 103 |
+
except Exception as e:
|
| 104 |
+
if attempt == max_retries:
|
| 105 |
+
logger.error(f"Failed to connect to Telegram after {max_retries} attempts. Exiting.")
|
| 106 |
+
return
|
| 107 |
+
logger.warning(f"Network not ready (Attempt {attempt}/{max_retries}). Retrying in 5s... Error: {e}")
|
| 108 |
+
await asyncio.sleep(5)
|
| 109 |
|
| 110 |
await dp.start_polling(bot)
|
| 111 |
|