Update executor.py
Browse files- executor.py +38 -7
executor.py
CHANGED
|
@@ -1,17 +1,48 @@
|
|
|
|
|
| 1 |
import subprocess
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def execute_command(command_type: str, command_text: str) -> str:
|
| 4 |
try:
|
| 5 |
if command_type == "open_app":
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
elif command_type == "screenshot":
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
elif command_type == "create_file":
|
| 12 |
-
|
|
|
|
| 13 |
f.write("Hello from your AI assistant.")
|
| 14 |
-
return "β
File '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except Exception as e:
|
| 16 |
return f"β Error while executing command: {e}"
|
| 17 |
-
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import subprocess
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from config import OS_COMMANDS, TEMP_DIR
|
| 5 |
|
| 6 |
def execute_command(command_type: str, command_text: str) -> str:
|
| 7 |
try:
|
| 8 |
if command_type == "open_app":
|
| 9 |
+
for app, cmd in OS_COMMANDS.get("open", {}).items():
|
| 10 |
+
if app in command_text.lower():
|
| 11 |
+
subprocess.Popen(cmd.split())
|
| 12 |
+
return f"β
Opening {app.title()}..."
|
| 13 |
+
|
| 14 |
+
elif command_type == "close_app":
|
| 15 |
+
for app, cmd in OS_COMMANDS.get("close", {}).items():
|
| 16 |
+
if app in command_text.lower():
|
| 17 |
+
os.system(cmd)
|
| 18 |
+
return f"π Closing {app.title()}..."
|
| 19 |
+
|
| 20 |
elif command_type == "screenshot":
|
| 21 |
+
screenshot_path = os.path.join(TEMP_DIR, f"screenshot_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png")
|
| 22 |
+
cmd = OS_COMMANDS["screenshot"]["default"]
|
| 23 |
+
cmd = cmd.replace("screenshot.png", screenshot_path)
|
| 24 |
+
os.system(cmd)
|
| 25 |
+
return f"πΈ Screenshot saved to: {screenshot_path}"
|
| 26 |
+
|
| 27 |
elif command_type == "create_file":
|
| 28 |
+
filename = "new_file.txt"
|
| 29 |
+
with open(filename, "w") as f:
|
| 30 |
f.write("Hello from your AI assistant.")
|
| 31 |
+
return f"β
File '{filename}' created."
|
| 32 |
+
|
| 33 |
+
elif command_type == "shutdown":
|
| 34 |
+
os.system(OS_COMMANDS["shutdown"])
|
| 35 |
+
return "π Shutting down..."
|
| 36 |
+
|
| 37 |
+
elif command_type == "restart":
|
| 38 |
+
os.system(OS_COMMANDS["restart"])
|
| 39 |
+
return "π Restarting system..."
|
| 40 |
+
|
| 41 |
+
elif command_type == "lock":
|
| 42 |
+
os.system(OS_COMMANDS["lock"])
|
| 43 |
+
return "π System locked."
|
| 44 |
+
|
| 45 |
except Exception as e:
|
| 46 |
return f"β Error while executing command: {e}"
|
| 47 |
+
|
| 48 |
+
return "β οΈ Command not recognized or not supported yet."
|