Пример #1
0
async def test_validate_filter_invalid_value():
    command = Command(name="test", context=MockMessage(channel=MockChannel()))
    assert not await validate_filter(command=command, _filter="type:undefined", filter_context=filter_context)
    assert "✗" in command.response
    assert "invalid value" in command.response.lower()

    embed = filter_embed(key="type", filter_context=filter_context)
    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
    assert command.response_embed.fields[2].name == embed.fields[2].name
    assert command.response_embed.fields[2].value == embed.fields[2].value
Пример #2
0
async def test_validate_filter_invalid_value():
    ctx = MockContext()
    assert not await validate_filter(
        ctx, _filter="type:undefined", filter_context=filter_context)
    assert "✗" in ctx.text
    assert "invalid value" in ctx.text.lower()

    embed = filter_embed(key="type", filter_context=filter_context)
    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
    assert ctx.embed.fields[2].name == embed.fields[2].name
    assert ctx.embed.fields[2].value == embed.fields[2].value
Пример #3
0
async def test_enable_invalid_value():
    mock_command = MockCommand(
        "enable",
        "enable",
        "user:name",
        context=MockMessage(channel=MockChannel(guild=MockGuild(_id=3))))

    assert await receive_command(mock_command)
    assert "✗" in mock_command.response
    assert "invalid value" in mock_command.response.lower()
    expected_embed = filter_embed(key="user", 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"))
Пример #4
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)
    )
Пример #5
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)