"""Shared helpers for wiring tests (command invocation, sent-text asserts).""" from __future__ import annotations import asyncio from collections.abc import Callable from typing import Any, cast from unittest.mock import MagicMock from discord.ext import commands def invoke(bot: commands.Bot, name: str, *args: Any, **kwargs: Any) -> None: """Invoke a registered command's callback directly with the given args.""" cmd = bot.get_command(name) assert cmd is not None callback = cast("Callable[..., Any]", cmd.callback) asyncio.run(callback(*args, **kwargs)) def sent_texts(ctx: MagicMock) -> list[str]: """All positional text messages sent through ctx.send.""" return [c.args[0] for c in ctx.send.call_args_list if c.args]