Spaces:
Sleeping
Sleeping
change
Browse files- Dockerfile +2 -0
- app.py +19 -0
- utils/pokemon_utils.py +16 -7
Dockerfile
CHANGED
|
@@ -9,6 +9,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 9 |
|
| 10 |
COPY . .
|
| 11 |
|
|
|
|
|
|
|
| 12 |
|
| 13 |
EXPOSE 7860
|
| 14 |
|
|
|
|
| 9 |
|
| 10 |
COPY . .
|
| 11 |
|
| 12 |
+
# Create directory for battle replays with proper permissions
|
| 13 |
+
RUN mkdir -p battle_replays && chmod 755 battle_replays
|
| 14 |
|
| 15 |
EXPOSE 7860
|
| 16 |
|
app.py
CHANGED
|
@@ -505,6 +505,25 @@ def cleanup_battles() -> dict:
|
|
| 505 |
"message": f"Failed to cleanup battles: {str(e)}"
|
| 506 |
}
|
| 507 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
|
| 509 |
# --- Server Execution ---
|
| 510 |
if __name__ == "__main__":
|
|
|
|
| 505 |
"message": f"Failed to cleanup battles: {str(e)}"
|
| 506 |
}
|
| 507 |
|
| 508 |
+
@mcp.tool()
|
| 509 |
+
async def wait_30_seconds() -> dict:
|
| 510 |
+
"""
|
| 511 |
+
Wait for 30 seconds. Useful for giving processes time to complete or timing operations.
|
| 512 |
+
Returns:
|
| 513 |
+
dict: Status of the wait operation
|
| 514 |
+
"""
|
| 515 |
+
try:
|
| 516 |
+
await asyncio.sleep(30)
|
| 517 |
+
return {
|
| 518 |
+
"status": "success",
|
| 519 |
+
"message": "Waited 30 seconds successfully"
|
| 520 |
+
}
|
| 521 |
+
except Exception as e:
|
| 522 |
+
return {
|
| 523 |
+
"status": "error",
|
| 524 |
+
"message": f"Failed to wait: {str(e)}"
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
|
| 528 |
# --- Server Execution ---
|
| 529 |
if __name__ == "__main__":
|
utils/pokemon_utils.py
CHANGED
|
@@ -537,9 +537,15 @@ async def download_battle_replay(battle_id: str) -> str:
|
|
| 537 |
if not battle:
|
| 538 |
raise ValueError(f"Battle object for {battle_id} not found")
|
| 539 |
|
| 540 |
-
#
|
| 541 |
-
|
| 542 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
# Look for replay file
|
| 545 |
potential_files = [
|
|
@@ -555,10 +561,13 @@ async def download_battle_replay(battle_id: str) -> str:
|
|
| 555 |
|
| 556 |
# If no replay file found, return the battle's replay data if available
|
| 557 |
if hasattr(battle, 'replay') and battle.replay:
|
| 558 |
-
replay_path = f"{
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
|
|
|
|
|
|
|
|
|
| 562 |
|
| 563 |
raise ValueError(f"No replay found for battle {battle_id}")
|
| 564 |
|
|
|
|
| 537 |
if not battle:
|
| 538 |
raise ValueError(f"Battle object for {battle_id} not found")
|
| 539 |
|
| 540 |
+
# Create replay directory with proper permissions
|
| 541 |
+
# Use /tmp for temporary files or create in current directory with explicit permissions
|
| 542 |
+
replay_dir = os.path.join(os.getcwd(), "battle_replays")
|
| 543 |
+
try:
|
| 544 |
+
os.makedirs(replay_dir, mode=0o755, exist_ok=True)
|
| 545 |
+
except PermissionError:
|
| 546 |
+
# Fallback to /tmp if we can't write to current directory
|
| 547 |
+
replay_dir = "/tmp/battle_replays"
|
| 548 |
+
os.makedirs(replay_dir, mode=0o755, exist_ok=True)
|
| 549 |
|
| 550 |
# Look for replay file
|
| 551 |
potential_files = [
|
|
|
|
| 561 |
|
| 562 |
# If no replay file found, return the battle's replay data if available
|
| 563 |
if hasattr(battle, 'replay') and battle.replay:
|
| 564 |
+
replay_path = os.path.join(replay_dir, f"{battle_id}_replay.txt")
|
| 565 |
+
try:
|
| 566 |
+
with open(replay_path, 'w') as f:
|
| 567 |
+
f.write(str(battle.replay))
|
| 568 |
+
return replay_path
|
| 569 |
+
except PermissionError:
|
| 570 |
+
raise ValueError(f"Permission denied when writing replay file to {replay_path}. Check directory permissions.")
|
| 571 |
|
| 572 |
raise ValueError(f"No replay found for battle {battle_id}")
|
| 573 |
|