fix: динамическая кнопка чата с ИИ
Изменения: - Разные callback_data для вкл/выкл (toggle_ai_chat_on/off) - Разный текст кнопки в зависимости от статуса - Telegram теперь правильно обновляет кнопку Теперь кнопка показывает правильное действие Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
a41556a2d6
commit
00e7c1a1e5
28
bot.py
28
bot.py
|
|
@ -785,9 +785,14 @@ class MenuBuilder:
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
if item.callback == "toggle_ai_chat":
|
if item.callback == "toggle_ai_chat":
|
||||||
# Меняем текст кнопки
|
# Меняем текст кнопки и callback_data в зависимости от статуса
|
||||||
label = f"{ai_status} Чат с ИИ агентом"
|
if state.ai_chat_mode:
|
||||||
button = InlineKeyboardButton(label, callback_data=item.callback)
|
label = f"{ai_status} Выключить чат с ИИ"
|
||||||
|
callback = "toggle_ai_chat_off"
|
||||||
|
else:
|
||||||
|
label = f"{ai_status} Включить чат с ИИ"
|
||||||
|
callback = "toggle_ai_chat_on"
|
||||||
|
button = InlineKeyboardButton(label, callback_data=callback)
|
||||||
else:
|
else:
|
||||||
button = InlineKeyboardButton(item.label, callback_data=item.callback)
|
button = InlineKeyboardButton(item.label, callback_data=item.callback)
|
||||||
keyboard.append([button])
|
keyboard.append([button])
|
||||||
|
|
@ -1457,6 +1462,23 @@ async def menu_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||||
reply_markup=menu_builder.get_keyboard("main", user_id=query.from_user.id)
|
reply_markup=menu_builder.get_keyboard("main", user_id=query.from_user.id)
|
||||||
)
|
)
|
||||||
state.current_menu = "main"
|
state.current_menu = "main"
|
||||||
|
|
||||||
|
elif callback in ["toggle_ai_chat_on", "toggle_ai_chat_off"]:
|
||||||
|
# Переключаем режим (новые callback_data для правильной работы кнопки)
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
async def execute_cli_command(query, command: str):
|
async def execute_cli_command(query, command: str):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue