Fix gendersub. Resolve #2038

This commit is contained in:
Griatch 2020-02-03 08:51:09 +01:00
parent 47e5116345
commit e76d401117

View file

@ -8,26 +8,39 @@ insert custom markers in their text to indicate gender-aware
messaging. It relies on a modified msg() and is meant as an
inspiration and starting point to how to do stuff like this.
When in use, all messages being sent to the character will make use of
the character's gender, for example the echo
An object can have the following genders:
- male (he/his)
- female (her/hers)
- neutral (it/its)
- ambiguous (they/them/their/theirs)
When in use, messages can contain special tags to indicate pronouns gendered
based on the one being addressed. Capitalization will be retained.
- `|s`, `|S`: Subjective form: he, she, it, He, She, It, They
- `|o`, `|O`: Objective form: him, her, it, Him, Her, It, Them
- `|p`, `|P`: Possessive form: his, her, its, His, Her, Its, Their
- `|a`, `|A`: Absolute Possessive form: his, hers, its, His, Hers, Its, Theirs
For example,
```
char.msg("%s falls on |p face with a thud." % char.key)
"Tom falls on his face with a thud"
```
will result in "Tom falls on his|her|its|their face with a thud"
depending on the gender of the object being messaged. Default gender
is "ambiguous" (they).
The default gender is "ambiguous" (they/them/their/theirs).
To use, have DefaultCharacter inherit from this, or change
setting.DEFAULT_CHARACTER to point to this class.
The `@gender` command needs to be added to the default cmdset before
it becomes available.
The `@gender` command is used to set the gender. It needs to be added to the
default cmdset before it becomes available.
"""
import re
from evennia.utils import logger
from evennia import DefaultCharacter
from evennia import Command
@ -114,7 +127,10 @@ class GenderCharacter(DefaultCharacter):
gender-aware markers in output.
Args:
text (str, optional): The message to send
text (str or tuple, optional): The message to send. This
is treated internally like any send-command, so its
value can be a tuple if sending multiple arguments to
the `text` oob command.
from_obj (obj, optional): object that is sending. If
given, at_msg_send will be called
session (Session or list, optional): session or list of
@ -125,9 +141,13 @@ class GenderCharacter(DefaultCharacter):
All extra kwargs will be passed on to the protocol.
"""
# pre-process the text before continuing
try:
text = _RE_GENDER_PRONOUN.sub(self._get_pronoun, text)
if text and isinstance(text, tuple):
text = (self._RE_GENDER_PRONOUN.sub(self._get_pronoun, text[0]), *text[1:])
else:
text = self._RE_GENDER_PRONOUN.sub(self._get_pronoun, text)
except TypeError:
pass
except Exception as e:
logger.log_trace(e)
super().msg(text, from_obj=from_obj, session=session, **kwargs)