eddddyy commited on
Commit
2e1fa69
Β·
verified Β·
1 Parent(s): 51354f3

Update executor.py

Browse files
Files changed (1) hide show
  1. 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
- if "chrome" in command_text.lower():
7
- subprocess.Popen(["chrome"])
8
- return "βœ… Opening Chrome..."
 
 
 
 
 
 
 
 
9
  elif command_type == "screenshot":
10
- return "πŸ“Έ Simulated screenshot taken."
 
 
 
 
 
11
  elif command_type == "create_file":
12
- with open("new_file.txt", "w") as f:
 
13
  f.write("Hello from your AI assistant.")
14
- return "βœ… File 'new_file.txt' created."
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  except Exception as e:
16
  return f"❌ Error while executing command: {e}"
17
- return None
 
 
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."