X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=501d5b40498ccc3e2bd0dab25a4a1ffb92352de7;hp=50a94569fbad396bf2c84b577caeb0aba6c8f1e1;hb=de65a162dc402df0e052c9a6e79a533a00036902;hpb=56f918a8f40771b5fd7db125d301b8e50e9a7a32 diff --git a/mudpy/misc.py b/mudpy/misc.py index 50a9456..501d5b4 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -1474,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.""" @@ -1864,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):