X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=501d5b40498ccc3e2bd0dab25a4a1ffb92352de7;hp=dce3ea6c84c7b0ccdc1782a4d5d7601414ef3b6b;hb=de65a162dc402df0e052c9a6e79a533a00036902;hpb=da204426401f781b90121eac018166bcde5ee211 diff --git a/mudpy/misc.py b/mudpy/misc.py index dce3ea6..501d5b4 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -672,8 +672,18 @@ class User: if not prompt: return get_menu_prompt(self.state) + # Allow including the World clock state + if "$_(time)" in prompt: + prompt = prompt.replace( + "$_(time)", + str(universe.groups["internal"]["counters"].get("elapsed"))) + + # Append a single space for clear separation from user input + if prompt[-1] != " ": + prompt = "%s " % prompt + # Return the cooked prompt - return "%s " % prompt + return prompt def adjust_echoing(self): """Adjust echoing to match state menu requirements.""" @@ -1464,6 +1474,25 @@ def check_for_connection(listening_socket): return user +def find_command(command_name): + """Try to find a command by name or abbreviation.""" + + # lowercase the command + command_name = command_name.lower() + + command = None + if command_name in universe.groups["command"]: + # the command matches a command word for which we have data + command = universe.groups["command"][command_name] + else: + for candidate in sorted(universe.groups["command"]): + if candidate.startswith(command_name): + # the command matches the start of a command word + command = universe.groups["command"][candidate] + break + return command + + def get_menu(state, error=None, choices=None): """Show the correct menu text to a user.""" @@ -1854,14 +1883,8 @@ def handler_active(user): else: command_name, parameters = first_word(input_data) - # lowercase the command - command_name = command_name.lower() - - # the command matches a command word for which we have data - if command_name in universe.groups["command"]: - command = universe.groups["command"][command_name] - else: - command = None + # expand to an actual command + command = find_command(command_name) # if it's allowed, do it if actor.can_run(command):