Fix bug in say to command

Also, if you say without ending in punctuation, the "say" command
output is reversed. Just to keep everyone on their toes.
This commit is contained in:
Howard Abrams 2026-03-13 22:18:46 -07:00
parent bef4d35f36
commit 92b6c9973b
2 changed files with 36 additions and 12 deletions

View file

@ -4,7 +4,7 @@ from random import random
from re import match, split, sub, MULTILINE from re import match, split, sub, MULTILINE
from evennia.contrib.rpg.rpsystem import send_emote from evennia.contrib.rpg.rpsystem import send_emote
from evennia.utils import logger from evennia.utils import logger, delay
from evennia.utils.verb_conjugation.pronouns import PRONOUN_MAPPING from evennia.utils.verb_conjugation.pronouns import PRONOUN_MAPPING
from commands.command import Command from commands.command import Command
@ -154,6 +154,7 @@ class CmdSay(Command):
def parse(self): def parse(self):
"""Parse the input into speech parts.""" """Parse the input into speech parts."""
self.phrase = self.args.strip() self.phrase = self.args.strip()
self.reverse = False
m = match(r".+\?.*", self.phrase) m = match(r".+\?.*", self.phrase)
if m: if m:
@ -161,6 +162,9 @@ class CmdSay(Command):
m = match(r".+!.*", self.phrase) m = match(r".+!.*", self.phrase)
if m: if m:
self.verb = "exclaim" self.verb = "exclaim"
m = match(r'.+\w$', self.phrase)
if m:
self.reverse = True
m = match(r'.*".+".*', self.phrase) m = match(r'.*".+".*', self.phrase)
if not m: if not m:
@ -236,10 +240,16 @@ class CmdSay(Command):
verb = " " + verb verb = " " + verb
adverb = " " + self.adverb if self.adverb else "" adverb = " " + self.adverb if self.adverb else ""
if adverb.endswith("ly") and random() < 0.5: if self.reverse:
full_speech = f"You{adverb}{verb}{to_who}, \"{phrase}\"" if adverb.endswith("ly") and random() < 0.5:
full_speech = f"\"{phrase},\" you{adverb}{verb}{to_who}."
else:
full_speech = f"\"{phrase},\" you{verb}{adverb}{to_who}."
else: else:
full_speech = f"You{verb}{adverb}{to_who}, \"{phrase}\"" if adverb.endswith("ly") and random() < 0.5:
full_speech = f"You{adverb}{verb}{to_who}, \"{phrase}\""
else:
full_speech = f"You{verb}{adverb}{to_who}, \"{phrase}\""
speaker.msg(full_speech, from_obj=speaker) speaker.msg(full_speech, from_obj=speaker)
def to_others(self, speaker, verb, phrase): def to_others(self, speaker, verb, phrase):
@ -254,23 +264,35 @@ class CmdSay(Command):
whom = PRONOUN_MAPPING['3rd person']['reflexive pronoun'][self.caller.db.gender] whom = PRONOUN_MAPPING['3rd person']['reflexive pronoun'][self.caller.db.gender]
else: else:
who = self.target.get_display_name(speaker) who = self.target.get_display_name(speaker)
whom = f"/{self.target.key}" if self.target.sdesc:
whom = f"the /{self.target.sdesc.get()}"
else:
whom = f"the /{self.target.name}"
if verb == "ask": if verb == "ask":
to_whom = " " + whom to_whom = " " + whom
else: else:
to_whom = " to " + whom to_whom = " to " + whom
# English is weird... # english is weird...
verb = ' replie' if verb == 'reply' else " " + verb verb = ' replie' if verb == 'reply' else " " + verb
adverb = " " + self.adverb if self.adverb else "" adverb = " " + self.adverb if self.adverb else ""
targets = [item for item in speaker.location.contents targets = [item for item in speaker.location.contents
if item != speaker] if item != speaker]
if adverb.endswith("ly") and random() < 0.5: if self.reverse:
full_speech = f"/me{adverb}{verb}s{to_whom}, \"{phrase}\"" if adverb.endswith("ly") and random() < 0.5:
full_speech = f"\"{phrase},\" /me{adverb}{verb}s{to_whom}."
else:
full_speech = f"\"{phrase},\" /me{verb}s{adverb}{to_whom}."
else: else:
full_speech = f"/me{verb}s{adverb}{to_whom}, \"{phrase}\"" if adverb.endswith("ly") and random() < 0.5:
full_speech = f"/me{adverb}{verb}s{to_whom}, \"{phrase}\""
else:
full_speech = f"/me{verb}s{adverb}{to_whom}, \"{phrase}\""
logger.info(f"Full speech: {full_speech}")
# Full speech: /me asks /Trampoli, "How are you?"
send_emote(speaker, targets, full_speech, msg_type="say", send_emote(speaker, targets, full_speech, msg_type="say",
anonymous_add=None) anonymous_add=None)
@ -283,8 +305,9 @@ class CmdSay(Command):
if not target: if not target:
for char in speaker.location.contents: for char in speaker.location.contents:
if hasattr(char, 'other_say') and callable(char.other_say): if hasattr(char, 'other_say') and callable(char.other_say):
char.other_say(speaker, phrase) logger.info(f"to_puppets: all: {char}")
delay(1, char.other_say, speaker, phrase)
else: else:
if hasattr(target, 'other_sayto') and callable(target.other_sayto): if hasattr(target, 'other_sayto') and callable(target.other_sayto):
logger.info(f"Found {target.key}: {phrase}") logger.info(f"Found {target.key}: {phrase}")
target.other_sayto(speaker, phrase) delay(1, target.other_sayto, speaker, phrase)

View file

@ -122,7 +122,8 @@ class KnockScript(Script):
gnome = search_object("Dabbler").first() gnome = search_object("Dabbler").first()
if gnome: if gnome:
gnome.msg(f"With your seer stone, you see the knocker is {knocker.key}, {knocker.db._sdesc}.") delay(3, gnome.msg,
f"With your seer stone, you see the knocker is {knocker.key}, the {knocker.db._sdesc}.")
def at_repeat(self, **kwargs): def at_repeat(self, **kwargs):
waker = self.attributes.get("waker") waker = self.attributes.get("waker")