Imported from archive.
[mudpy.git] / lib / muff / muffcmds.py
index c640c96..8f1562c 100644 (file)
@@ -26,36 +26,13 @@ import muff
 for module in muff.__all__:
        exec("import " + module)
 
-# does the files:commands setting exist yet?
-try:
-       if muffconf.get("files", "commands"): pass
-
-# if not, reload the muffconf module
-except AttributeError:
-       reload(muffconf)
-
-# now we can safely nab the command path setting and build a list of data files
-command_path = muffconf.get("files", "commands")
-command_files_index = ConfigParser.SafeConfigParser()
-command_files_index.read(command_path + "/index")
-command_files = []
-for each_file in command_files_index.get("index", "files").split():
-       command_files.append(command_path + "/" + each_file)
-
-# read the command data files
-command_data = ConfigParser.SafeConfigParser()
-command_data.read(command_files)
-
-# this creates a list of commands mentioned in the data files
-command_list = command_data.sections()
-
 def handle_user_input(user):
        """The main handler, branches to a state-specific handler."""
 
        # check to make sure the state is expected, then call that handler
-       try:
+       if "handler_" + user.state in globals():
                exec("handler_" + user.state + "(user)")
-       except NameError:
+       else:
                generic_menu_handler(user)
 
        # since we got input, flag that the menu/prompt needs to be redisplayed
@@ -68,8 +45,10 @@ def generic_menu_handler(user):
        """A generic menu choice handler."""
 
        # get a lower-case representation of the next line of input
-       choice = user.input_queue.pop(0)
-       if choice: choice = choice.lower()
+       if user.input_queue:
+               choice = user.input_queue.pop(0)
+               if choice: choice = choice.lower()
+       else: choice = ""
 
        # run any script related to this choice
        exec(muffmenu.get_choice_action(user, choice))
@@ -236,7 +215,8 @@ def handler_active(user):
        command = command.lower()
 
        # the command matches a command word for which we have data
-       if command in command_list: exec("command_" + command + "(user, command, parameters)")
+       if command in muffuniv.universe.commands.keys():
+               exec(muffuniv.universe.commands[command].get("action"))
 
        # no data matching the entered command word
        elif command: command_error(user, command, parameters)
@@ -271,8 +251,7 @@ def command_quit(user, command="", parameters=""):
 
 def command_time(user, command="", parameters=""):
        """Show the current world time in elapsed increments."""
-       user.send(muffmisc.repr_long(muffmisc.getlong(muffvars.variable_data,
-               "time", "elapsed")) + " increments elapsed since the world was created.")
+       user.send(muffuniv.universe.internals["counters"].get("elapsed") + " increments elapsed since the world was created.")
 
 def command_help(user, command="", parameters=""):
        """List available commands and provide help for commands."""
@@ -281,19 +260,17 @@ def command_help(user, command="", parameters=""):
        if parameters:
 
                # is the command word one for which we have data?
-               if parameters in command_list:
+               if parameters in muffuniv.universe.commands.keys():
 
                        # add a description if provided
-                       try:
-                               description = command_data.get(parameters, "description")
-                       except:
+                       description = muffuniv.universe.commands[parameters].get("description")
+                       if not description:
                                description = "(no short description provided)"
-                       output = "$(grn)" + parameters + "$(nrm) - " + command_data.get(parameters, "description") + "$(eol)$(eol)"
+                       output = "$(grn)" + parameters + "$(nrm) - " + description + "$(eol)$(eol)"
 
                        # add the help text if provided
-                       try:
-                               help_text = command_data.get(parameters, "help")
-                       except:
+                       help_text = muffuniv.universe.commands[parameters].get("help")
+                       if not help_text:
                                help_text = "No help is provided for this command."
                        output += help_text
 
@@ -306,14 +283,13 @@ def command_help(user, command="", parameters=""):
 
                # give a sorted list of commands with descriptions if provided
                output = "These are the commands available to you:$(eol)$(eol)"
-               sorted_commands = command_list
+               sorted_commands = muffuniv.universe.commands.keys()
                sorted_commands.sort()
                for item in sorted_commands:
-                       try:
-                               description = command_data.get(item, "description")
-                       except:
+                       description = muffuniv.universe.commands[item].get("description")
+                       if not description:
                                description = "(no short description provided)"
-                       output += "   $(grn)" + item + "$(nrm) - " + command_data.get(item, "description") + "$(eol)"
+                       output += "   $(grn)" + item + "$(nrm) - " + description + "$(eol)"
                output += "$(eol)Enter \"help COMMAND\" for help on a command named \"COMMAND\"."
 
        # send the accumulated output to the user
@@ -370,16 +346,21 @@ def command_say(user, command="", parameters=""):
 
 def command_show(user, command="", parameters=""):
        """Show program data."""
-       if parameters == "universe":
-               message = "These are the current elements in the universe:$(eol)"
-               keys = muffuniv.universe.contents.keys()
-               keys.sort()
-               for key in keys: message += "$(eol)   $(grn)" + key + "$(nrm)"
-       elif parameters == "avatars":
+       if parameters == "avatars":
                message = "These are the avatars managed by your account:$(eol)"
                avatars = user.list_avatar_names()
                avatars.sort()
                for avatar in avatars: message += "$(eol)   $(grn)" + avatar + "$(nrm)"
+       elif parameters == "files":
+               message = "These are the current files containing the universe:$(eol)"
+               keys = muffuniv.universe.files.keys()
+               keys.sort()
+               for key in keys: message += "$(eol)   $(grn)" + key + "$(nrm)"
+       elif parameters == "universe":
+               message = "These are the current elements in the universe:$(eol)"
+               keys = muffuniv.universe.contents.keys()
+               keys.sort()
+               for key in keys: message += "$(eol)   $(grn)" + key + "$(nrm)"
        elif parameters: message = "I don't know what \"" + parameters + "\" is."
        else: message = "What do you want to show?"
        user.send(message)