From a7d2c98c97defc54ad256b655a93bbe7b55521a8 Mon Sep 17 00:00:00 2001 From: cyclop-bot <178948048+cyclop-bot@users.noreply.github.com> Date: Mon, 2 Jun 2025 14:55:30 -0500 Subject: [PATCH] Refactor telegram_helper.py: Apply constants, remove unused git import, and prepare for processing_status encapsulation. --- telegram_helper.py | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/telegram_helper.py b/telegram_helper.py index 53d55b7..e3c83cc 100644 --- a/telegram_helper.py +++ b/telegram_helper.py @@ -3,16 +3,21 @@ 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 from browse_command import browse_command, button_callback class TelegramHelper: + # --- Constants for configurable paths and magic strings --- + REBOOT_CLAUDE_FILE = '.reboot_claude' + REBOOT_FILE = '.doreboot' + CLAUDE_REBOOT_TARGET = 'claude' + HTML_QUOTE_BLOCK_START = '
Thinking...' + HTML_QUOTE_BLOCK_END = '' + def __init__(self, bot): self.bot = bot self.telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN') - self.repo = git.Repo(".") self.start_time = time.time() async def start(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: @@ -23,11 +28,11 @@ class TelegramHelper: async def clear(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: user_id = update.effective_user.id - await self.bot.clear(user_id) + await self.bot.clear_conversation_history(user_id) await update.message.reply_text("Conversation history cleared. Let's start fresh!") async def status(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: - status_message = await self.bot.status() + status_message = await self.bot.get_bot_status() await update.message.reply_text(status_message) async def switch(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: @@ -56,23 +61,22 @@ class TelegramHelper: logging.info(f"Message from user {user_id}: {user_message}") - status_message = await update.message.reply_text("Processing your request...", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Abort", callback_data='abort')]])) - self.bot.processing_status[user_id] = {"processing": True, "message_id": status_message.message_id} + status_message = await update.message.reply_text("Processing your request...", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Abort", callback_data='abort')]]))\ + await self.bot.set_processing_status(user_id, status_message.message_id) response = await self.bot.handle_message(user_id, user_message) await context.bot.delete_message(chat_id=update.effective_chat.id, message_id=status_message.message_id) - del self.bot.processing_status[user_id] - response = response.replace("
Thinking...").replace("