if parameters and actor.owner:
# is the command word one for which we have data?
- if parameters in actor.universe.groups["command"]:
- command = actor.universe.groups["command"][parameters]
- else:
- command = None
+ command = mudpy.misc.find_command(parameters)
# only for allowed commands
if actor.can_run(command):
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."""
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):
(2, "This will save all active accounts", ""),
)
+test_abbrev = (
+ (0, "> ", "help mov"),
+ (0, r"Move in a specific direction\.", "mov north"),
+ (0, r"You exit to the north\.", ""),
+)
+
test_reload = (
(2, "> ", "reload"),
(2, r"Reloading all code modules, configs and data\."
(test_telnet_unknown_option, "log unknown telnet option"),
(test_admin_restriction, "restricted admin commands"),
(test_admin_help, "admin help"),
+ (test_abbrev, "command abbreviation"),
(test_reload, "reload"),
(test_set_facet, "set facet"),
(test_set_refused, "refuse altering read-only element"),