Add /browse command and button callback handlers to TelegramHelper

This commit is contained in:
cyclop-bot
2024-08-20 16:52:09 -05:00
parent 80f2fc4fed
commit c52dd6a3a1
+7 -1
View File
@@ -6,6 +6,7 @@ import time
import git
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes, CallbackQueryHandler
from browse_command import browse_command, button_callback
class TelegramHelper:
def __init__(self, bot):
@@ -108,6 +109,9 @@ class TelegramHelper:
logging.error(f"Error checking for new commits: {str(e)}")
await asyncio.sleep(60) # Check every 60 seconds
async def browse(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await browse_command(update, context)
def run(self):
application = Application.builder().token(self.telegram_bot_token).build()
@@ -116,8 +120,10 @@ class TelegramHelper:
application.add_handler(CommandHandler("switch", self.switch))
application.add_handler(CommandHandler("status", self.status))
application.add_handler(CommandHandler("reboot", self.reboot))
application.add_handler(CommandHandler("browse", self.browse))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, self.handle_message))
application.add_handler(CallbackQueryHandler(self.abort_processing, pattern='^abort$'))
application.add_handler(CallbackQueryHandler(button_callback, pattern='^(browse|file):'))
logging.info("Bot is running...")
@@ -127,4 +133,4 @@ class TelegramHelper:
# Start the commit checking task
asyncio.get_event_loop().create_task(self.check_for_new_commits())
application.run_polling()
application.run_polling()