""" EntertainmentSkill - Piadas, Dicas e Citações em uma skill agrupada """ from modules.skills.base_skill import BaseSkill from modules.api_integrations.entertainment_providers import EntertainmentProviders class EntertainmentSkill(BaseSkill): """ Skill de entretenimento que retorna: - Piadas (Joke API + fallback local) - Dicas (Advice Slip API + fallback local) - Citações (Quotable API + fallback local) Usa fallback automático se a API primária falhar """ def __init__(self): super().__init__( name="get_entertainment", description="Retorna piadas, dicas ou citações com fallbacks automáticos" ) def get_primary_provider(self): """Tipo depende do parâmetro 'tipo'""" return self.comedy_or_advice def get_fallback_chain(self): """Fallbacks locais""" return [ self.fallback_entertainment, ] def comedy_or_advice(self, tipo: str = "random", **kwargs) -> dict: """ Baseado no tipo, retorna piada, dica ou citação """ tipo = tipo.lower().strip() if tipo == "joke": result = EntertainmentProviders.get_joke() if result and result.get("sucesso"): return result return {"sucesso": False, "erro": "Joke API falhou"} elif tipo == "advice": result = EntertainmentProviders.get_advice() if result and result.get("sucesso"): return result return {"sucesso": False, "erro": "Advice API falhou"} elif tipo == "quote": result = EntertainmentProviders.get_quote() if result and result.get("sucesso"): return result return {"sucesso": False, "erro": "Quote API falhou"} else: # random import random tipo_aleatorio = random.choice(["joke", "advice", "quote"]) return self.comedy_or_advice(tipo=tipo_aleatorio, **kwargs) def fallback_entertainment(self, tipo: str = "random", **kwargs) -> dict: """ Fallback 1: Entertainment local Usa cache de piadas, dicas e citações """ tipo = tipo.lower().strip() if tipo == "joke": return EntertainmentProviders.get_joke_fallback() elif tipo == "advice": return EntertainmentProviders.get_advice_fallback() elif tipo == "quote": return EntertainmentProviders.get_quote_fallback() else: # Random entre os 3 import random tipo_aleatorio = random.choice(["joke", "advice", "quote"]) return self.fallback_entertainment(tipo=tipo_aleatorio, **kwargs) def _get_error_suggestion(self) -> str: """Sugestão quando tudo falha""" return "Tenta de novo em alguns segundos"