Пример #1
0
async def test_disable_dm_channel():
    mock_command = MockCommand("disable", "disable", context=MockMessage(channel=MockDMChannel()))
    
    assert await receive_command(mock_command)
    assert "✗" in mock_command.response
    assert "dm channel" in mock_command.response.lower()
    assert mock_command.response_embed.fields[0].name == help_embed("disable").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed("disable").fields[0].value
Пример #2
0
async def test_help_with_arg():
    mock_command = MockCommand("help",
                               "name",
                               context=MockMessage(channel=MockChannel()))

    assert await receive_command(mock_command)
    assert f"`{DEFAULT_PREFIX}help`" in mock_command.response  # Should suggest using this for a list of commands.
    assert mock_command.response_embed.fields[0].name == help_embed(
        "name").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "name").fields[0].value
Пример #3
0
async def test_filters_unrecognized_command():
    mock_command = MockCommand("filters",
                               "undefined",
                               context=MockMessage(channel=MockChannel()))

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "`undefined`" in mock_command.response
    assert mock_command.response_embed.fields[0].name == help_embed(
        "filters").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "filters").fields[0].value
Пример #4
0
async def test_unsub_no_sub():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("unsub", context=mock_message)

    assert not subscriber.cache

    assert await receive_command(mock_command)
    assert mock_command.response.startswith("✗")
    assert "nothing to unsub" in mock_command.response.lower()
    assert mock_command.response_embed.fields[0].name == help_embed(
        "unsub").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "unsub").fields[0].value
Пример #5
0
async def test_recent_not_found():
    mock_message = MockMessage(
        channel=MockChannel(_id=6, guild=MockGuild(_id=2)))
    mock_command = MockCommand("recent",
                               "type:(nominate or qualify)",
                               context=mock_message)

    assert await receive_command(mock_command)

    assert mock_command.response == "✗ No event matching `type:(nominate or qualify)` could be found."
    assert mock_command.response_embed.fields[0].name == help_embed(
        "recent").fields[0].name
    assert mock_command.response_embed.fields[0].value == help_embed(
        "recent").fields[0].value
Пример #6
0
def test_command_help_embed():
    register(
        category="Some Category",
        names=["test"],
        required_args=["one", "two"],
        optional_args=["three"],
        description=
        "A command that uses `<one>`, `<two>`, and `[three]` to do stuff.",
        example_args=["one two", "1 2 3", "\"o n e\" two three"])(None)

    embed1 = Command("test").help_embed()
    embed2 = help_embed("test")

    assert embed1.fields[0].name == embed2.fields[0].name
    assert embed1.fields[0].value == embed2.fields[0].value
Пример #7
0
async def cmd_help(command: Command, name: str = None):
    if name:
        # Clean up the argument so that `+help +ping` works, as the user would expect.
        name = name.replace("+", "")

        embed = help_embed(name, prefix=command.prefix())
        content = f"Type `{command.prefix()}help` for a list of commands."
    else:
        embed = general_help_embed(prefix=command.prefix())
        content = f"Type `{command.prefix()}help <command>` for usage."

    if not embed:
        await command.respond_err(f"No command `{name}` exists.")
        return

    await command.respond(content, embed=embed)
Пример #8
0
def test_help_embed_custom_prefix():
    register(
        category="Some Category",
        names=["test"],
        required_args=["one", "two"],
        optional_args=["three"],
        description=
        "A command that uses `<one>`, `<two>`, and `[three]` to do stuff.",
        example_args=["one two", "1 2 3", "\"o n e\" two three"])(None)
    embed = help_embed("test", prefix="&")

    assert embed.fields[0].name == "**`&test <one> <two> [three]`**"
    assert "A command that uses `<one>`, `<two>`, and `[three]` to do stuff." in embed.fields[
        0].value
    for example_args in ["one two", "1 2 3", "\"o n e\" two three"]:
        assert f"`&test {example_args}`" in embed.fields[1].value
Пример #9
0
async def test_command_respond_err():
    register(
        category="Some Category",
        names=["test"],
        required_args=["one", "two"],
        optional_args=["three"],
        description=
        "A command that uses `<one>`, `<two>`, and `[three]` to do stuff.",
        example_args=["one two", "1 2 3", "\"o n e\" two three"])(None)
    embed = help_embed("test")

    mock_channel = MockChannel()
    mock_message = MockMessage("+test 1 2 3", channel=mock_channel)
    command = Command("test", "1", "2", "3", context=mock_message)

    assert await command.respond_err("error")
    assert command.response == "✗ error"
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
Пример #10
0
def test_help_embed_unrecognized_arg():
    assert not help_embed("unrecognized")