source/main.py aktualisiert
This commit is contained in:
@@ -9,6 +9,7 @@ import re
|
|||||||
import httpx
|
import httpx
|
||||||
import struct
|
import struct
|
||||||
import termios
|
import termios
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import ApplicationBuilder, ContextTypes, MessageHandler, filters
|
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):
|
async def get_ai_response(user_input, system_prompt):
|
||||||
global chat_history
|
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:]
|
chat_history = chat_history[-30:]
|
||||||
ai_msg = ""
|
ai_msg = ""
|
||||||
|
|
||||||
@@ -199,7 +201,8 @@ async def get_ai_response(user_input, system_prompt):
|
|||||||
print(f"KI Fehler: {e}")
|
print(f"KI Fehler: {e}")
|
||||||
|
|
||||||
# 3. Die Antwort der KI ebenfalls ins Gedächtnis aufnehmen
|
# 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
|
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."
|
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')
|
await update.message.reply_text(f"💻 **Output von {n['name']}:**\n```\n{result_text}\n```", parse_mode='Markdown')
|
||||||
|
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}"})
|
chat_history.append({"role": "user", "content": f"[SYSTEM] Befehl '{cmd}' auf {target} fertig:\n{result_text}", "timestamp": now})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await update.message.reply_text(f"❌ Fehler bei der Ausführung: {e}")
|
await update.message.reply_text(f"❌ Fehler bei der Ausführung: {e}")
|
||||||
else:
|
else:
|
||||||
@@ -615,7 +618,8 @@ async def run_remote_task(ip, user, cmd):
|
|||||||
out = line.decode('utf-8', errors='ignore').strip()
|
out = line.decode('utf-8', errors='ignore').strip()
|
||||||
if out: await manager.broadcast(f"🛠️ {out}"); full_output += out + "\n"
|
if out: await manager.broadcast(f"🛠️ {out}"); full_output += out + "\n"
|
||||||
await proc.wait()
|
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 ---
|
# --- Settings API ---
|
||||||
@app.get("/api/settings")
|
@app.get("/api/settings")
|
||||||
|
|||||||
Reference in New Issue
Block a user