Expand the 'say' command to be personable again
This commit is contained in:
parent
ddddfe4b7b
commit
a9e0c24ad9
2 changed files with 28 additions and 15 deletions
|
|
@ -36,18 +36,28 @@ class CmdSay(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "say"
|
key = "say"
|
||||||
aliases = ["speak", "yell", "scream", "ask"]
|
aliases = ["speak", "yell", "scream", "ask", "\""]
|
||||||
priority = 0
|
priority = 0
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
rhs_split = (",", "=")
|
rhs_split = ("=")
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"""
|
"""
|
||||||
Implements the new 'say' command with switches.
|
Implements the new 'say' command with switches.
|
||||||
"""
|
"""
|
||||||
def characters(chars):
|
def chars_for_self(chars):
|
||||||
|
return [self.caller.search(c).get_display_name(self) for c in split(r"[ ,]+", chars)]
|
||||||
|
|
||||||
|
def chars_for_others(chars):
|
||||||
return [c if c.startswith('/') else '/'+c for c in split(r"[ ,]+", chars)]
|
return [c if c.startswith('/') else '/'+c for c in split(r"[ ,]+", chars)]
|
||||||
|
|
||||||
|
def chars_list(chars, verb, for_rp=True):
|
||||||
|
char_lst = chars_for_others(chars) if for_rp else chars_for_self(chars)
|
||||||
|
return (' to ' if verb == 'say' else ' ') + \
|
||||||
|
iter_to_str(char_lst, endsep='and')
|
||||||
|
|
||||||
|
logger.info(f"CmdSayIt: {self.cmdstring} lhs={self.lhs} switches={self.switches}")
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Say what?")
|
self.caller.msg("Say what?")
|
||||||
return
|
return
|
||||||
|
|
@ -61,29 +71,31 @@ class CmdSay(MuxCommand):
|
||||||
if not self.caller.at_pre_say(speech):
|
if not self.caller.at_pre_say(speech):
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"CmdSayIt: {self.cmdstring}")
|
|
||||||
adverb = ''
|
adverb = ''
|
||||||
for switch in self.switches:
|
for switch in self.switches:
|
||||||
if switch.endswith('ly'):
|
if switch.endswith('ly'):
|
||||||
adverb = switch + ' '
|
adverb = switch + ' '
|
||||||
|
|
||||||
if 'yell' in self.switches or self.cmdstring == 'yell' or speech.endswith('!'):
|
if 'yell' in self.switches or self.cmdstring == 'yell' or speech.endswith('!'):
|
||||||
omsg_type = adverb + 'yells'
|
verb = 'yell'
|
||||||
elif 'scream' in self.switches or self.cmdstring == 'scream':
|
elif 'scream' in self.switches or self.cmdstring == 'scream':
|
||||||
omsg_type = adverb + 'screams'
|
verb = 'scream'
|
||||||
elif 'ask' in self.switches or self.cmdstring == 'ask' or speech.endswith('?'):
|
elif 'ask' in self.switches or self.cmdstring == 'ask' or speech.endswith('?'):
|
||||||
omsg_type = adverb + 'asks'
|
verb = 'ask'
|
||||||
else:
|
else:
|
||||||
omsg_type = adverb + "says"
|
verb = "say"
|
||||||
|
|
||||||
if 'to' in self.switches:
|
# The `send_emote` is _global_, so if we want to say to 'Bob',
|
||||||
to_whom = ' to ' if omsg_type.endswith('says') else ' ' + \
|
# 'You say ...', we have to both send him a message with the
|
||||||
iter_to_str(characters(self.lhs), endsep='and')
|
# 'You' as well as everyone else with the 'send_emote'.
|
||||||
else:
|
|
||||||
to_whom = ''
|
|
||||||
|
|
||||||
full_speech = f"/Me {omsg_type}{to_whom}, \"{speech}\""
|
to_whom = chars_list(self.lhs, verb, for_rp=False) if 'to' in self.switches else ''
|
||||||
targets = self.caller.location.contents
|
full_speech = f"You {adverb}{verb}{to_whom}, \"{speech}\""
|
||||||
|
self.caller.msg(full_speech, from_obj=self.caller)
|
||||||
|
|
||||||
|
targets = [item for item in self.caller.location.contents if item != self.caller]
|
||||||
|
to_whom = chars_list(self.lhs, verb) if 'to' in self.switches else ''
|
||||||
|
full_speech = f"/Me {adverb}{verb}s{to_whom}, \"{speech}\""
|
||||||
send_emote(self.caller, targets, full_speech, msg_type="say", anonymous_add=None)
|
send_emote(self.caller, targets, full_speech, msg_type="say", anonymous_add=None)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ STATIC_URL = "/cozy/static/"
|
||||||
SSH_ENABLED = True
|
SSH_ENABLED = True
|
||||||
# SSL_ENABLED = True
|
# SSL_ENABLED = True
|
||||||
|
|
||||||
|
FUNCPARSER_PARSE_OUTGOING_MESSAGES_ENABLED = True
|
||||||
SEARCH_MULTIMATCH_REGEX = r"(?P<number>[0-9]+)-(?P<name>[^-]*)(?P<args>.*)"
|
SEARCH_MULTIMATCH_REGEX = r"(?P<number>[0-9]+)-(?P<name>[^-]*)(?P<args>.*)"
|
||||||
SEARCH_MULTIMATCH_TEMPLATE = " {number}-{name}{aliases}{info}\n"
|
SEARCH_MULTIMATCH_TEMPLATE = " {number}-{name}{aliases}{info}\n"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue