Remove: режим подтверждения (confirm/auto)

- Удалена команда /mode
- Удалён ChatMode из states.py
- Все запросы теперь выполняются в режиме yolo=True
- Бот всегда работает в автономном режиме
- Упрощён confirm_callback - только выбор модели

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-03-19 00:55:40 +08:00
parent 1f988ad724
commit 6b21889964
2 changed files with 15 additions and 110 deletions

View File

@ -14,7 +14,7 @@ from config.config import get_settings
from src.tools.orchestrator import Orchestrator
from src.tools.xray import get_xray_client
from src.speech.speech import SpeechRecognizer
from src.bot.states import chat_state, ChatMode, XRayState
from src.bot.states import chat_state, XRayState
from src.bot.config_manager import get_selected_tool, get_selected_model, set_tool
logging.basicConfig(
@ -124,7 +124,6 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
"📋 Команды:\n"
"/qwen - Использовать Qwen (все запросы через Qwen)\n"
"/open - Выбрать модель OpenCode\n"
"/mode confirm/auto - Режим подтверждения\n"
"/forget - Очистить историю\n"
"/xray [email] - Добавить пользователя XRay\n"
"/stt on|off - Распознавание речи\n\n"
@ -135,24 +134,6 @@ async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(help_text)
async def mode_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not context.args:
mode = chat_state.get_mode(update.effective_chat.id)
mode_name = "с подтверждением" if mode == ChatMode.CONFIRM else "автономный"
await update.message.reply_text(f"Текущий режим: {mode_name}")
return
mode_arg = context.args[0].lower()
if mode_arg == "confirm":
chat_state.set_mode(update.effective_chat.id, ChatMode.CONFIRM)
await update.message.reply_text("Режим: подтверждение для опасных действий")
elif mode_arg == "auto":
chat_state.set_mode(update.effective_chat.id, ChatMode.AUTO)
await update.message.reply_text("Режим: автономный")
else:
await update.message.reply_text("Использование: /mode confirm | auto")
async def confirm_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
await query.answer()
@ -170,41 +151,6 @@ async def confirm_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
await query.edit_message_text(f"✅ Выбрана модель: {model}\nВсе запросы будут идти через эту модель.")
return
if data == "confirm_yes":
pending = chat_state.get_pending_action(chat_id)
if not pending:
await query.edit_message_text("❌ Ошибка: действие не найдено")
return
await query.edit_message_text("✅ Подтверждено. Выполняю...")
prompt = pending.get("prompt")
tool = pending.get("tool")
dangerous = pending.get("dangerous", False)
chat_state.set_waiting_confirmation(chat_id, False)
model_raw = get_selected_model()
model = None
if tool == "opencode" and model_raw:
if model_raw.startswith("opencode/"):
model = model_raw.replace("opencode/", "", 1)
else:
model = model_raw
thinking_msg = await query.message.reply_text("🤔 Думаю...")
simple_prompt = prompt
result, success = await orchestrator.ask(simple_prompt, chat_id, tool, model, yolo=True)
text = result[:4096] if len(result) > 4096 else result
await query.message.reply_text(text, parse_mode="Markdown")
try:
await thinking_msg.delete()
except:
pass
elif data == "confirm_no":
chat_state.set_waiting_confirmation(chat_id, False)
await query.edit_message_text("❌ Отменено. Команда не будет выполнена.")
async def execute_tool_query(update, tool: str, prompt: str):
chat_id = update.message.chat.id if hasattr(update, 'message') else update.effective_chat.id
@ -234,11 +180,9 @@ async def qwen_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
prompt = " ".join(context.args)
chat_id = update.effective_chat.id
mode = chat_state.get_mode(chat_id)
use_yolo = mode == ChatMode.AUTO
thinking_msg = await update.message.reply_text("🤔 Думаю..." + (" (YOLO)" if use_yolo else ""))
result, success = await orchestrator.ask(prompt, chat_id, "qwen", None, yolo=use_yolo)
thinking_msg = await update.message.reply_text("🤔 Думаю...")
result, success = await orchestrator.ask(prompt, chat_id, "qwen", None, yolo=True)
text = result[:4096] if len(result) > 4096 else result
await update.message.reply_text(text)
try:
@ -281,11 +225,9 @@ async def open_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
model = "opencode/minimax-m2.5-free"
chat_id = update.effective_chat.id
mode = chat_state.get_mode(chat_id)
use_yolo = mode == ChatMode.AUTO
thinking_msg = await update.message.reply_text("🤔 Думаю..." + (" (YOLO)" if use_yolo else ""))
result, success = await orchestrator.ask(prompt, chat_id, "opencode", model, yolo=use_yolo)
thinking_msg = await update.message.reply_text("🤔 Думаю...")
result, success = await orchestrator.ask(prompt, chat_id, "opencode", model, yolo=True)
text = result[:4096] if len(result) > 4096 else result
await update.message.reply_text(text)
try:
@ -552,7 +494,6 @@ def main():
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("help", help_command))
application.add_handler(CommandHandler("mode", mode_command))
application.add_handler(CommandHandler("qwen", qwen_command))
application.add_handler(CommandHandler("open", open_command))
application.add_handler(CommandHandler("forget", forget_command))

View File

@ -5,11 +5,6 @@ from enum import Enum
logger = logging.getLogger(__name__)
class ChatMode(str, Enum):
CONFIRM = "confirm"
AUTO = "auto"
class XRayState(str, Enum):
"""Состояния для команды /xray"""
WAITING_EMAIL = "waiting_email"
@ -19,37 +14,6 @@ class ChatState:
def __init__(self):
self.states: Dict[int, dict] = {}
def get_mode(self, chat_id: int) -> ChatMode:
return self.states.get(chat_id, {}).get("mode", ChatMode.CONFIRM)
def set_mode(self, chat_id: int, mode: ChatMode):
if chat_id not in self.states:
self.states[chat_id] = {}
self.states[chat_id]["mode"] = mode
def is_waiting_confirmation(self, chat_id: int) -> bool:
return self.states.get(chat_id, {}).get("waiting_confirmation", False)
def set_waiting_confirmation(self, chat_id: int, waiting: bool, action_data: Optional[dict] = None):
if chat_id not in self.states:
self.states[chat_id] = {}
self.states[chat_id]["waiting_confirmation"] = waiting
if action_data:
self.states[chat_id]["pending_action"] = action_data
elif not waiting:
self.states[chat_id].pop("pending_action", None)
def get_pending_action(self, chat_id: int) -> Optional[dict]:
return self.states.get(chat_id, {}).get("pending_action")
def set_current_task(self, chat_id: int, task_id: Optional[str]):
if chat_id not in self.states:
self.states[chat_id] = {}
self.states[chat_id]["current_task"] = task_id
def get_current_task(self, chat_id: int) -> Optional[str]:
return self.states.get(chat_id, {}).get("current_task")
# Методы для состояния XRay
def set_xray_state(self, chat_id: int, state: Optional[XRayState]):
if chat_id not in self.states: