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()}"