Source code for tools.exit_game

"""GameGirl Color -- Exit game tool.

# 💀 CARTRIDGE EJECTION PROTOCOL
"""

from __future__ import annotations

import json
import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tool_context import ToolContext

logger = logging.getLogger(__name__)

TOOL_NAME = "exit_game"
TOOL_DESCRIPTION = (
    "Exit and save the current GameGirl Color session in this channel. "
    "The game state is persisted to Redis for potential reload."
)
TOOL_PARAMETERS = {
    "type": "object",
    "properties": {},
    "required": [],
}


[docs] async def run( ctx: ToolContext | None = None, ) -> str: """Exit the active game session. Returns: str: JSON result with exit status. """ if ctx is None: return json.dumps({"error": "No tool context available."}) from game_session import get_session, remove_session channel_id = str(ctx.channel_id) session = get_session(channel_id) if session is None or not session.active: return json.dumps({ "error": "No active game session in this channel.", }) redis = getattr(ctx, "redis", None) exit_msg = await session.exit_game(redis=redis) remove_session(channel_id) return json.dumps({ "success": True, "game_id": session.game_id, "game_name": session.game_name, "turns_played": session.turn_number, "exit_message": exit_msg, })