Merge pull request #3281 from volundmush/actor_your
Adds $you() and $your() to the ACTOR_STANCE callables.
This commit is contained in:
commit
769d951b18
2 changed files with 120 additions and 49 deletions
|
|
@ -1222,10 +1222,7 @@ def funcparser_callable_you(
|
|||
"""
|
||||
if args and mapping:
|
||||
# this would mean a $you(key) form
|
||||
try:
|
||||
caller = mapping.get(args[0])
|
||||
except KeyError:
|
||||
pass
|
||||
caller = mapping.get(args[0], None)
|
||||
|
||||
if not (caller and receiver):
|
||||
raise ParsingError("No caller or receiver supplied to $you callable.")
|
||||
|
|
@ -1252,6 +1249,73 @@ def funcparser_callable_you_capitalize(
|
|||
)
|
||||
|
||||
|
||||
def funcparser_callable_your(
|
||||
*args, caller=None, receiver=None, mapping=None, capitalize=False, **kwargs
|
||||
):
|
||||
"""
|
||||
Usage: $your() or $your(key)
|
||||
|
||||
Replaces with your for the caller of the string, with the display_name +'s
|
||||
of the caller for others.
|
||||
|
||||
Keyword Args:
|
||||
caller (Object): The 'your' in the string. This is used unless another
|
||||
your-key is passed to the callable in combination with `mapping`.
|
||||
receiver (Object): The recipient of the string.
|
||||
mapping (dict, optional): This is a mapping `{key:Object, ...}` and is
|
||||
used to find which object `$you(key)` refers to. If not given, the
|
||||
`caller` kwarg is used.
|
||||
capitalize (bool): Passed by the You helper, to capitalize you.
|
||||
|
||||
Returns:
|
||||
str: The parsed string.
|
||||
|
||||
Raises:
|
||||
ParsingError: If `caller` and `receiver` were not supplied.
|
||||
|
||||
Notes:
|
||||
The kwargs should be passed the to parser directly.
|
||||
|
||||
Examples:
|
||||
This can be used by the say or emote hooks to pass actor stance
|
||||
strings.
|
||||
|
||||
- `$your() pet jumps at $you(tommy).`
|
||||
|
||||
The caller-object will see "Your pet jumps Tommy."
|
||||
Tommy will see "CharName's pet jumps at you."
|
||||
Others will see "CharName's pet jumps at Tommy."
|
||||
|
||||
"""
|
||||
if args and mapping:
|
||||
# this would mean a $your(key) form
|
||||
caller = mapping.get(args[0], None)
|
||||
|
||||
if not (caller and receiver):
|
||||
raise ParsingError("No caller or receiver supplied to $your callable.")
|
||||
|
||||
capitalize = bool(capitalize)
|
||||
if caller == receiver:
|
||||
return "Your" if capitalize else "your"
|
||||
|
||||
name = caller.get_display_name(looker=receiver) \
|
||||
if hasattr(caller, "get_display_name") else str(caller)
|
||||
|
||||
return name + "'s"
|
||||
|
||||
|
||||
def funcparser_callable_your_capitalize(
|
||||
*args, you=None, receiver=None, mapping=None, capitalize=True, **kwargs
|
||||
):
|
||||
"""
|
||||
Usage: $Your() - capitalizes the 'your' output.
|
||||
|
||||
"""
|
||||
return funcparser_callable_your(
|
||||
*args, you=you, receiver=receiver, mapping=mapping, capitalize=capitalize, **kwargs
|
||||
)
|
||||
|
||||
|
||||
def funcparser_callable_conjugate(*args, caller=None, receiver=None, **kwargs):
|
||||
"""
|
||||
Usage: $conj(word, [options])
|
||||
|
|
@ -1484,6 +1548,8 @@ ACTOR_STANCE_CALLABLES = {
|
|||
# requires `you`, `receiver` and `mapping` to be passed into parser
|
||||
"you": funcparser_callable_you,
|
||||
"You": funcparser_callable_you_capitalize,
|
||||
"your": funcparser_callable_your,
|
||||
"Your": funcparser_callable_your_capitalize,
|
||||
"obj": funcparser_callable_you,
|
||||
"Obj": funcparser_callable_you_capitalize,
|
||||
"conj": funcparser_callable_conjugate,
|
||||
|
|
|
|||
|
|
@ -154,55 +154,55 @@ class TestFuncParser(TestCase):
|
|||
(r'Test args10 $foo(",")', "Test args10 _test(,)"),
|
||||
("Test args11 $foo(()", "Test args11 $foo(()"), # invalid syntax
|
||||
(
|
||||
r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)',
|
||||
"Test kwarg1 _test(foo=1, bar=foo, too=ere)",
|
||||
r'Test kwarg1 $bar(foo=1, bar="foo", too=ere)',
|
||||
"Test kwarg1 _test(foo=1, bar=foo, too=ere)",
|
||||
),
|
||||
("Test kwarg2 $bar(foo,bar,too=ere)", "Test kwarg2 _test(foo, bar, too=ere)"),
|
||||
("test kwarg3 $foo(foo = bar, bar = ere )", "test kwarg3 _test(foo=bar, bar=ere)"),
|
||||
(
|
||||
r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )",
|
||||
"test kwarg4 _test(foo=' bar ', \" bar \"=ere)",
|
||||
r"test kwarg4 $foo(foo =' bar ',\" bar \"= ere )",
|
||||
"test kwarg4 _test(foo=' bar ', \" bar \"=ere)",
|
||||
),
|
||||
(
|
||||
"Test nest1 $foo($bar(foo,bar,too=ere))",
|
||||
"Test nest1 _test(_test(foo, bar, too=ere))",
|
||||
"Test nest1 $foo($bar(foo,bar,too=ere))",
|
||||
"Test nest1 _test(_test(foo, bar, too=ere))",
|
||||
),
|
||||
(
|
||||
"Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc",
|
||||
"Test nest2 _test(bar, rar, rr=rr, a=b) etc",
|
||||
"Test nest2 $foo(bar,$repl(a),$repl()=$repl(),a=b) etc",
|
||||
"Test nest2 _test(bar, rar, rr=rr, a=b) etc",
|
||||
),
|
||||
("Test nest3 $foo(bar,$repl($repl($repl(c))))", "Test nest3 _test(bar, rrrcrrr)"),
|
||||
(
|
||||
"Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())",
|
||||
"Test nest4 _test(_test(a, b), _test(a, rr), _test())",
|
||||
"Test nest4 $foo($bar(a,b),$bar(a,$repl()),$bar())",
|
||||
"Test nest4 _test(_test(a, b), _test(a, rr), _test())",
|
||||
),
|
||||
("Test escape1 \\$repl(foo)", "Test escape1 $repl(foo)"),
|
||||
(
|
||||
'Test escape2 "This is $foo() and $bar($bar())", $repl()',
|
||||
'Test escape2 "This is _test() and _test(_test())", rr',
|
||||
'Test escape2 "This is $foo() and $bar($bar())", $repl()',
|
||||
'Test escape2 "This is _test() and _test(_test())", rr',
|
||||
),
|
||||
(
|
||||
"Test escape3 'This is $foo() and $bar($bar())', $repl()",
|
||||
"Test escape3 'This is _test() and _test(_test())', rr",
|
||||
"Test escape3 'This is $foo() and $bar($bar())', $repl()",
|
||||
"Test escape3 'This is _test() and _test(_test())', rr",
|
||||
),
|
||||
(
|
||||
"Test escape4 $$foo() and $$bar(a,b), $repl()",
|
||||
"Test escape4 $foo() and $bar(a,b), rr",
|
||||
"Test escape4 $$foo() and $$bar(a,b), $repl()",
|
||||
"Test escape4 $foo() and $bar(a,b), rr",
|
||||
),
|
||||
("Test with color |r$foo(a,b)|n is ok", "Test with color |r_test(a, b)|n is ok"),
|
||||
("Test malformed1 This is $foo( and $bar(", "Test malformed1 This is $foo( and $bar("),
|
||||
(
|
||||
"Test malformed2 This is $foo( and $bar()",
|
||||
"Test malformed2 This is $foo( and _test()",
|
||||
"Test malformed2 This is $foo( and $bar()",
|
||||
"Test malformed2 This is $foo( and _test()",
|
||||
),
|
||||
("Test malformed3 $", "Test malformed3 $"),
|
||||
(
|
||||
"Test malformed4 This is $foo(a=b and $bar(",
|
||||
"Test malformed4 This is $foo(a=b and $bar(",
|
||||
"Test malformed4 This is $foo(a=b and $bar(",
|
||||
"Test malformed4 This is $foo(a=b and $bar(",
|
||||
),
|
||||
(
|
||||
"Test malformed5 This is $foo(a=b, and $repl()",
|
||||
"Test malformed5 This is $foo(a=b, and rr",
|
||||
"Test malformed5 This is $foo(a=b, and $repl()",
|
||||
"Test malformed5 This is $foo(a=b, and rr",
|
||||
),
|
||||
("Test nonstr 4x2 = $double(4)", "Test nonstr 4x2 = 8"),
|
||||
("Test nonstr 4x2 = $double(foo)", "Test nonstr 4x2 = N/A"),
|
||||
|
|
@ -212,8 +212,8 @@ class TestFuncParser(TestCase):
|
|||
("Test eval3 $eval(\"'21' + 'foo' + 'bar'\")", "Test eval3 21foobar"),
|
||||
(r"Test eval4 $eval('21' + '$repl()' + \"\" + str(10 // 2))", "Test eval4 21rr5"),
|
||||
(
|
||||
r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))",
|
||||
"Test eval5 21$repl()5",
|
||||
r"Test eval5 $eval(\'21\' + \'\$repl()\' + \'\' + str(10 // 2))",
|
||||
"Test eval5 21$repl()5",
|
||||
),
|
||||
("Test eval6 $eval(\"'$repl(a)' + '$repl(b)'\")", "Test eval6 rarrbr"),
|
||||
("Test type1 $typ([1,2,3,4])", "Test type1 <class 'list'>"),
|
||||
|
|
@ -222,8 +222,8 @@ class TestFuncParser(TestCase):
|
|||
("Test type4 $typ({1:2,3:4})", "Test type4 <class 'dict'>"),
|
||||
("Test type5 $typ(1), $typ(1.0)", "Test type5 <class 'int'>, <class 'float'>"),
|
||||
(
|
||||
"Test type6 $typ(\"'1'\"), $typ('\"1.0\"')",
|
||||
"Test type6 <class 'str'>, <class 'str'>",
|
||||
"Test type6 $typ(\"'1'\"), $typ('\"1.0\"')",
|
||||
"Test type6 <class 'str'>, <class 'str'>",
|
||||
),
|
||||
("Test add1 $add(1, 2)", "Test add1 3"),
|
||||
("Test add2 $add([1,2,3,4], [5,6])", "Test add2 [1, 2, 3, 4, 5, 6]"),
|
||||
|
|
@ -248,8 +248,8 @@ class TestFuncParser(TestCase):
|
|||
|
||||
@parameterized.expand(
|
||||
(
|
||||
"Test malformed This is $dummy(a, b) and $bar(",
|
||||
"Test $funcNotFound()",
|
||||
"Test malformed This is $dummy(a, b) and $bar(",
|
||||
"Test $funcNotFound()",
|
||||
)
|
||||
)
|
||||
def test_parse_raise_unparseable(self, unparseable):
|
||||
|
|
@ -437,20 +437,25 @@ class TestDefaultCallables(TestCase):
|
|||
("$You() $conj(smile) at $You(char1).", "You smile at You.", "Char1 smiles at Char1."),
|
||||
("$You() $conj(smile) at $You(char2).", "You smile at Char2.", "Char1 smiles at You."),
|
||||
(
|
||||
"$You(char2) $conj(smile) at $you(char1).",
|
||||
"Char2 smile at you.",
|
||||
"You smiles at Char1.",
|
||||
"$You(char2) $conj(smile) at $you(char1).",
|
||||
"Char2 smile at you.",
|
||||
"You smiles at Char1.",
|
||||
),
|
||||
(
|
||||
"$You() $conj(smile) to $pron(yourself,m).",
|
||||
"You smile to yourself.",
|
||||
"Char1 smiles to himself.",
|
||||
"$You() $conj(smile) to $pron(yourself,m).",
|
||||
"You smile to yourself.",
|
||||
"Char1 smiles to himself.",
|
||||
),
|
||||
(
|
||||
"$You() $conj(smile) to $pron(herself).",
|
||||
"You smile to yourself.",
|
||||
"Char1 smiles to herself.",
|
||||
"$You() $conj(smile) to $pron(herself).",
|
||||
"You smile to yourself.",
|
||||
"Char1 smiles to herself.",
|
||||
), # reverse reference
|
||||
(
|
||||
"$Your() smile is the greatest ever.",
|
||||
"Your smile is the greatest ever.",
|
||||
"Char1's smile is the greatest ever."
|
||||
),
|
||||
]
|
||||
)
|
||||
def test_conjugate(self, string, expected_you, expected_them):
|
||||
|
|
@ -511,8 +516,8 @@ class TestDefaultCallables(TestCase):
|
|||
[
|
||||
("Test $pad(Hello, 20, c, -) there", "Test -------Hello-------- there"),
|
||||
(
|
||||
"Test $pad(Hello, width=20, align=c, fillchar=-) there",
|
||||
"Test -------Hello-------- there",
|
||||
"Test $pad(Hello, width=20, align=c, fillchar=-) there",
|
||||
"Test -------Hello-------- there",
|
||||
),
|
||||
("Test $crop(This is a long test, 12)", "Test This is[...]"),
|
||||
("Some $space(10) here", "Some here"),
|
||||
|
|
@ -528,16 +533,16 @@ class TestDefaultCallables(TestCase):
|
|||
("Some $rjust(Hello, width=30)", "Some Hello"),
|
||||
("Some $cjust(Hello, 30)", "Some Hello "),
|
||||
(
|
||||
"There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.",
|
||||
"There is one goose here.",
|
||||
"There $pluralize(is, 1, are) one $pluralize(goose, 1, geese) here.",
|
||||
"There is one goose here.",
|
||||
),
|
||||
(
|
||||
"There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.",
|
||||
"There are two geese here.",
|
||||
"There $pluralize(is, 2, are) two $pluralize(goose, 2, geese) here.",
|
||||
"There are two geese here.",
|
||||
),
|
||||
(
|
||||
"There is $int2str(1) murderer, but $int2str(12) suspects.",
|
||||
"There is one murderer, but twelve suspects.",
|
||||
"There is $int2str(1) murderer, but $int2str(12) suspects.",
|
||||
"There is one murderer, but twelve suspects.",
|
||||
),
|
||||
("There is $an(thing) here", "There is a thing here"),
|
||||
("Some $eval(\"'-'*20\")Hello", "Some --------------------Hello"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue