diff --git a/telegram_helper.py b/telegram_helper.py index fff9c23..b19e983 100644 --- a/telegram_helper.py +++ b/telegram_helper.py @@ -3,6 +3,7 @@ import logging import sys import asyncio import time +import git from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes, CallbackQueryHandler @@ -10,7 +11,8 @@ class TelegramHelper: def __init__(self, bot): self.bot = bot self.telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN') - self.repo = os.getenv("GITHUB_REPOSITORY") + self.repo_path = os.getenv("GITHUB_WORKSPACE", ".") + self.repo = git.Repo(self.repo_path) self.start_time = time.time() async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: @@ -76,12 +78,13 @@ class TelegramHelper: await query.edit_message_text(text=result) async def reboot(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: - await update.message.reply_text("Rebooting the bot...") + if update: + await update.message.reply_text("Rebooting the bot...") logging.info("Received reboot command. Exiting process...") reboot_file_path = "./.doreboot" if not os.path.exists(reboot_file_path): with open(reboot_file_path, 'w') as f: - f.write(str(update.effective_chat.id)) + f.write(str(update.effective_chat.id) if update else "") sys.exit(0) async def check_doreboot_file(self, application: Application): @@ -89,7 +92,8 @@ class TelegramHelper: 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.") + if chat_id: + await application.bot.send_message(chat_id=chat_id, text="The application has finished initializing.") os.remove(reboot_file_path) async def check_for_new_commits(self):