File size: 1,835 Bytes
2e1fa69
85bd391
2e1fa69
 
85bd391
 
 
 
2e1fa69
 
 
 
 
 
 
 
 
 
 
85bd391
2e1fa69
 
 
 
 
 
85bd391
2e1fa69
 
85bd391
2e1fa69
 
 
 
 
 
 
 
 
 
 
 
 
 
85bd391
 
2e1fa69
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import subprocess
from datetime import datetime
from config import OS_COMMANDS, TEMP_DIR

def execute_command(command_type: str, command_text: str) -> str:
    try:
        if command_type == "open_app":
            for app, cmd in OS_COMMANDS.get("open", {}).items():
                if app in command_text.lower():
                    subprocess.Popen(cmd.split())
                    return f"βœ… Opening {app.title()}..."

        elif command_type == "close_app":
            for app, cmd in OS_COMMANDS.get("close", {}).items():
                if app in command_text.lower():
                    os.system(cmd)
                    return f"πŸ›‘ Closing {app.title()}..."

        elif command_type == "screenshot":
            screenshot_path = os.path.join(TEMP_DIR, f"screenshot_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png")
            cmd = OS_COMMANDS["screenshot"]["default"]
            cmd = cmd.replace("screenshot.png", screenshot_path)
            os.system(cmd)
            return f"πŸ“Έ Screenshot saved to: {screenshot_path}"

        elif command_type == "create_file":
            filename = "new_file.txt"
            with open(filename, "w") as f:
                f.write("Hello from your AI assistant.")
            return f"βœ… File '{filename}' created."

        elif command_type == "shutdown":
            os.system(OS_COMMANDS["shutdown"])
            return "πŸ”Œ Shutting down..."

        elif command_type == "restart":
            os.system(OS_COMMANDS["restart"])
            return "πŸ”„ Restarting system..."

        elif command_type == "lock":
            os.system(OS_COMMANDS["lock"])
            return "πŸ”’ System locked."

    except Exception as e:
        return f"❌ Error while executing command: {e}"

    return "⚠️ Command not recognized or not supported yet."