AI Update: پیده سازی کن

This commit is contained in:
Antigravity Bot
2026-08-30 12:28:49 +03:30
parent b2ba9a17fd
commit 64f99b542a
5 changed files with 434 additions and 31 deletions
+103 -11
View File
@@ -4557,6 +4557,89 @@ async def callback_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
except Exception:
await query.message.reply_html(text, reply_markup=markup, disable_web_page_preview=True)
elif data.startswith("aibtn:"):
btn_id = data.split(":", 1)[1].strip()
from bot_actions import get_ai_button_payload
payload_data = get_ai_button_payload(btn_id)
if not payload_data:
await query.answer("⚠️ این دکمه منقضی شده یا نامعتبر است." if is_fa else "⚠️ This button has expired or is invalid.", show_alert=True)
return
act_type = payload_data.get("type", "prompt")
act_value = payload_data.get("value", "").strip()
btn_project = payload_data.get("project")
if act_type == "prompt":
await query.answer("🧠 در حال ارسال دستور به هوش مصنوعی..." if is_fa else "🧠 Processing prompt with AI...")
if btn_project:
accessible = session_manager.get_all_accessible_projects(chat_id)
for k, p in accessible.items():
if k.lower() == btn_project.lower() or p.name.lower() == btn_project.lower():
session.current_project = p.name
session_manager.save()
break
prompt_echo = (
f"💬 <b>دستور ارسالی:</b> <code>{escape_html(act_value)}</code>"
if is_fa else
f"💬 <b>Sent prompt:</b> <code>{escape_html(act_value)}</code>"
)
try:
await query.message.reply_html(prompt_echo)
except Exception:
pass
asyncio.create_task(process_agent_turn_by_chat_id(context.application, chat_id, act_value))
elif act_type == "cmd":
await query.answer("⚡ در حال اجرای دستور..." if is_fa else "⚡ Running command...")
cmd = act_value
if cmd.startswith("/"):
cmd_parts = cmd.split(maxsplit=1)
c_name = cmd_parts[0].lower()
if c_name in ("/usage", "/quota", "/credits", "/credit"):
text, markup = await build_usage_report(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/status", "/stats", "/sys"):
text, markup = build_server_hardware_menu(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/git", "/gitea"):
text, markup = await build_git_menu(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/tasks", "/cron", "/schedule"):
text, markup = build_tasks_menu(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/memory", "/mem"):
text, markup = build_memory_menu(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/projects", "/proj"):
text, markup = build_projects_menu(chat_id)
await query.message.reply_html(text, reply_markup=markup)
elif c_name in ("/backup", "/export"):
if curr_proj:
await query.message.reply_html("📦 در حال تهیه فایل پشتیبان..." if is_fa else "📦 Creating backup...")
zip_p = await backup_manager.create_project_backup(curr_proj.workspace, curr_proj.name)
if zip_p and zip_p.exists():
await context.bot.send_document(
chat_id=chat_id,
document=zip_p.open("rb"),
filename=zip_p.name,
caption=f"📦 Backup of <b>{escape_html(curr_proj.name)}</b>",
parse_mode=constants.ParseMode.HTML,
)
else:
await query.message.reply_html("❌ خطا در ایجاد پشتیبان." if is_fa else "❌ Failed to create backup.")
else:
asyncio.create_task(process_agent_turn_by_chat_id(context.application, chat_id, cmd))
else:
asyncio.create_task(process_agent_turn_by_chat_id(context.application, chat_id, cmd))
elif act_type == "action":
query.data = act_value
await callback_handler(update, context)
return
elif data in ("btn_usage_menu", "btn_usage_refresh"):
await query.answer("⏳ استعلام مصرف..." if is_fa else "⏳ Refreshing...")
text, markup = await build_usage_report(chat_id)
@@ -6417,8 +6500,8 @@ async def process_agent_turn(
# 1. Convert Markdown to Telegram HTML first
formatted_html = markdown_to_telegram_html(raw_text)
# 2. Intercept and execute all AI Bot Actions (Model switching, Effort, Languages, Projects, Tasks, Caddy, Files, etc.)
formatted_html, created_tasks, executed_actions = await process_all_ai_actions(
# 2. Intercept and execute all AI Bot Actions (Model switching, Effort, Languages, Projects, Tasks, Caddy, Buttons, Files, etc.)
formatted_html, created_tasks, executed_actions, inline_markup = await process_all_ai_actions(
raw_text=formatted_html,
chat_id=chat_id,
project_name=curr_proj.name,
@@ -6428,17 +6511,26 @@ async def process_agent_turn(
chunks = split_message(formatted_html, max_length=settings.max_message_length)
first_chunk = chunks[0] if chunks else "✅ <i>Done</i>"
try:
await status_msg.edit_text(first_chunk, parse_mode=constants.ParseMode.HTML, disable_web_page_preview=True, reply_markup=None)
except Exception:
await status_msg.edit_text(escape_html(formatted_html[:settings.max_message_length]), parse_mode=constants.ParseMode.HTML, reply_markup=None)
for follow_up in chunks[1:]:
if len(chunks) <= 1:
first_chunk = chunks[0] if chunks else "✅ <i>Done</i>"
try:
await update.effective_message.reply_html(follow_up, disable_web_page_preview=True)
await status_msg.edit_text(first_chunk, parse_mode=constants.ParseMode.HTML, disable_web_page_preview=True, reply_markup=inline_markup)
except Exception:
await update.effective_message.reply_text(follow_up)
await status_msg.edit_text(escape_html(formatted_html[:settings.max_message_length]), parse_mode=constants.ParseMode.HTML, reply_markup=inline_markup)
else:
first_chunk = chunks[0] if chunks else "✅ <i>Done</i>"
try:
await status_msg.edit_text(first_chunk, parse_mode=constants.ParseMode.HTML, disable_web_page_preview=True, reply_markup=None)
except Exception:
await status_msg.edit_text(escape_html(formatted_html[:settings.max_message_length]), parse_mode=constants.ParseMode.HTML, reply_markup=None)
for i, follow_up in enumerate(chunks[1:]):
is_last = (i == len(chunks[1:]) - 1)
chunk_markup = inline_markup if is_last else None
try:
await update.effective_message.reply_html(follow_up, disable_web_page_preview=True, reply_markup=chunk_markup)
except Exception:
await update.effective_message.reply_text(follow_up, reply_markup=chunk_markup)
# Mark successfully completed and delivered
session.turn_in_progress = False