From a9e0c24ad9cd77b70334a044595bb2cbcd9d1392 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Sun, 27 Apr 2025 09:08:53 -0700 Subject: [PATCH] Expand the 'say' command to be personable again --- commands/everyone.py | 42 ++++++++++++++++++++++++++--------------- server/conf/settings.py | 1 + 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/commands/everyone.py b/commands/everyone.py index 4a12e1e..19f44bf 100755 --- a/commands/everyone.py +++ b/commands/everyone.py @@ -36,18 +36,28 @@ class CmdSay(MuxCommand): """ key = "say" - aliases = ["speak", "yell", "scream", "ask"] + aliases = ["speak", "yell", "scream", "ask", "\""] priority = 0 locks = "cmd:all()" - rhs_split = (",", "=") + rhs_split = ("=") def func(self): """ 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)] + 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: self.caller.msg("Say what?") return @@ -61,29 +71,31 @@ class CmdSay(MuxCommand): if not self.caller.at_pre_say(speech): return - logger.info(f"CmdSayIt: {self.cmdstring}") adverb = '' for switch in self.switches: if switch.endswith('ly'): adverb = switch + ' ' 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': - omsg_type = adverb + 'screams' + verb = 'scream' elif 'ask' in self.switches or self.cmdstring == 'ask' or speech.endswith('?'): - omsg_type = adverb + 'asks' + verb = 'ask' else: - omsg_type = adverb + "says" + verb = "say" - if 'to' in self.switches: - to_whom = ' to ' if omsg_type.endswith('says') else ' ' + \ - iter_to_str(characters(self.lhs), endsep='and') - else: - to_whom = '' + # The `send_emote` is _global_, so if we want to say to 'Bob', + # 'You say ...', we have to both send him a message with the + # 'You' as well as everyone else with the 'send_emote'. - full_speech = f"/Me {omsg_type}{to_whom}, \"{speech}\"" - targets = self.caller.location.contents + to_whom = chars_list(self.lhs, verb, for_rp=False) if 'to' in self.switches else '' + 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) diff --git a/server/conf/settings.py b/server/conf/settings.py index 65f6eff..d545838 100644 --- a/server/conf/settings.py +++ b/server/conf/settings.py @@ -49,6 +49,7 @@ STATIC_URL = "/cozy/static/" SSH_ENABLED = True # SSL_ENABLED = True +FUNCPARSER_PARSE_OUTGOING_MESSAGES_ENABLED = True SEARCH_MULTIMATCH_REGEX = r"(?P[0-9]+)-(?P[^-]*)(?P.*)" SEARCH_MULTIMATCH_TEMPLATE = " {number}-{name}{aliases}{info}\n"