From 1b19c368ff0bb79350ac5913910a7ec5f16e4bbf Mon Sep 17 00:00:00 2001 From: "info@pi-farm.de" Date: Sun, 8 Mar 2026 01:38:05 +0000 Subject: [PATCH] source/main.py aktualisiert --- source/main.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/main.py b/source/main.py index ef186db..2deeb58 100644 --- a/source/main.py +++ b/source/main.py @@ -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")