From 1b56d8c00b02565244fed864423a6cf4cd5fbe47 Mon Sep 17 00:00:00 2001 From: bucolucas Date: Tue, 20 Aug 2024 14:09:12 -0500 Subject: [PATCH] Add .doreboot file check and message sending functionality --- telegram_helper.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/telegram_helper.py b/telegram_helper.py index f8788ce..f2f1b3e 100644 --- a/telegram_helper.py +++ b/telegram_helper.py @@ -80,6 +80,14 @@ class TelegramHelper: f.write(str(update.effective_chat.id)) sys.exit(0) + async def check_doreboot_file(self, application: Application): + reboot_file_path = "./.doreboot" + if os.path.exists(reboot_file_path): + with open(reboot_file_path, 'r') as f: + chat_id = f.read().strip() + await application.bot.send_message(chat_id=chat_id, text="The application has finished initializing.") + os.remove(reboot_file_path) + def run(self): application = Application.builder().token(self.telegram_bot_token).build() @@ -93,7 +101,7 @@ class TelegramHelper: logging.info("Bot is running...") - if os.path.exists("./.doreboot"): - os.remove("./.doreboot") - + # Check for .doreboot file and send message if it exists + application.create_task(self.check_doreboot_file(application)) + application.run_polling() \ No newline at end of file