source/main.py aktualisiert

This commit is contained in:
2026-03-08 01:38:05 +00:00
parent 1ffb7cec26
commit 1b19c368ff

View File

@@ -9,6 +9,7 @@ import re
import httpx
import struct
import termios
from datetime import datetime
from pathlib import Path
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
@@ -134,7 +135,8 @@ def get_system_prompt():
async def get_ai_response(user_input, system_prompt):
global chat_history
chat_history.append({"role": "user", "content": user_input})
now = datetime.now().strftime("%d.%m.%Y %H:%M")
chat_history.append({"role": "user", "content": user_input, "timestamp": now})
chat_history = chat_history[-30:]
ai_msg = ""
@@ -199,7 +201,8 @@ async def get_ai_response(user_input, system_prompt):
print(f"KI Fehler: {e}")
# 3. Die Antwort der KI ebenfalls ins Gedächtnis aufnehmen
chat_history.append({"role": "assistant", "content": ai_msg})
now = datetime.now().strftime("%d.%m.%Y %H:%M")
chat_history.append({"role": "assistant", "content": ai_msg, "timestamp": now})
return ai_msg
@@ -264,8 +267,8 @@ async def handle_telegram_message(update: Update, context: ContextTypes.DEFAULT_
result_text = output[:4000] if output else "✅ Befehl ohne Output ausgeführt."
await update.message.reply_text(f"💻 **Output von {n['name']}:**\n```\n{result_text}\n```", parse_mode='Markdown')
chat_history.append({"role": "user", "content": f"[SYSTEM] Befehl '{cmd}' auf {target} fertig:\n{result_text}"})
now = datetime.now().strftime("%d.%m.%Y %H:%M")
chat_history.append({"role": "user", "content": f"[SYSTEM] Befehl '{cmd}' auf {target} fertig:\n{result_text}", "timestamp": now})
except Exception as e:
await update.message.reply_text(f"❌ Fehler bei der Ausführung: {e}")
else:
@@ -615,7 +618,8 @@ async def run_remote_task(ip, user, cmd):
out = line.decode('utf-8', errors='ignore').strip()
if out: await manager.broadcast(f"🛠️ {out}"); full_output += out + "\n"
await proc.wait()
chat_history.append({"role": "user", "content": f"[SYSTEM] Befehl '{cmd}' auf {ip} fertig:\n{full_output or 'Kein Output'}"})
now = datetime.now().strftime("%d.%m.%Y %H:%M")
chat_history.append({"role": "user", "content": f"[SYSTEM] Befehl '{cmd}' auf {ip} fertig:\n{full_output or 'Kein Output'}", "timestamp": now})
# --- Settings API ---
@app.get("/api/settings")