X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fcommand.py;h=a26906b93f3885ec29afde98e19de09af4302c08;hp=2eaf3832e5cd76bfe449ec2e3a4dbdccbbbc1c06;hb=509e33f717fdbd455792f4cba3f2a583dc6100db;hpb=441a3b1816c93351b15ba23e94ce9a69e704907b diff --git a/mudpy/command.py b/mudpy/command.py index 2eaf383..a26906b 100644 --- a/mudpy/command.py +++ b/mudpy/command.py @@ -11,7 +11,7 @@ import unicodedata import mudpy -def chat(actor): +def chat(actor, parameters): """Toggle chat mode.""" mode = actor.get("mode") if not mode: @@ -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): @@ -164,7 +161,8 @@ def help(actor, parameters): output = "$(red)" else: output = "$(grn)" - output += parameters + "$(nrm) - " + description + "$(eol)$(eol)" + output = "%s%s$(nrm) - %s$(eol)$(eol)" % ( + output, command.subkey, description) # add the help text if provided help_text = command.get("help") @@ -235,14 +233,52 @@ def move(actor, parameters): actor.send("You cannot go that way.") -def quit(actor): +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, parameters): """Leave the world and go back to the main menu.""" if actor.owner: actor.owner.state = "main_utility" actor.owner.deactivate_avatar() -def reload(actor): +def reload(actor, parameters): """Reload all code modules, configs and data.""" if actor.owner: