Merge pull request #2807 from volundmush/fix_rpsystem_msg
Added msg_type to rpsystem.send_emote()
This commit is contained in:
commit
86c89b56cc
2 changed files with 32 additions and 28 deletions
|
|
@ -213,6 +213,7 @@ _RE_REF_LANG = re.compile(r"\{+\##([0-9]+)\}+")
|
||||||
# this regex returns in groups (langname, say), where langname can be empty.
|
# this regex returns in groups (langname, say), where langname can be empty.
|
||||||
_RE_LANGUAGE = re.compile(r"(?:\((\w+)\))*(\".+?\")")
|
_RE_LANGUAGE = re.compile(r"(?:\((\w+)\))*(\".+?\")")
|
||||||
|
|
||||||
|
|
||||||
# the emote parser works in two steps:
|
# the emote parser works in two steps:
|
||||||
# 1) convert the incoming emote into an intermediary
|
# 1) convert the incoming emote into an intermediary
|
||||||
# form with all object references mapped to ids.
|
# form with all object references mapped to ids.
|
||||||
|
|
@ -404,7 +405,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
match_index = marker_match.start()
|
match_index = marker_match.start()
|
||||||
# split the emote string at the reference marker, to process everything after it
|
# split the emote string at the reference marker, to process everything after it
|
||||||
head = string[:match_index]
|
head = string[:match_index]
|
||||||
tail = string[match_index + 1 :]
|
tail = string[match_index + 1:]
|
||||||
|
|
||||||
if search_mode:
|
if search_mode:
|
||||||
# match the candidates against the whole search string after the marker
|
# match the candidates against the whole search string after the marker
|
||||||
|
|
@ -450,7 +451,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
# save search string
|
# save search string
|
||||||
matched_text = "".join(tail[1:iend])
|
matched_text = "".join(tail[1:iend])
|
||||||
# recombine remainder of emote back into a string
|
# recombine remainder of emote back into a string
|
||||||
tail = "".join(tail[iend + 1 :])
|
tail = "".join(tail[iend + 1:])
|
||||||
|
|
||||||
nmatches = len(bestmatches)
|
nmatches = len(bestmatches)
|
||||||
|
|
||||||
|
|
@ -527,7 +528,7 @@ def parse_sdescs_and_recogs(sender, candidates, string, search_mode=False, case_
|
||||||
return string, mapping
|
return string, mapping
|
||||||
|
|
||||||
|
|
||||||
def send_emote(sender, receivers, emote, anonymous_add="first", **kwargs):
|
def send_emote(sender, receivers, emote, msg_type="pose", anonymous_add="first", **kwargs):
|
||||||
"""
|
"""
|
||||||
Main access function for distribute an emote.
|
Main access function for distribute an emote.
|
||||||
|
|
||||||
|
|
@ -537,6 +538,9 @@ def send_emote(sender, receivers, emote, anonymous_add="first", **kwargs):
|
||||||
will also form the basis for which sdescs are
|
will also form the basis for which sdescs are
|
||||||
'valid' to use in the emote.
|
'valid' to use in the emote.
|
||||||
emote (str): The raw emote string as input by emoter.
|
emote (str): The raw emote string as input by emoter.
|
||||||
|
msg_type (str): The type of emote this is. "say" or "pose"
|
||||||
|
for example. This is arbitrary and used for generating
|
||||||
|
extra data for .msg(text) tuple.
|
||||||
anonymous_add (str or None, optional): If `sender` is not
|
anonymous_add (str or None, optional): If `sender` is not
|
||||||
self-referencing in the emote, this will auto-add
|
self-referencing in the emote, this will auto-add
|
||||||
`sender`'s data to the emote. Possible values are
|
`sender`'s data to the emote. Possible values are
|
||||||
|
|
@ -613,7 +617,7 @@ def send_emote(sender, receivers, emote, anonymous_add="first", **kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
# do the template replacement of the sdesc/recog {#num} markers
|
# do the template replacement of the sdesc/recog {#num} markers
|
||||||
receiver.msg(sendemote.format(**receiver_sdesc_mapping), from_obj=sender, **kwargs)
|
receiver.msg(text=(sendemote.format(**receiver_sdesc_mapping), {"type": msg_type}), from_obj=sender, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
@ -924,7 +928,7 @@ class CmdSay(RPCommand): # replaces standard say
|
||||||
# calling the speech modifying hook
|
# calling the speech modifying hook
|
||||||
speech = caller.at_pre_say(self.args)
|
speech = caller.at_pre_say(self.args)
|
||||||
targets = self.caller.location.contents
|
targets = self.caller.location.contents
|
||||||
send_emote(self.caller, targets, speech, anonymous_add=None)
|
send_emote(self.caller, targets, speech, msg_type="say", anonymous_add=None)
|
||||||
|
|
||||||
|
|
||||||
class CmdSdesc(RPCommand): # set/look at own sdesc
|
class CmdSdesc(RPCommand): # set/look at own sdesc
|
||||||
|
|
@ -1267,19 +1271,19 @@ class ContribRPObject(DefaultObject):
|
||||||
self.sdesc.add("Something")
|
self.sdesc.add("Something")
|
||||||
|
|
||||||
def search(
|
def search(
|
||||||
self,
|
self,
|
||||||
searchdata,
|
searchdata,
|
||||||
global_search=False,
|
global_search=False,
|
||||||
use_nicks=True,
|
use_nicks=True,
|
||||||
typeclass=None,
|
typeclass=None,
|
||||||
location=None,
|
location=None,
|
||||||
attribute_name=None,
|
attribute_name=None,
|
||||||
quiet=False,
|
quiet=False,
|
||||||
exact=False,
|
exact=False,
|
||||||
candidates=None,
|
candidates=None,
|
||||||
nofound_string=None,
|
nofound_string=None,
|
||||||
multimatch_string=None,
|
multimatch_string=None,
|
||||||
use_dbref=None,
|
use_dbref=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Returns an Object matching a search string/condition, taking
|
Returns an Object matching a search string/condition, taking
|
||||||
|
|
@ -1363,10 +1367,10 @@ class ContribRPObject(DefaultObject):
|
||||||
)
|
)
|
||||||
|
|
||||||
if global_search or (
|
if global_search or (
|
||||||
is_string
|
is_string
|
||||||
and searchdata.startswith("#")
|
and searchdata.startswith("#")
|
||||||
and len(searchdata) > 1
|
and len(searchdata) > 1
|
||||||
and searchdata[1:].isdigit()
|
and searchdata[1:].isdigit()
|
||||||
):
|
):
|
||||||
# only allow exact matching if searching the entire database
|
# only allow exact matching if searching the entire database
|
||||||
# or unique #dbrefs
|
# or unique #dbrefs
|
||||||
|
|
|
||||||
|
|
@ -222,17 +222,17 @@ class TestRPSystem(BaseEvenniaTest):
|
||||||
receiver2.msg = lambda text, **kwargs: setattr(self, "out2", text)
|
receiver2.msg = lambda text, **kwargs: setattr(self, "out2", text)
|
||||||
rpsystem.send_emote(speaker, receivers, emote, case_sensitive=False)
|
rpsystem.send_emote(speaker, receivers, emote, case_sensitive=False)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out0,
|
self.out0[0],
|
||||||
"With a flair, |mSender|n looks at |bThe first receiver of emotes.|n "
|
"With a flair, |mSender|n looks at |bThe first receiver of emotes.|n "
|
||||||
'and |bAnother nice colliding sdesc-guy for tests|n. She says |w"This is a test."|n',
|
'and |bAnother nice colliding sdesc-guy for tests|n. She says |w"This is a test."|n',
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out1,
|
self.out1[0],
|
||||||
"With a flair, |bA nice sender of emotes|n looks at |mReceiver1|n and "
|
"With a flair, |bA nice sender of emotes|n looks at |mReceiver1|n and "
|
||||||
'|bAnother nice colliding sdesc-guy for tests|n. She says |w"This is a test."|n',
|
'|bAnother nice colliding sdesc-guy for tests|n. She says |w"This is a test."|n',
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out2,
|
self.out2[0],
|
||||||
"With a flair, |bA nice sender of emotes|n looks at |bThe first "
|
"With a flair, |bA nice sender of emotes|n looks at |bThe first "
|
||||||
'receiver of emotes.|n and |mReceiver2|n. She says |w"This is a test."|n',
|
'receiver of emotes.|n and |mReceiver2|n. She says |w"This is a test."|n',
|
||||||
)
|
)
|
||||||
|
|
@ -251,19 +251,19 @@ class TestRPSystem(BaseEvenniaTest):
|
||||||
receiver2.msg = lambda text, **kwargs: setattr(self, "out2", text)
|
receiver2.msg = lambda text, **kwargs: setattr(self, "out2", text)
|
||||||
rpsystem.send_emote(speaker, receivers, case_emote)
|
rpsystem.send_emote(speaker, receivers, case_emote)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out0,
|
self.out0[0],
|
||||||
"|mSender|n looks at |bthe first receiver of emotes.|n. Then, |mSender|n "
|
"|mSender|n looks at |bthe first receiver of emotes.|n. Then, |mSender|n "
|
||||||
"looks at |bTHE FIRST RECEIVER OF EMOTES.|n, |bThe first receiver of emotes.|n "
|
"looks at |bTHE FIRST RECEIVER OF EMOTES.|n, |bThe first receiver of emotes.|n "
|
||||||
"and |bAnother nice colliding sdesc-guy for tests|n twice.",
|
"and |bAnother nice colliding sdesc-guy for tests|n twice.",
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out1,
|
self.out1[0],
|
||||||
"|bA nice sender of emotes|n looks at |mReceiver1|n. Then, "
|
"|bA nice sender of emotes|n looks at |mReceiver1|n. Then, "
|
||||||
"|ba nice sender of emotes|n looks at |mReceiver1|n, |mReceiver1|n "
|
"|ba nice sender of emotes|n looks at |mReceiver1|n, |mReceiver1|n "
|
||||||
"and |bAnother nice colliding sdesc-guy for tests|n twice.",
|
"and |bAnother nice colliding sdesc-guy for tests|n twice.",
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.out2,
|
self.out2[0],
|
||||||
"|bA nice sender of emotes|n looks at |bthe first receiver of emotes.|n. "
|
"|bA nice sender of emotes|n looks at |bthe first receiver of emotes.|n. "
|
||||||
"Then, |ba nice sender of emotes|n looks at |bTHE FIRST RECEIVER OF EMOTES.|n, "
|
"Then, |ba nice sender of emotes|n looks at |bTHE FIRST RECEIVER OF EMOTES.|n, "
|
||||||
"|bThe first receiver of emotes.|n and |mReceiver2|n twice.",
|
"|bThe first receiver of emotes.|n and |mReceiver2|n twice.",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue