bentosmau commited on
Commit ·
18dae39
1
Parent(s): 4426eaf
Add player statistics and refine profile display for Roblox users
Browse filesUpdate roblox_api.py to fetch and display player statistics (friends, followers, following) and adjust the user profile display format for better readability.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e3ff2484-bbd8-4aba-bea0-1940769b874a
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 5659d8f9-40bd-4d4c-961c-03ec357f67e1
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
- chat-app/roblox_api.py +53 -14
chat-app/roblox_api.py
CHANGED
|
@@ -17,14 +17,18 @@ def buscar_jugador(nombre):
|
|
| 17 |
user_id = usuario["id"]
|
| 18 |
perfil = obtener_perfil(user_id)
|
| 19 |
avatar_url = obtener_avatar(user_id)
|
|
|
|
| 20 |
return {
|
| 21 |
"id": user_id,
|
| 22 |
"nombre": usuario.get("name"),
|
| 23 |
"nombre_display": usuario.get("displayName"),
|
| 24 |
-
"descripcion": perfil.get("description", "
|
| 25 |
"creado": perfil.get("created", "Desconocido"),
|
| 26 |
"is_banned": perfil.get("isBanned", False),
|
| 27 |
"avatar": avatar_url,
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
except Exception as e:
|
| 30 |
return {"error": str(e)}
|
|
@@ -46,6 +50,25 @@ def obtener_avatar(user_id):
|
|
| 46 |
except Exception:
|
| 47 |
return None
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def buscar_juego(nombre):
|
| 50 |
try:
|
| 51 |
url = f"https://games.roblox.com/v1/games/list?keyword={nombre}&maxRows=5&startRows=0"
|
|
@@ -59,7 +82,6 @@ def buscar_juego(nombre):
|
|
| 59 |
"nombre": juego.get("name"),
|
| 60 |
"creador": juego.get("creatorName"),
|
| 61 |
"jugando": juego.get("playerCount", 0),
|
| 62 |
-
"visitas": juego.get("totalUpVotes", 0),
|
| 63 |
"id": juego.get("universeId"),
|
| 64 |
}
|
| 65 |
except Exception as e:
|
|
@@ -70,19 +92,36 @@ def formatear_jugador(datos):
|
|
| 70 |
return "No encontré ese jugador en Roblox. Verifica que el nombre de usuario sea correcto."
|
| 71 |
if "error" in datos:
|
| 72 |
return f"Hubo un error al buscar el jugador: {datos['error']}"
|
| 73 |
-
|
| 74 |
descripcion = datos.get("descripcion") or "Sin descripción."
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
def formatear_juego(datos):
|
| 88 |
if not datos:
|
|
|
|
| 17 |
user_id = usuario["id"]
|
| 18 |
perfil = obtener_perfil(user_id)
|
| 19 |
avatar_url = obtener_avatar(user_id)
|
| 20 |
+
estadisticas = obtener_estadisticas(user_id)
|
| 21 |
return {
|
| 22 |
"id": user_id,
|
| 23 |
"nombre": usuario.get("name"),
|
| 24 |
"nombre_display": usuario.get("displayName"),
|
| 25 |
+
"descripcion": perfil.get("description", ""),
|
| 26 |
"creado": perfil.get("created", "Desconocido"),
|
| 27 |
"is_banned": perfil.get("isBanned", False),
|
| 28 |
"avatar": avatar_url,
|
| 29 |
+
"amigos": estadisticas.get("amigos", "N/A"),
|
| 30 |
+
"seguidores": estadisticas.get("seguidores", "N/A"),
|
| 31 |
+
"siguiendo": estadisticas.get("siguiendo", "N/A"),
|
| 32 |
}
|
| 33 |
except Exception as e:
|
| 34 |
return {"error": str(e)}
|
|
|
|
| 50 |
except Exception:
|
| 51 |
return None
|
| 52 |
|
| 53 |
+
def obtener_estadisticas(user_id):
|
| 54 |
+
resultado = {}
|
| 55 |
+
try:
|
| 56 |
+
r = requests.get(f"https://friends.roblox.com/v1/users/{user_id}/friends/count", headers=HEADERS, timeout=8)
|
| 57 |
+
resultado["amigos"] = r.json().get("count", "N/A")
|
| 58 |
+
except Exception:
|
| 59 |
+
resultado["amigos"] = "N/A"
|
| 60 |
+
try:
|
| 61 |
+
r = requests.get(f"https://friends.roblox.com/v1/users/{user_id}/followers/count", headers=HEADERS, timeout=8)
|
| 62 |
+
resultado["seguidores"] = r.json().get("count", "N/A")
|
| 63 |
+
except Exception:
|
| 64 |
+
resultado["seguidores"] = "N/A"
|
| 65 |
+
try:
|
| 66 |
+
r = requests.get(f"https://friends.roblox.com/v1/users/{user_id}/followings/count", headers=HEADERS, timeout=8)
|
| 67 |
+
resultado["siguiendo"] = r.json().get("count", "N/A")
|
| 68 |
+
except Exception:
|
| 69 |
+
resultado["siguiendo"] = "N/A"
|
| 70 |
+
return resultado
|
| 71 |
+
|
| 72 |
def buscar_juego(nombre):
|
| 73 |
try:
|
| 74 |
url = f"https://games.roblox.com/v1/games/list?keyword={nombre}&maxRows=5&startRows=0"
|
|
|
|
| 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:
|
|
|
|
| 92 |
return "No encontré ese jugador en Roblox. Verifica que el nombre de usuario sea correcto."
|
| 93 |
if "error" in datos:
|
| 94 |
return f"Hubo un error al buscar el jugador: {datos['error']}"
|
| 95 |
+
|
| 96 |
descripcion = datos.get("descripcion") or "Sin descripción."
|
| 97 |
+
fecha = datos.get("creado", "Desconocido")
|
| 98 |
+
if fecha != "Desconocido":
|
| 99 |
+
fecha = fecha[:10]
|
| 100 |
+
baneado = "Sí ⚠️" if datos.get("is_banned") else "No ✅"
|
| 101 |
+
amigos = datos.get("amigos", "N/A")
|
| 102 |
+
seguidores = datos.get("seguidores", "N/A")
|
| 103 |
+
siguiendo = datos.get("siguiendo", "N/A")
|
| 104 |
+
|
| 105 |
+
lineas = [
|
| 106 |
+
"Aquí tienes datos públicos del jugador en Roblox 😊",
|
| 107 |
+
"",
|
| 108 |
+
f"👤 **Nombre de usuario:** {datos['nombre']}",
|
| 109 |
+
f"✏️ **Su nombre completo:** {datos['nombre_display']}",
|
| 110 |
+
f"🆔 **ID:** {datos['id']}",
|
| 111 |
+
f"📝 **Historia (descripción):** {descripcion}",
|
| 112 |
+
f"📅 **Nacimiento de la cuenta de Roblox:** {fecha}",
|
| 113 |
+
f"🚫 **¿Fue baneado?:** {baneado}",
|
| 114 |
+
"",
|
| 115 |
+
"📊 **Estadísticas:**",
|
| 116 |
+
f"👫 **Sus amigos:** {amigos}",
|
| 117 |
+
f"👥 **Sus seguidores:** {seguidores}",
|
| 118 |
+
f"➡️ **A quien sigue:** {siguiendo}",
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
if datos.get("avatar"):
|
| 122 |
+
lineas.append(f"\n🖼️ **Avatar:** {datos['avatar']}")
|
| 123 |
+
|
| 124 |
+
return "\n".join(lineas)
|
| 125 |
|
| 126 |
def formatear_juego(datos):
|
| 127 |
if not datos:
|