W1xced commited on
Commit
61aaa78
·
verified ·
1 Parent(s): 0475441

Upload main.py

Browse files
Files changed (1) hide show
  1. main.py +18 -5
main.py CHANGED
@@ -39,8 +39,11 @@ dp = Dispatcher()
39
 
40
  @dp.message(CommandStart())
41
  async def cmd_start(message: types.Message):
42
- bot_info = await bot.get_me()
43
- await message.answer(f"Hello! I am an inline bot. Type @{bot_info.username} in any chat to see my snippets.")
 
 
 
44
 
45
  @dp.inline_query()
46
  async def inline_query_handler(query: types.InlineQuery):
@@ -68,9 +71,19 @@ async def main():
68
  await runner.setup()
69
  await web.TCPSite(runner, "0.0.0.0", 7860).start()
70
 
71
- bot_info = await bot.get_me()
72
- logger.info(f"Bot started: @{bot_info.username}")
73
- await dp.start_polling(bot)
 
 
 
 
 
 
 
 
 
 
74
 
75
  if __name__ == "__main__":
76
  import sys
 
39
 
40
  @dp.message(CommandStart())
41
  async def cmd_start(message: types.Message):
42
+ try:
43
+ bot_info = await bot.get_me()
44
+ await message.answer(f"Hello! I am an inline bot. Type @{bot_info.username} in any chat to see my snippets.")
45
+ except:
46
+ await message.answer("Hello! I am an inline bot.")
47
 
48
  @dp.inline_query()
49
  async def inline_query_handler(query: types.InlineQuery):
 
71
  await runner.setup()
72
  await web.TCPSite(runner, "0.0.0.0", 7860).start()
73
 
74
+ logger.info("Attempting to connect to Telegram...")
75
+ for attempt in range(1, 11):
76
+ try:
77
+ bot_info = await bot.get_me()
78
+ logger.info(f"Connected! Bot: @{bot_info.username}")
79
+ await dp.start_polling(bot)
80
+ break
81
+ except Exception as e:
82
+ if attempt == 10:
83
+ logger.error("Final connection attempt failed.")
84
+ return
85
+ logger.warning(f"Attempt {attempt} failed, retrying in 5s...")
86
+ await asyncio.sleep(5)
87
 
88
  if __name__ == "__main__":
89
  import sys