X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fcommand.py;h=ebd9036983b8178a0f3d9a7ef71840b811446c46;hp=2eaf3832e5cd76bfe449ec2e3a4dbdccbbbc1c06;hb=b64bdabe02e5d30113df5052050cfb9b62683a74;hpb=6c86b6ed827994f838112260ba1fe162b6726ee4 diff --git a/mudpy/command.py b/mudpy/command.py index 2eaf383..ebd9036 100644 --- a/mudpy/command.py +++ b/mudpy/command.py @@ -235,6 +235,40 @@ def move(actor, parameters): actor.send("You cannot go that way.") +def preferences(actor, parameters): + """List, view and change actor preferences.""" + 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: