diff --git a/inconnu/vr/parse.py b/inconnu/vr/parse.py index 290522e..e88f04c 100644 --- a/inconnu/vr/parse.py +++ b/inconnu/vr/parse.py @@ -168,7 +168,10 @@ async def perform_roll(character: "VChar", syntax, max_hunger=5): def needs_character(syntax: str): """Determines whether a roll needs a character.""" - return re.search(r"[A-z_" + VCharTrait.DELIMITER + "]", syntax) is not None + if not syntax: + return False + + return any(c.isalpha() or c in {"_", VCharTrait.DELIMITER} for c in syntax) async def stringify_mentions(ctx, sentence): diff --git a/tests/test_rollparser.py b/tests/test_rollparser.py index 65a033e..cec4bae 100644 --- a/tests/test_rollparser.py +++ b/tests/test_rollparser.py @@ -4,6 +4,7 @@ import inconnu.errors from inconnu.models.vchar import VChar +from inconnu.vr.parse import needs_character from inconnu.vr.rollparser import RollParser from tests.characters import gen_char @@ -137,3 +138,21 @@ def test_no_power_bonus( p = RollParser(character, syntax, power_bonus=add_bonus) assert p.pool_str == expected_str assert p.pool == expected_dice + + +@pytest.mark.parametrize( + "syntax,needs", + [ + ("3", False), + ("3 + 2", False), + ("3 4 5", False), + ("Strength", True), + ("3 + Strength", True), + ("Strength + Brawl hunger 3", True), + ("ΓΌ", True), + ("3 + .", True), + ("3 + _", True), + ], +) +def test_needs_character(syntax: str, needs: bool): + assert needs_character(syntax) == needs