fix: логирование и очистка обработчика toggle_ai_chat

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-02-24 07:34:22 +08:00
parent 4b1c033a5e
commit 6397559dd1
1 changed files with 6 additions and 20 deletions

22
bot.py
View File

@ -781,6 +781,7 @@ class MenuBuilder:
# Для главного меню — динамически меняем кнопку ИИ # Для главного меню — динамически меняем кнопку ИИ
if menu_name == "main" and user_id: if menu_name == "main" and user_id:
state = state_manager.get(user_id) state = state_manager.get(user_id)
logger.info(f"get_keyboard: user_id={user_id}, ai_chat_mode={state.ai_chat_mode}")
for item in items: for item in items:
if item.callback == "toggle_ai_chat": if item.callback == "toggle_ai_chat":
@ -791,6 +792,7 @@ class MenuBuilder:
else: else:
label = f"❌ Включить чат с ИИ" label = f"❌ Включить чат с ИИ"
callback = "toggle_ai_chat_on" callback = "toggle_ai_chat_on"
logger.info(f"get_keyboard: label={label}, callback={callback}")
button = InlineKeyboardButton(label, callback_data=callback) button = InlineKeyboardButton(label, callback_data=callback)
else: else:
button = InlineKeyboardButton(item.label, callback_data=item.callback) button = InlineKeyboardButton(item.label, callback_data=item.callback)
@ -1445,26 +1447,10 @@ async def menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
) )
state.current_menu = "main" state.current_menu = "main"
elif callback == "toggle_ai_chat":
# Переключаем режим
state.ai_chat_mode = not state.ai_chat_mode
ai_status = "✅ ВКЛЮЧЕН" if state.ai_chat_mode else "❌ ВЫКЛЮЧЕН"
action = "включён" if state.ai_chat_mode else "выключен"
await query.edit_message_text(
f"🏠 *Главное меню*\n\n"
f"💬 *Чат с ИИ:* {ai_status}\n\n"
f"Режим чата с агентом {action}.\n"
f"Теперь все сообщения будут отправляться в Qwen Code.",
parse_mode="Markdown",
reply_markup=menu_builder.get_keyboard("main", user_id=query.from_user.id)
)
state.current_menu = "main"
elif callback in ["toggle_ai_chat_on", "toggle_ai_chat_off"]: elif callback in ["toggle_ai_chat_on", "toggle_ai_chat_off"]:
# Переключаем режим (новые callback_data для правильной работы кнопки) # Переключаем режим чата с ИИ
state.ai_chat_mode = not state.ai_chat_mode state.ai_chat_mode = not state.ai_chat_mode
logger.info(f"toggle_ai_chat: user_id={user_id}, new_mode={state.ai_chat_mode}")
ai_status = "✅ ВКЛЮЧЕН" if state.ai_chat_mode else "❌ ВЫКЛЮЧЕН" ai_status = "✅ ВКЛЮЧЕН" if state.ai_chat_mode else "❌ ВЫКЛЮЧЕН"
action = "включён" if state.ai_chat_mode else "выключен" action = "включён" if state.ai_chat_mode else "выключен"