From b7e6eaa803ab15d9a46354ea0ccbcc8079a689a8 Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 2 Jun 2025 17:40:44 -0500 Subject: [PATCH] Refactor telegram_helper.py to correctly handle asyncio event loop by using Application.post_init for startup tasks. --- telegram_helper.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/telegram_helper.py b/telegram_helper.py index 2bdbae6..ee39e43 100644 --- a/telegram_helper.py +++ b/telegram_helper.py @@ -226,7 +226,7 @@ class TelegramHelper: await browse_command(update, context, self.bot) def run(self): - application = Application.builder().token(self.telegram_bot_token).build() + application = Application.builder().token(self.telegram_bot_token).post_init(self.check_doreboot_file).build() application.add_handler(CommandHandler("start", self.start)) application.add_handler(CommandHandler("clear", self.clear)) @@ -239,11 +239,4 @@ class TelegramHelper: application.add_handler(CallbackQueryHandler(button_callback, pattern='^(browse|file):')) logging.info("Bot is running...") - - loop = asyncio.get_event_loop() - if loop.is_running(): # pragma: no cover - loop.create_task(self.check_doreboot_file(application)) - else: # pragma: no cover - asyncio.run(self.check_doreboot_file(application)) - application.run_polling()