Skip to content

tux.cogs.admin.mock

Classes:

Name Description
Mock

Classes

Mock(bot: Tux)

Bases: Cog

Methods:

Name Description
mock

Base command group for mocking various bot behaviors.

mock_error

Raises a specified error to test the global error handler.

Source code in tux/cogs/admin/mock.py
Python
def __init__(self, bot: Tux) -> None:
    self.bot = bot

Functions

mock(ctx: commands.Context[Tux]) -> None async

Base command group for mocking various bot behaviors. Requires System Administrator permissions (Level 8).

Source code in tux/cogs/admin/mock.py
Python
@commands.hybrid_group(name="mock", description="Commands to mock bot behaviors for testing.")
@checks.has_pl(level=8)
async def mock(self, ctx: commands.Context[Tux]) -> None:
    """
    Base command group for mocking various bot behaviors.
    Requires System Administrator permissions (Level 8).
    """
    # Send help if no subcommand is invoked
    if ctx.invoked_subcommand is None:
        await ctx.send_help(ctx.command)
mock_error(ctx: commands.Context[Tux], *, error_type: str) async

Raises a specified error to test the global error handler.

Parameters:

Name Type Description Default
ctx Context[Tux]

The command invocation context.

required
error_type str

The name of the error to raise (use autocomplete).

required
Notes

This command intentionally raises various exceptions based on the input. These exceptions will propagate up to the global ErrorHandler cog. Requires System Administrator permissions (Level 8).

Source code in tux/cogs/admin/mock.py
Python
@mock.command(name="error", description="Raise a specified error for testing error handling.")
@app_commands.autocomplete(error_type=error_type_autocomplete)
@checks.has_pl(level=8)  # Apply check to subcommand as well
async def mock_error(self, ctx: commands.Context[Tux], *, error_type: str):
    """
    Raises a specified error to test the global error handler.

    Parameters
    ----------
    ctx : commands.Context[Tux]
        The command invocation context.
    error_type : str
        The name of the error to raise (use autocomplete).

    Notes
    -----
    This command intentionally raises various exceptions based on the input.
    These exceptions will propagate up to the global ErrorHandler cog.
    Requires System Administrator permissions (Level 8).
    """

    error_info = ERRORS_TO_TEST.get(error_type)
    if not error_info:
        valid_keys = ", ".join(f"`{k}`" for k in ERRORS_TO_TEST)
        # Check if interaction or context to send ephemeral message
        if isinstance(ctx.interaction, discord.Interaction):
            await ctx.interaction.response.send_message(
                f"Error type '{error_type}' not found. Valid types are: {valid_keys}",
                ephemeral=True,
            )
        else:
            await ctx.send(
                f"Error type '{error_type}' not found. Valid types are: {valid_keys}",
            )  # Cannot be ephemeral here
        return

    error_class, error_args, error_kwargs = error_info

    # Log intention and raise the error
    logger.info(f"Admin '{ctx.author}' requested raising mocked error: {error_type}")

    raise error_class(*error_args, **error_kwargs)  # type: ignore