def test_passes_filter_and_not(): assert filter_context.test("type:reply and not mode:taiko", ["mode:catch", "type:reply"]) assert not filter_context.test("type:reply and not mode:taiko", ["mode:taiko", "type:reply"]) assert not filter_context.test("type:reply and not mode:taiko", ["mode:osu", "type:qualify"])
def test_passes_filter_or(): assert filter_context.test("type:reply or mode:taiko", ["mode:osu", "type:reply"]) assert filter_context.test("type:reply or mode:taiko", ["mode:taiko", "type:qualify"]) assert not filter_context.test("type:reply or mode:taiko", ["mode:osu", "type:qualify"])
def test_passes_filter_conversion(): assert filter_context.test("tags:guild", ["tags:abcguild123"]) assert filter_context.test("tags:(mappers' and guild)", ["tags:abcmappers'123", "tags:abcguild123"]) assert filter_context.test("tags:\"mappers' guild\"", ["tags:abcmappers'123", "tags:abcguild123"]) assert filter_context.test("tag:\"mappers' guild\"", ["tag:abcmappers'123", "tag:abcguild123"])
def test_passes_filter_event_object(): beatmapset = Beatmapset(3, allow_api=False) event = Event(_type="nominate", time=datetime.utcnow(), beatmapset=beatmapset, user=User(2, "sometwo")) assert filter_context.test("type:nominate and user:sometwo", event) assert not filter_context.test("type:reply", event)
def test_passes_filter_percent_wildcard(): assert filter_context.test("content:%something%", ["content:someone or something"]) assert filter_context.test("content:%something", ["content:someone or something"]) assert filter_context.test("%", ["content:someone or something"]) assert not filter_context.test("content:something%", ["content:someone or something"]) assert not filter_context.test("content:%something else%", ["content:someone or something"])
def test_passes_filter_partial(): assert not filter_context.test("type:reply", ["special-type:reply"]) assert not filter_context.test("type:reply", ["type:reply-special"])
def test_passes_filter_underscore_wildcard(): assert filter_context.test("content:so_ething", ["content:something"]) assert filter_context.test("content:someth___", ["content:something"]) assert not filter_context.test("content:something_", ["content:something"]) assert not filter_context.test("content:some_thing", ["content:something"])
def test_passes_filter_case_sensitivity(): assert filter_context.test("type:Reply AND mode:OSU", ["mode:osu", "type:reply"]) assert not filter_context.test("TYPE:QUALIFY", ["mode:osu", "type:reply"])
def test_passes_filter_missing_field(): assert not filter_context.test("content:hi", ["user:sometwo", "type:nominate"]) assert filter_context.test("not content:hi", ["user:sometwo", "type:nominate"])
async def forward_sub(event: Event, sub: Subscription, bot: discord.Bot, pre_generated_embed: discord.Embed) -> None: """Attempts to forward an event through the filter of the given subscription.""" if filter_context.test(sub.filter, event): await send_event(event, sub, bot, pre_generated_embed)
async def forward(event: Event, client: discord.Client) -> None: """Attempts to forward an event through all subscription filters.""" for sub in cache: if filter_context.test(sub.filter, event): await client.send_event(event, sub)
def test_passes_filter_event_object(): beatmapset = Beatmapset(3, "artist", "title", creator=User(1, "someone"), modes=["osu"], genre="g", language="l") event = Event(_type="nominate", time=datetime.utcnow(), beatmapset=beatmapset, user=User(2, "sometwo")) assert filter_context.test("type:nominate and user:sometwo", event) assert not filter_context.test("type:reply", event)