bentosmau commited on
Commit
9e90352
·
1 Parent(s): 18dae39

Update game search to fetch detailed information and reformat output

Browse files

Modify the Roblox API integration to first find a game's universe ID, then fetch comprehensive game details (genre, visits, update date, description) using a separate endpoint, and finally reformat the output to display all relevant game information.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e3ff2484-bbd8-4aba-bea0-1940769b874a
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 3cbcde20-7cbf-4b2a-b716-e9a9a4ee8fdd
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1739408b-93a5-479b-a658-30f2493b0467/e3ff2484-bbd8-4aba-bea0-1940769b874a/h035Gwm
Replit-Helium-Checkpoint-Created: true

Files changed (1) hide show
  1. chat-app/roblox_api.py +54 -12
chat-app/roblox_api.py CHANGED
@@ -77,12 +77,35 @@ def buscar_juego(nombre):
77
  juegos = datos.get("games", [])
78
  if not juegos:
79
  return None
80
- juego = juegos[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  return {
82
- "nombre": juego.get("name"),
83
- "creador": juego.get("creatorName"),
84
- "jugando": juego.get("playerCount", 0),
85
- "id": juego.get("universeId"),
 
 
 
 
86
  }
87
  except Exception as e:
88
  return {"error": str(e)}
@@ -128,10 +151,29 @@ def formatear_juego(datos):
128
  return "No encontré ese juego en Roblox. Intenta con otro nombre."
129
  if "error" in datos:
130
  return f"Hubo un error al buscar el juego: {datos['error']}"
131
- return (
132
- f"🕹️ **Juego encontrado en Roblox:**\n\n"
133
- f"🎮 **Nombre:** {datos['nombre']}\n"
134
- f"👤 **Creador:** {datos['creador']}\n"
135
- f"👥 **Jugando ahora:** {datos['jugando']:,}\n"
136
- f"🆔 **Universe ID:** {datos['id']}"
137
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  juegos = datos.get("games", [])
78
  if not juegos:
79
  return None
80
+ universe_id = juegos[0].get("universeId")
81
+ if not universe_id:
82
+ return None
83
+ detalle = obtener_detalle_juego(universe_id)
84
+ return detalle
85
+ except Exception as e:
86
+ return {"error": str(e)}
87
+
88
+ def obtener_detalle_juego(universe_id):
89
+ try:
90
+ url = f"https://games.roblox.com/v1/games?universeIds={universe_id}"
91
+ resp = requests.get(url, headers=HEADERS, timeout=8)
92
+ datos = resp.json()
93
+ juegos = datos.get("data", [])
94
+ if not juegos:
95
+ return None
96
+ j = juegos[0]
97
+ actualizado = j.get("updated", "Desconocido")
98
+ if actualizado and actualizado != "Desconocido":
99
+ actualizado = actualizado[:10]
100
  return {
101
+ "nombre": j.get("name"),
102
+ "tema": j.get("genre", "Sin categoría"),
103
+ "visitas": j.get("visits", 0),
104
+ "ultima_update": actualizado,
105
+ "descripcion": j.get("description") or "Sin descripción.",
106
+ "creador": j.get("creator", {}).get("name", "Desconocido"),
107
+ "jugando": j.get("playing", 0),
108
+ "id": universe_id,
109
  }
110
  except Exception as e:
111
  return {"error": str(e)}
 
151
  return "No encontré ese juego en Roblox. Intenta con otro nombre."
152
  if "error" in datos:
153
  return f"Hubo un error al buscar el juego: {datos['error']}"
154
+
155
+ visitas = datos.get("visitas", 0)
156
+ try:
157
+ visitas = f"{int(visitas):,}"
158
+ except Exception:
159
+ visitas = str(visitas)
160
+
161
+ jugando = datos.get("jugando", 0)
162
+ try:
163
+ jugando = f"{int(jugando):,}"
164
+ except Exception:
165
+ jugando = str(jugando)
166
+
167
+ lineas = [
168
+ "Datos del juego de Roblox 😎",
169
+ "",
170
+ f"🎮 **Nombre:** {datos.get('nombre', 'Desconocido')}",
171
+ f"🎭 **Tema:** {datos.get('tema', 'Sin categoría')}",
172
+ f"👁️ **Vistas:** {visitas}",
173
+ f"🔄 **Última update:** {datos.get('ultima_update', 'Desconocido')}",
174
+ f"📝 **Descripción del juego:** {datos.get('descripcion', 'Sin descripción.')}",
175
+ "",
176
+ f"👤 **Creador:** {datos.get('creador', 'Desconocido')}",
177
+ f"👥 **Jugando ahora:** {jugando}",
178
+ ]
179
+ return "\n".join(lineas)