Source code for tools.resume_music

"""Resume a paused Lyria music stream in a Discord voice channel."""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tool_context import ToolContext

logger = logging.getLogger(__name__)

TOOL_NAME = "resume_music"
TOOL_DESCRIPTION = (
    "Resume a paused Lyria music stream in a Discord voice channel. "
    "Requires an active (paused) music session."
)
TOOL_PARAMETERS = {
    "type": "object",
    "properties": {
        "guild_id": {"type": "string", "description": "Discord server (guild) ID."},
    },
    "required": ["guild_id"],
}


[docs] async def run( guild_id: str, ctx: "ToolContext | None" = None, ) -> str: """Resume a previously paused Lyria music stream in a Discord guild. Module-level entry point for the ``resume_music`` tool. Unpauses the Lyria generative-music session for the given guild so audio playback continues where ``pause_music`` left off, without tearing down or re-establishing the voice connection. Validates that a Discord adapter is present on the context, obtains the live discord.py client via ``get_discord_client`` (bailing out with that helper's error string if the gateway is unreachable), then delegates to ``ctx.adapter.lyria_service.resume`` with the parsed integer guild id. The actual side effect -- resuming the audio stream in the voice channel -- happens inside the Lyria service. Called by the tool registry's ``execute_tool`` dispatch: ``tool_loader.py`` discovers this module by its ``TOOL_NAME``/``TOOL_DESCRIPTION``/``run`` contract and registers ``run`` as the tool handler, so there are no direct in-repo callers. Args: guild_id: Discord server (guild) ID as a string; it is converted to an integer before being passed to the Lyria service. ctx: The :class:`~tool_context.ToolContext` for the invocation, injected by the registry. Must carry a non-``None`` ``adapter``; otherwise an error string is returned. Returns: str: The Lyria service's human-readable result message on success, or an error string when the adapter, Discord client, or ``guild_id`` is invalid. """ if ctx is None or not hasattr(ctx, "adapter") or ctx.adapter is None: return "Error: Discord adapter (ctx.adapter) is required." from tools._discord_helpers import get_discord_client client = get_discord_client(ctx) if isinstance(client, str): return client lyria = ctx.adapter.lyria_service try: guild_id_int = int(guild_id) except (ValueError, TypeError): return "Error: Invalid guild_id." return await lyria.resume(guild_id_int)