X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fcommand.py;h=95fb793d3f7e25fcf92b36b81ea95e1756658002;hp=14640dab3f787260761a65212dffddb175123d28;hb=de65a162dc402df0e052c9a6e79a533a00036902;hpb=e25d11c16634028eaf5a498adf0aacc0ad9ffda0 diff --git a/mudpy/command.py b/mudpy/command.py index 14640da..95fb793 100644 --- a/mudpy/command.py +++ b/mudpy/command.py @@ -1,6 +1,6 @@ """User command functions for the mudpy engine.""" -# Copyright (c) 2004-2018 mudpy authors. Permission to use, copy, +# Copyright (c) 2004-2019 mudpy authors. Permission to use, copy, # modify, and distribute this software is granted under terms # provided in the LICENSE file distributed with this software. @@ -148,10 +148,7 @@ def help(actor, parameters): 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): @@ -235,6 +232,44 @@ def move(actor, parameters): actor.send("You cannot go that way.") +def preferences(actor, parameters): + """List, view and change actor preferences.""" + + # Escape replacement macros in preferences + parameters = mudpy.misc.escape_macros(parameters) + + message = "" + arguments = parameters.split() + allowed_prefs = set() + user_config = actor.universe.contents.get("mudpy.user") + if user_config: + allowed_prefs.update(user_config.get("pref_allow", [])) + if actor.owner.account.get("administrator"): + allowed_prefs.update(user_config.get("pref_admin", [])) + if not arguments: + message += "These are your current preferences:" + for pref in allowed_prefs: + message += ("$(eol) $(red)%s $(grn)%s$(nrm)" + % (pref, actor.owner.account.get(pref))) + elif arguments[0] not in allowed_prefs: + message += ( + 'Preference "%s" does not exist. Try the `preferences` command by ' + "itself for a list of valid preferences." % arguments[0]) + elif len(arguments) == 1: + message += "%s" % actor.owner.account.get(arguments[0]) + else: + pref = arguments[0] + value = " ".join(arguments[1:]) + try: + actor.owner.account.set(pref, value) + message += 'Preference "%s" set to "%s".' % (pref, value) + except ValueError: + message = ( + 'Preference "%s" cannot be set to type "%s".' % ( + pref, type(value))) + actor.send(message) + + def quit(actor): """Leave the world and go back to the main menu.""" if actor.owner: @@ -341,7 +376,7 @@ def say(actor, parameters): actor.send("What do you want to say?") -def set(actor, parameters): +def c_set(actor, parameters): """Set a facet of an element.""" if not parameters: message = "You must specify an element, a facet and a value."