File size: 1,323 Bytes
90d2159
 
c5f750a
90d2159
40a7102
 
90d2159
 
40a7102
 
 
 
f6da057
 
40a7102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eada831
dab61c8
eada831
9ffa70c
40a7102
 
 
9ffa70c
f6da057
eada831
9ffa70c
eada831
9ffa70c
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
import time
import logging

class VirtualRobot:
    """Enhanced virtual robot with state management"""
    
    def __init__(self):
        self.state = "IDLE"
        logging.info("πŸ€– Virtual Robot initialized")
    
    def perform_action(self, command: str) -> str:
        """Main action processor with validation"""
        command = (command or "").strip().lower()
        
        if not command:
            return "❌ Please enter a command"
        
        try:
            if command == "wave":
                return self._wave()
            elif command.startswith("say"):
                return self._speak(command[3:].strip())
            return "❓ Try 'wave' or 'say [message]'"
        except Exception as e:
            logging.error(f"Action failed: {str(e)}")
            return f"⚠️ Error: {str(e)}"
    
    def _wave(self) -> str:
        """Handle wave action"""
        self.state = "WAVING"
        time.sleep(0.5)
        self.state = "IDLE"
        return "πŸ‘‹ Wave complete!"
    
    def _speak(self, message: str) -> str:
        """Handle speak action"""
        if not message:
            return "❌ No message provided"
        self.state = "SPEAKING"
        time.sleep(max(0.3, len(message)*0.05))
        self.state = "IDLE"
        return f"πŸ—£οΈ {message.capitalize()}"