Example #1
0
async def test(client, authored_by_bot, bot):
    event = EventType.MESSAGE
    context = Context(
        client,
        event,
        message=make_discord_object(0, author=make_discord_object(1, bot=bot)),
    )

    bf = BotFilter(authored_by_bot=authored_by_bot)

    if not authored_by_bot ^ bot:
        assert isr(await bf.run(ctx=context, next=empty_next_callable))
    else:
        assert not isr(await bf.run(ctx=context, next=empty_next_callable))
Example #2
0
async def test_ignoring(client):
    event = EventType.MESSAGE
    channel = Mock(spec=discord.DMChannel)
    context = Context(client,
                      event,
                      message=make_discord_object(0, channel=channel))

    ctf = ChannelTypeFilter(guild=True)
    assert not isr(await ctf.run(ctx=context, next=empty_next_callable))
Example #3
0
async def test_ignoring(client):
    event = EventType.MESSAGE
    pattern = r"some text"
    content = "A message without text to match"
    context = Context(client,
                      event,
                      message=make_discord_object(0, content=content))

    pf = PatternFilter(pattern)
    assert not isr(await pf.run(ctx=context, next=empty_next_callable))
Example #4
0
async def test_pattern_with_named_groups_ignores_unnamed(client):
    event = EventType.MESSAGE
    pattern = r"find (\w+) and (?P<first>\w+)"
    content = "It should find 42 and firework but match only firework as first"
    context = Context(client,
                      event,
                      message=make_discord_object(0, content=content))

    @m(PatternFilter(pattern))
    async def mw(*args, ctx, next, first, **kwargs):
        assert first == "firework"

    assert isr(await mw.run(ctx=context, next=empty_next_callable))
Example #5
0
async def test_pattern_with_named_groups(client):
    event = EventType.MESSAGE
    pattern = r"find (?P<first>\w+) and (?P<second>\w+)"
    content = "It should find 42 and firework as first and second parameters"
    context = Context(client,
                      event,
                      message=make_discord_object(0, content=content))

    @m(PatternFilter(pattern))
    async def mw(*args, ctx, next, first, second, **kwargs):
        assert first == "42"
        assert second == "firework"

    assert isr(await mw.run(ctx=context, next=empty_next_callable))
async def test_passing(client):
    event = EventType.MESSAGE
    context = Context(client, event)

    etf = EventTypeFilter(event)
    assert isr(await etf.run(ctx=context, next=empty_next_callable))
async def test_ignoring(client):
    event = EventType.READY
    context = Context(client, event)

    etf = EventTypeFilter(EventType.MESSAGE)
    assert not isr(await etf.run(ctx=context, next=empty_next_callable))