Exemplo n.º 1
0
async def test_validate_filter_invalid_word():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="user:sometwo annd type:qualify", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid word" in command.response.lower()

    embed = filters_embed(filter_context=filter_context)
    assert command.response_embed.title == embed.title
    assert command.response_embed.description == embed.description
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
Exemplo n.º 2
0
async def test_validate_filter_invalid_key():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="undefined:undefined", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid key" in command.response.lower()

    embed = filters_embed(filter_context=filter_context)
    assert command.response_embed.title == embed.title
    assert command.response_embed.description == embed.description
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
Exemplo n.º 3
0
async def test_validate_filter_missing_gate():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="user:sometwo type:qualify", filter_context=filter_context)
    assert "✗" in command.response
    assert "missing gate" in command.response.lower()
    assert "between `user:sometwo` and `type:qualify`" in command.response.lower()

    embed = filters_embed(filter_context=filter_context)
    assert command.response_embed.title == embed.title
    assert command.response_embed.description == embed.description
    assert command.response_embed.fields[0].name == embed.fields[0].name
    assert command.response_embed.fields[0].value == embed.fields[0].value
    assert command.response_embed.fields[1].name == embed.fields[1].name
    assert command.response_embed.fields[1].value == embed.fields[1].value
Exemplo n.º 4
0
async def test_validate_filter_invalid_key():
    ctx = MockContext()
    assert not await validate_filter(
        ctx, _filter="undefined:undefined", filter_context=filter_context)
    assert "✗" in ctx.text
    assert "invalid key" in ctx.text.lower()

    embed = filters_embed(filter_context=filter_context)
    assert ctx.embed.title == embed.title
    assert ctx.embed.description == embed.description
    assert ctx.embed.fields[0].name == embed.fields[0].name
    assert ctx.embed.fields[0].value == embed.fields[0].value
    assert ctx.embed.fields[1].name == embed.fields[1].name
    assert ctx.embed.fields[1].value == embed.fields[1].value
Exemplo n.º 5
0
async def test_validate_filter_invalid_word():
    ctx = MockContext()
    assert not await validate_filter(ctx,
                                     _filter="user:sometwo annd type:qualify",
                                     filter_context=filter_context)
    assert "✗" in ctx.text
    assert "invalid word" in ctx.text.lower()

    embed = filters_embed(filter_context=filter_context)
    assert ctx.embed.title == embed.title
    assert ctx.embed.description == embed.description
    assert ctx.embed.fields[0].name == embed.fields[0].name
    assert ctx.embed.fields[0].value == embed.fields[0].value
    assert ctx.embed.fields[1].name == embed.fields[1].name
    assert ctx.embed.fields[1].value == embed.fields[1].value
Exemplo n.º 6
0
async def test_validate_filter_missing_gate():
    ctx = MockContext()
    assert not await validate_filter(ctx,
                                     _filter="user:sometwo type:qualify",
                                     filter_context=filter_context)
    assert "✗" in ctx.text
    assert "missing gate" in ctx.text.lower()
    assert "between `user:sometwo` and `type:qualify`" in ctx.text.lower()

    embed = filters_embed(filter_context=filter_context)
    assert ctx.embed.title == embed.title
    assert ctx.embed.description == embed.description
    assert ctx.embed.fields[0].name == embed.fields[0].name
    assert ctx.embed.fields[0].value == embed.fields[0].value
    assert ctx.embed.fields[1].name == embed.fields[1].name
    assert ctx.embed.fields[1].value == embed.fields[1].value
Exemplo n.º 7
0
async def test_enable_invalid_key():
    mock_command = MockCommand(
        "enable",
        "enable",
        "undefined:value",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=3))))

    assert await receive_command(mock_command)
    assert "✗" in mock_command.response
    assert "invalid key" in mock_command.response.lower()
    expected_embed = filters_embed(filter_context=filter_context)
    assert mock_command.response_embed.fields[0].name == expected_embed.fields[
        0].name
    assert mock_command.response_embed.fields[
        0].value == expected_embed.fields[0].value
    assert not get_permission_filter(guild_id=3,
                                     command_wrapper=get_wrapper("enable"))
Exemplo n.º 8
0
async def cmd_filters(command: Command, key: str=None):
    if key:
        key = key.lower().strip()
        tag = filter_context.get_tag(key)
        keys = tag.names if tag else None

        if not tag or not keys:
            await command.respond_err(f"No filter key `{key}` exists.")
            return

        await command.respond(
            response = f"Type `{command.prefix()}filters` for a list of keys and gates.",
            embed    = filter_embed(key, filter_context)
        )
        return

    await command.respond(
        response = f"Type `{command.prefix()}filters <key>` for usage.",
        embed    = filters_embed(filter_context)
    )
Exemplo n.º 9
0
    async def filters(self, ctx, key: Option(
        str,
        "Explains how this specific filter key works (e.g. `creator`).",
        required=False,
        default=None)):
        """Explains how filters work with examples."""
        if key:
            key = key.lower().strip()
            tag = filter_context.get_tag(key)
            keys = tag.names if tag else None

            if not tag or not keys:
                await ctx.respond(f"✗ No filter key `{key}` exists.",
                                  ephemeral=True)
                return

            await ctx.respond("Type `/filters` for a list of keys and gates.",
                              embed=filter_embed(key, filter_context),
                              ephemeral=True)
            return

        await ctx.respond("Type `/filters <key>` for usage.",
                          embed=filters_embed(filter_context),
                          ephemeral=True)