Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -239,7 +239,7 @@ async def root():
|
|
| 239 |
|
| 240 |
@app.post("/api/chat")
|
| 241 |
async def chat_with_ai(request: ChatRequest):
|
| 242 |
-
"""نقطة النهاية للمحادثة مع الذكاء الاصطناعي - النسخة الح
|
| 243 |
try:
|
| 244 |
logger.info(f"💬 طلب محادثة من العميل {request.client_id}: {request.message}")
|
| 245 |
update_client_activity(request.client_id, "chat")
|
|
@@ -268,12 +268,12 @@ async def chat_with_ai(request: ChatRequest):
|
|
| 268 |
return await handle_memory_scan(request)
|
| 269 |
elif "تثبيت" in user_message or "install" in user_message:
|
| 270 |
return await handle_tool_installation(request)
|
| 271 |
-
elif "مرحبا" in user_message or "اهلا" in user_message or "hello" in user_message:
|
| 272 |
-
return await handle_welcome(request)
|
| 273 |
elif "الذاكرة" in user_message or "memory" in user_message:
|
| 274 |
return await handle_memory_query(request)
|
|
|
|
|
|
|
| 275 |
else:
|
| 276 |
-
return await
|
| 277 |
|
| 278 |
except Exception as e:
|
| 279 |
logger.error(f"❌ خطأ في معالجة المحادثة: {e}")
|
|
@@ -281,11 +281,11 @@ async def chat_with_ai(request: ChatRequest):
|
|
| 281 |
|
| 282 |
async def handle_scan_programs(request: ChatRequest):
|
| 283 |
"""معالجة طلب مسح البرامج"""
|
| 284 |
-
thinking = "
|
| 285 |
|
| 286 |
response = ChatResponse(
|
| 287 |
thinking_process=thinking,
|
| 288 |
-
message="
|
| 289 |
actions=[
|
| 290 |
{
|
| 291 |
"type": "scan_installed_programs",
|
|
@@ -302,11 +302,11 @@ async def handle_scan_programs(request: ChatRequest):
|
|
| 302 |
|
| 303 |
async def handle_scan_processes(request: ChatRequest):
|
| 304 |
"""معالجة طلب مسح العمليات"""
|
| 305 |
-
thinking = "
|
| 306 |
|
| 307 |
response = ChatResponse(
|
| 308 |
thinking_process=thinking,
|
| 309 |
-
message="
|
| 310 |
actions=[
|
| 311 |
{
|
| 312 |
"type": "scan_running_processes",
|
|
@@ -323,7 +323,7 @@ async def handle_scan_processes(request: ChatRequest):
|
|
| 323 |
|
| 324 |
async def handle_reverse_engineering(request: ChatRequest):
|
| 325 |
"""معالجة طلب الهندسة العكسية"""
|
| 326 |
-
thinking = "
|
| 327 |
|
| 328 |
# استخراج مسار الملف من الرسالة
|
| 329 |
file_path = extract_file_path(request.message)
|
|
@@ -331,7 +331,7 @@ async def handle_reverse_engineering(request: ChatRequest):
|
|
| 331 |
if not file_path:
|
| 332 |
response = ChatResponse(
|
| 333 |
thinking_process=thinking + " لم يتم تحديد مسار الملف. طلب التوضيح من المستخدم.",
|
| 334 |
-
message="
|
| 335 |
actions=[
|
| 336 |
{
|
| 337 |
"type": "prepare_reverse_engineering",
|
|
@@ -346,7 +346,7 @@ async def handle_reverse_engineering(request: ChatRequest):
|
|
| 346 |
|
| 347 |
response = ChatResponse(
|
| 348 |
thinking_process=thinking + f" تم تحديد المسار: {file_path}. جاري إعداد أدوات الهندسة العكسية.",
|
| 349 |
-
message=f"
|
| 350 |
actions=[
|
| 351 |
{
|
| 352 |
"type": "reverse_engineer",
|
|
@@ -374,7 +374,7 @@ async def handle_reverse_engineering(request: ChatRequest):
|
|
| 374 |
|
| 375 |
async def handle_bot_development(request: ChatRequest):
|
| 376 |
"""معالجة طلب تطوير البوت"""
|
| 377 |
-
thinking = "
|
| 378 |
|
| 379 |
game_name = extract_game_name(request.message)
|
| 380 |
bot_type = extract_bot_type(request.message)
|
|
@@ -382,7 +382,7 @@ async def handle_bot_development(request: ChatRequest):
|
|
| 382 |
if not game_name:
|
| 383 |
response = ChatResponse(
|
| 384 |
thinking_process=thinking + " لم يتم تحديد اسم اللعبة. طلب التوضيح.",
|
| 385 |
-
message="
|
| 386 |
actions=[
|
| 387 |
{
|
| 388 |
"type": "prepare_bot_development",
|
|
@@ -393,8 +393,8 @@ async def handle_bot_development(request: ChatRequest):
|
|
| 393 |
)
|
| 394 |
else:
|
| 395 |
response = ChatResponse(
|
| 396 |
-
thinking_process=thinking + f" تطوير بوت {bot_type} للعبة {game_name}.
|
| 397 |
-
message=f"
|
| 398 |
actions=[
|
| 399 |
{
|
| 400 |
"type": "develop_bot",
|
|
@@ -405,14 +405,6 @@ async def handle_bot_development(request: ChatRequest):
|
|
| 405 |
"features": ["auto_detection", "memory_control", "image_recognition", "screen_capture"],
|
| 406 |
"save_to_memory": True
|
| 407 |
}
|
| 408 |
-
},
|
| 409 |
-
{
|
| 410 |
-
"type": "install_tool",
|
| 411 |
-
"description": "تثبيت أدوات تطوير البوت",
|
| 412 |
-
"parameters": {
|
| 413 |
-
"tool_name": "python",
|
| 414 |
-
"save_to_memory": True
|
| 415 |
-
}
|
| 416 |
}
|
| 417 |
]
|
| 418 |
)
|
|
@@ -421,11 +413,11 @@ async def handle_bot_development(request: ChatRequest):
|
|
| 421 |
|
| 422 |
async def handle_screenshot(request: ChatRequest):
|
| 423 |
"""معالجة طلب تصوير الشاشة"""
|
| 424 |
-
thinking = "
|
| 425 |
|
| 426 |
response = ChatResponse(
|
| 427 |
thinking_process=thinking,
|
| 428 |
-
message="
|
| 429 |
actions=[
|
| 430 |
{
|
| 431 |
"type": "take_screenshot",
|
|
@@ -441,20 +433,20 @@ async def handle_screenshot(request: ChatRequest):
|
|
| 441 |
|
| 442 |
async def handle_memory_scan(request: ChatRequest):
|
| 443 |
"""معالجة طلب مسح الذاكرة"""
|
| 444 |
-
thinking = "
|
| 445 |
|
| 446 |
process_name = extract_process_name(request.message)
|
| 447 |
|
| 448 |
if not process_name:
|
| 449 |
response = ChatResponse(
|
| 450 |
thinking_process=thinking + " لم يتم تحديد اسم العملية. طلب التوضيح.",
|
| 451 |
-
message="
|
| 452 |
actions=[]
|
| 453 |
)
|
| 454 |
else:
|
| 455 |
response = ChatResponse(
|
| 456 |
-
thinking_process=thinking + f" مسح ذاكرة العملية: {process_name}.
|
| 457 |
-
message=f"
|
| 458 |
actions=[
|
| 459 |
{
|
| 460 |
"type": "scan_game_memory",
|
|
@@ -472,20 +464,20 @@ async def handle_memory_scan(request: ChatRequest):
|
|
| 472 |
|
| 473 |
async def handle_tool_installation(request: ChatRequest):
|
| 474 |
"""معالجة طلب تثبيت الأدوات"""
|
| 475 |
-
thinking = "
|
| 476 |
|
| 477 |
tool_name = extract_tool_name(request.message)
|
| 478 |
|
| 479 |
if not tool_name:
|
| 480 |
response = ChatResponse(
|
| 481 |
thinking_process=thinking + " لم يتم تحديد الأداة. عرض القائمة.",
|
| 482 |
-
message="
|
| 483 |
actions=[]
|
| 484 |
)
|
| 485 |
else:
|
| 486 |
response = ChatResponse(
|
| 487 |
-
thinking_process=thinking + f" تثبيت الأداة: {tool_name}.
|
| 488 |
-
message=f"
|
| 489 |
actions=[
|
| 490 |
{
|
| 491 |
"type": "install_tool",
|
|
@@ -500,81 +492,91 @@ async def handle_tool_installation(request: ChatRequest):
|
|
| 500 |
|
| 501 |
return response
|
| 502 |
|
| 503 |
-
async def
|
| 504 |
-
"""معالجة
|
| 505 |
-
thinking = "
|
| 506 |
-
|
| 507 |
-
# استرجاع إحصائيات الذاكرة للعميل
|
| 508 |
-
memory_stats = await get_memory_stats_for_client(request.client_id)
|
| 509 |
|
| 510 |
response = ChatResponse(
|
| 511 |
thinking_process=thinking,
|
| 512 |
-
message=
|
| 513 |
-
|
| 514 |
-
f"• المحادثات: {memory_stats['conversations']}\n"
|
| 515 |
-
f"• تحليلات الألعاب: {memory_stats['game_analyses']}\n"
|
| 516 |
-
f"• الإجراءات: {memory_stats['actions']}\n\n"
|
| 517 |
-
f"🚀 **الميزات الحقيقية الجاهزة للتنفيذ على جهازك:**\n\n"
|
| 518 |
-
f"• 🔍 **مسح شامل** للبرامج والعمليات\n"
|
| 519 |
-
f"• 🎮 **تحليل الذاكرة** للألعاب والتعديل\n"
|
| 520 |
-
f"• 🤖 **تطوير بوتات** كاملة وتجربتها\n"
|
| 521 |
-
f"• 🔬 **هندسة عكسية** متقدمة للملفات\n"
|
| 522 |
-
f"• 📸 **تصوير الشاشة** والتسجيل\n"
|
| 523 |
-
f"• ⚡ **تثبيت أدوات** متخصصة\n\n"
|
| 524 |
-
f"💡 **كل شيء يتم حفظه تلقائياً في الذاكرة الدائمة!**\n\n"
|
| 525 |
-
f"ما المهمة التي تريد البدء بها؟",
|
| 526 |
-
actions=[
|
| 527 |
-
{
|
| 528 |
-
"type": "welcome",
|
| 529 |
-
"description": "ترحيب بالمستخدم وتحضير البيئة الحقيقية",
|
| 530 |
-
"parameters": {}
|
| 531 |
-
}
|
| 532 |
-
]
|
| 533 |
)
|
| 534 |
return response
|
| 535 |
|
| 536 |
async def handle_memory_query(request: ChatRequest):
|
| 537 |
"""معالجة استعلامات الذاكرة"""
|
| 538 |
-
thinking = "
|
| 539 |
|
| 540 |
memory_stats = await get_memory_stats_for_client(request.client_id)
|
| 541 |
|
| 542 |
response = ChatResponse(
|
| 543 |
thinking_process=thinking,
|
| 544 |
-
message=f"
|
| 545 |
-
f"📊 **التفاصيل:**\n"
|
| 546 |
-
f"• المحادثات المحفوظة: {memory_stats['conversations']}\n"
|
| 547 |
-
f"• تحليلات الألعاب: {memory_stats['game_analyses']}\n"
|
| 548 |
-
f"• معلومات النظام: {memory_stats['system_info']}\n"
|
| 549 |
-
f"• البرامج المثبتة: {memory_stats['installed_programs']}\n"
|
| 550 |
-
f"• سجل الإجراءات: {memory_stats['actions']}\n\n"
|
| 551 |
-
f"🔍 **آخر 5 محادثات:**\n{memory_stats['recent_conversations']}\n\n"
|
| 552 |
-
f"🎮 **الألعاب التي تم تحليلها:** {memory_stats['games_analyzed']}",
|
| 553 |
actions=[]
|
| 554 |
)
|
| 555 |
return response
|
| 556 |
|
| 557 |
-
async def
|
| 558 |
-
"""معالجة ال
|
| 559 |
-
thinking = "
|
| 560 |
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
}
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
return response
|
| 577 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
async def get_memory_stats_for_client(client_id: str):
|
| 579 |
"""الحصول على إحصائيات الذاكرة للعميل"""
|
| 580 |
conversations = len(get_client_memory(client_id, "conversation"))
|
|
@@ -583,22 +585,12 @@ async def get_memory_stats_for_client(client_id: str):
|
|
| 583 |
installed_programs = 1 if client_id in installed_programs_memory else 0
|
| 584 |
actions = len(get_action_history(client_id))
|
| 585 |
|
| 586 |
-
# آخر 5 محادثات
|
| 587 |
-
recent_convos = get_client_memory(client_id, "conversation", 5)
|
| 588 |
-
recent_text = "\n".join([f"• {conv['data'].get('user_message', '')[:50]}..." for conv in recent_convos])
|
| 589 |
-
|
| 590 |
-
# الألعاب التي تم تحليلها
|
| 591 |
-
games_analyzed = list(get_game_analysis(client_id).keys())
|
| 592 |
-
games_text = ", ".join(games_analyzed) if games_analyzed else "لا توجد"
|
| 593 |
-
|
| 594 |
return {
|
| 595 |
"conversations": conversations,
|
| 596 |
"game_analyses": game_analyses,
|
| 597 |
"system_info": system_info,
|
| 598 |
"installed_programs": installed_programs,
|
| 599 |
-
"actions": actions
|
| 600 |
-
"recent_conversations": recent_text,
|
| 601 |
-
"games_analyzed": games_text
|
| 602 |
}
|
| 603 |
|
| 604 |
def extract_file_path(message: str) -> str:
|
|
|
|
| 239 |
|
| 240 |
@app.post("/api/chat")
|
| 241 |
async def chat_with_ai(request: ChatRequest):
|
| 242 |
+
"""نقطة النهاية للمحادثة مع الذكاء الاصطناعي - النسخة المحسنة"""
|
| 243 |
try:
|
| 244 |
logger.info(f"💬 طلب محادثة من العميل {request.client_id}: {request.message}")
|
| 245 |
update_client_activity(request.client_id, "chat")
|
|
|
|
| 268 |
return await handle_memory_scan(request)
|
| 269 |
elif "تثبيت" in user_message or "install" in user_message:
|
| 270 |
return await handle_tool_installation(request)
|
|
|
|
|
|
|
| 271 |
elif "الذاكرة" in user_message or "memory" in user_message:
|
| 272 |
return await handle_memory_query(request)
|
| 273 |
+
elif "ماذا تستطيع" in user_message or "الميزات" in user_message or "capabilities" in user_message:
|
| 274 |
+
return await handle_capabilities_query(request)
|
| 275 |
else:
|
| 276 |
+
return await handle_general_conversation(request)
|
| 277 |
|
| 278 |
except Exception as e:
|
| 279 |
logger.error(f"❌ خطأ في معالجة المحادثة: {e}")
|
|
|
|
| 281 |
|
| 282 |
async def handle_scan_programs(request: ChatRequest):
|
| 283 |
"""معالجة طلب مسح البرامج"""
|
| 284 |
+
thinking = "المستخدم يطلب مسح البرامج المثبتة. جاري إعداد أمر المسح الشامل."
|
| 285 |
|
| 286 |
response = ChatResponse(
|
| 287 |
thinking_process=thinking,
|
| 288 |
+
message="جاري مسح البرامج المثبتة على جهازك...",
|
| 289 |
actions=[
|
| 290 |
{
|
| 291 |
"type": "scan_installed_programs",
|
|
|
|
| 302 |
|
| 303 |
async def handle_scan_processes(request: ChatRequest):
|
| 304 |
"""معالجة طلب مسح العمليات"""
|
| 305 |
+
thinking = "المستخدم يريد مسح العمليات النشطة. تحديد العمليات الجارية والألعاب النشطة."
|
| 306 |
|
| 307 |
response = ChatResponse(
|
| 308 |
thinking_process=thinking,
|
| 309 |
+
message="جاري مسح العمليات النشطة على جهازك...",
|
| 310 |
actions=[
|
| 311 |
{
|
| 312 |
"type": "scan_running_processes",
|
|
|
|
| 323 |
|
| 324 |
async def handle_reverse_engineering(request: ChatRequest):
|
| 325 |
"""معالجة طلب الهندسة العكسية"""
|
| 326 |
+
thinking = "المستخدم يطلب هندسة عكسية لملف. تحديد المسار وتحليل المتطلبات."
|
| 327 |
|
| 328 |
# استخراج مسار الملف من الرسالة
|
| 329 |
file_path = extract_file_path(request.message)
|
|
|
|
| 331 |
if not file_path:
|
| 332 |
response = ChatResponse(
|
| 333 |
thinking_process=thinking + " لم يتم تحديد مسار الملف. طلب التوضيح من المستخدم.",
|
| 334 |
+
message="أحتاج إلى مسار الملف للبدء في الهندسة العكسية. مثال: `F:\\Coven Kal\\engine.exe`",
|
| 335 |
actions=[
|
| 336 |
{
|
| 337 |
"type": "prepare_reverse_engineering",
|
|
|
|
| 346 |
|
| 347 |
response = ChatResponse(
|
| 348 |
thinking_process=thinking + f" تم تحديد المسار: {file_path}. جاري إعداد أدوات الهندسة العكسية.",
|
| 349 |
+
message=f"جاري تحضير الهندسة العكسية للملف: `{file_path}`",
|
| 350 |
actions=[
|
| 351 |
{
|
| 352 |
"type": "reverse_engineer",
|
|
|
|
| 374 |
|
| 375 |
async def handle_bot_development(request: ChatRequest):
|
| 376 |
"""معالجة طلب تطوير البوت"""
|
| 377 |
+
thinking = "المستخدم يطلب تطوير بوت. تحديد نوع البوت واللعبة المستهدفة."
|
| 378 |
|
| 379 |
game_name = extract_game_name(request.message)
|
| 380 |
bot_type = extract_bot_type(request.message)
|
|
|
|
| 382 |
if not game_name:
|
| 383 |
response = ChatResponse(
|
| 384 |
thinking_process=thinking + " لم يتم تحديد اسم اللعبة. طلب التوضيح.",
|
| 385 |
+
message="أخبرني اسم اللعبة ونوع البوت المطلوب (مزرعة، قتال، إلخ).",
|
| 386 |
actions=[
|
| 387 |
{
|
| 388 |
"type": "prepare_bot_development",
|
|
|
|
| 393 |
)
|
| 394 |
else:
|
| 395 |
response = ChatResponse(
|
| 396 |
+
thinking_process=thinking + f" تطوير بوت {bot_type} للعبة {game_name}.",
|
| 397 |
+
message=f"بدأت تطوير بوت {bot_type} للعبة {game_name}.",
|
| 398 |
actions=[
|
| 399 |
{
|
| 400 |
"type": "develop_bot",
|
|
|
|
| 405 |
"features": ["auto_detection", "memory_control", "image_recognition", "screen_capture"],
|
| 406 |
"save_to_memory": True
|
| 407 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
}
|
| 409 |
]
|
| 410 |
)
|
|
|
|
| 413 |
|
| 414 |
async def handle_screenshot(request: ChatRequest):
|
| 415 |
"""معالجة طلب تصوير الشاشة"""
|
| 416 |
+
thinking = "المستخدم يطلب تصوير شاشة جهازه. إعداد أمر التقاط الصورة."
|
| 417 |
|
| 418 |
response = ChatResponse(
|
| 419 |
thinking_process=thinking,
|
| 420 |
+
message="جاري التقاط صورة لشاشة جهازك...",
|
| 421 |
actions=[
|
| 422 |
{
|
| 423 |
"type": "take_screenshot",
|
|
|
|
| 433 |
|
| 434 |
async def handle_memory_scan(request: ChatRequest):
|
| 435 |
"""معالجة طلب مسح الذاكرة"""
|
| 436 |
+
thinking = "المستخدم يريد مسح ذاكرة لعبة. تحديد اسم العملية المستهدفة."
|
| 437 |
|
| 438 |
process_name = extract_process_name(request.message)
|
| 439 |
|
| 440 |
if not process_name:
|
| 441 |
response = ChatResponse(
|
| 442 |
thinking_process=thinking + " لم يتم تحديد اسم العملية. طلب التوضيح.",
|
| 443 |
+
message="أخبرني اسم العملية أو اللعبة التي تريد مسح ذاكرتها.",
|
| 444 |
actions=[]
|
| 445 |
)
|
| 446 |
else:
|
| 447 |
response = ChatResponse(
|
| 448 |
+
thinking_process=thinking + f" مسح ذاكرة العملية: {process_name}.",
|
| 449 |
+
message=f"جاري مسح ذاكرة اللعبة: {process_name}",
|
| 450 |
actions=[
|
| 451 |
{
|
| 452 |
"type": "scan_game_memory",
|
|
|
|
| 464 |
|
| 465 |
async def handle_tool_installation(request: ChatRequest):
|
| 466 |
"""معالجة طلب تثبيت الأدوات"""
|
| 467 |
+
thinking = "المستخدم يريد تثبيت أداة. تحديد الأداة المطلوبة."
|
| 468 |
|
| 469 |
tool_name = extract_tool_name(request.message)
|
| 470 |
|
| 471 |
if not tool_name:
|
| 472 |
response = ChatResponse(
|
| 473 |
thinking_process=thinking + " لم يتم تحديد الأداة. عرض القائمة.",
|
| 474 |
+
message="الأدوات المتاحة: cheatengine, python, ida, x64dbg. ما الأداة التي تريدها؟",
|
| 475 |
actions=[]
|
| 476 |
)
|
| 477 |
else:
|
| 478 |
response = ChatResponse(
|
| 479 |
+
thinking_process=thinking + f" تثبيت الأداة: {tool_name}.",
|
| 480 |
+
message=f"جاري تثبيت الأداة: {tool_name}",
|
| 481 |
actions=[
|
| 482 |
{
|
| 483 |
"type": "install_tool",
|
|
|
|
| 492 |
|
| 493 |
return response
|
| 494 |
|
| 495 |
+
async def handle_capabilities_query(request: ChatRequest):
|
| 496 |
+
"""معالجة استعلام الميزات"""
|
| 497 |
+
thinking = "المستخدم يطلب معرفة الميزات المتاحة."
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
response = ChatResponse(
|
| 500 |
thinking_process=thinking,
|
| 501 |
+
message="**الميزات المتاحة:**\n\n• 🔍 مسح البرامج والعمليات\n• 🎮 تحليل ذاكرة الألعاب\n• 🤖 تطوير البوتات\n• 🔬 الهندسة العكسية\n• 📸 تصوير الشاشة\n• ⚡ تثبيت الأدوات\n\nما الذي تريد القيام به؟",
|
| 502 |
+
actions=[]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
)
|
| 504 |
return response
|
| 505 |
|
| 506 |
async def handle_memory_query(request: ChatRequest):
|
| 507 |
"""معالجة استعلامات الذاكرة"""
|
| 508 |
+
thinking = "المستخدم يطلب معلومات عن الذاكرة. تجهيز إحصائيات الذاكرة."
|
| 509 |
|
| 510 |
memory_stats = await get_memory_stats_for_client(request.client_id)
|
| 511 |
|
| 512 |
response = ChatResponse(
|
| 513 |
thinking_process=thinking,
|
| 514 |
+
message=f"**إحصائيات الذاكرة:**\n• المحادثات: {memory_stats['conversations']}\n• تحليلات الألعاب: {memory_stats['game_analyses']}\n• الإجراءات: {memory_stats['actions']}",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
actions=[]
|
| 516 |
)
|
| 517 |
return response
|
| 518 |
|
| 519 |
+
async def handle_general_conversation(request: ChatRequest):
|
| 520 |
+
"""معالجة المحادثة العامة - النسخة المحسنة"""
|
| 521 |
+
thinking = "تحليل رسالة المستخدم العامة والرد بشكل طبيعي مع تحديد الإجراءات المناسبة."
|
| 522 |
|
| 523 |
+
# تحليل نية المستخدم من الرسالة
|
| 524 |
+
user_intent = analyze_user_intent(request.message)
|
| 525 |
+
|
| 526 |
+
if user_intent == "greeting":
|
| 527 |
+
response = ChatResponse(
|
| 528 |
+
thinking_process=thinking + " المستخدم يرسل تحية. الرد بترحيب بسيط.",
|
| 529 |
+
message="مرحباً! كيف يمكنني مساعدتك اليوم؟",
|
| 530 |
+
actions=[]
|
| 531 |
+
)
|
| 532 |
+
elif user_intent == "thanks":
|
| 533 |
+
response = ChatResponse(
|
| 534 |
+
thinking_process=thinking + " المستخدم يشكر. الرد بأدب.",
|
| 535 |
+
message="على الرحب والسعة! هل هناك شيء آخر تحتاج المساعدة فيه؟",
|
| 536 |
+
actions=[]
|
| 537 |
+
)
|
| 538 |
+
elif user_intent == "question":
|
| 539 |
+
response = ChatResponse(
|
| 540 |
+
thinking_process=thinking + " المستخدم يطرح سؤالاً عاماً. تقديم إجابة مفيدة.",
|
| 541 |
+
message="أفهم سؤالك. يمكنني مساعدتك في مهام مثل تحليل البرامج، تطوير البوتات، الهندسة العكسية، وغيرها. هل يمكنك توضيح طلبك أكثر؟",
|
| 542 |
+
actions=[]
|
| 543 |
+
)
|
| 544 |
+
else:
|
| 545 |
+
response = ChatResponse(
|
| 546 |
+
thinking_process=thinking + " رسالة عامة. الرد بشكل طبيعي وتقديم المساعدة.",
|
| 547 |
+
message="فهمت ما تقصد. سأقوم بمساعدتك في هذا الأمر. هل يمكنك إعطائي المزيد من التفاصيل أو توضيح ما تريد بالضبط؟",
|
| 548 |
+
actions=[
|
| 549 |
+
{
|
| 550 |
+
"type": "general_analysis",
|
| 551 |
+
"description": "تحليل المهمة العامة وتحديد المتطلبات",
|
| 552 |
+
"parameters": {
|
| 553 |
+
"user_message": request.message,
|
| 554 |
+
"analysis_type": "comprehensive",
|
| 555 |
+
"save_to_memory": True
|
| 556 |
+
}
|
| 557 |
}
|
| 558 |
+
]
|
| 559 |
+
)
|
| 560 |
+
|
| 561 |
return response
|
| 562 |
|
| 563 |
+
def analyze_user_intent(message: str) -> str:
|
| 564 |
+
"""تحليل نية المستخدم من الرسالة"""
|
| 565 |
+
message_lower = message.lower()
|
| 566 |
+
|
| 567 |
+
greeting_words = ["مرحبا", "اهلا", "سلام", "السلام", "hello", "hi", "hey"]
|
| 568 |
+
thanks_words = ["شكرا", "متشكر", "thanks", "thank you"]
|
| 569 |
+
question_words = ["كيف", "لماذا", "متى", "أين", "ماذا", "هل", "?", "what", "how", "when", "where", "why"]
|
| 570 |
+
|
| 571 |
+
if any(word in message_lower for word in greeting_words):
|
| 572 |
+
return "greeting"
|
| 573 |
+
elif any(word in message_lower for word in thanks_words):
|
| 574 |
+
return "thanks"
|
| 575 |
+
elif any(word in message_lower for word in question_words):
|
| 576 |
+
return "question"
|
| 577 |
+
else:
|
| 578 |
+
return "general"
|
| 579 |
+
|
| 580 |
async def get_memory_stats_for_client(client_id: str):
|
| 581 |
"""الحصول على إحصائيات الذاكرة للعميل"""
|
| 582 |
conversations = len(get_client_memory(client_id, "conversation"))
|
|
|
|
| 585 |
installed_programs = 1 if client_id in installed_programs_memory else 0
|
| 586 |
actions = len(get_action_history(client_id))
|
| 587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
return {
|
| 589 |
"conversations": conversations,
|
| 590 |
"game_analyses": game_analyses,
|
| 591 |
"system_info": system_info,
|
| 592 |
"installed_programs": installed_programs,
|
| 593 |
+
"actions": actions
|
|
|
|
|
|
|
| 594 |
}
|
| 595 |
|
| 596 |
def extract_file_path(message: str) -> str:
|