2007-05-22 15:11:56 +00:00
|
|
|
"""
|
2009-01-27 15:21:15 +00:00
|
|
|
Command Table Module
|
2009-05-01 15:34:43 +00:00
|
|
|
|
2007-05-22 15:11:56 +00:00
|
|
|
Each command entry consists of a key and a tuple containing a reference to the
|
|
|
|
|
command's function, and a tuple of the permissions to match against. The user
|
|
|
|
|
only need have one of the permissions in the permissions tuple to gain
|
|
|
|
|
access to the command. Obviously, super users don't have to worry about this
|
|
|
|
|
stuff. If the command is open to all (or you want to implement your own
|
|
|
|
|
privilege checking in the command function), use None in place of the
|
|
|
|
|
permissions tuple.
|
2009-01-27 15:21:15 +00:00
|
|
|
|
|
|
|
|
Commands are located under evennia/src/commands. server.py imports these
|
|
|
|
|
based on the value of settings.COMMAND_MODULES and
|
|
|
|
|
settings.CUSTOM_COMMAND_MODULES. Each module imports cmdtable.py and runs
|
|
|
|
|
add_command on the command table each command belongs to.
|
2007-05-22 15:11:56 +00:00
|
|
|
"""
|
|
|
|
|
|
2009-04-11 23:17:44 +00:00
|
|
|
from src.helpsys.management.commands.edit_helpfiles import add_help
|
|
|
|
|
|
2008-12-14 01:49:37 +00:00
|
|
|
class CommandTable(object):
|
2008-06-17 00:38:59 +00:00
|
|
|
"""
|
2009-05-01 15:34:43 +00:00
|
|
|
Stores commands and performs lookups.
|
2008-06-17 00:38:59 +00:00
|
|
|
"""
|
2009-01-12 18:01:35 +00:00
|
|
|
ctable = None
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
# This ensures there are no leftovers when the class is instantiated.
|
|
|
|
|
self.ctable = {}
|
2008-12-14 01:49:37 +00:00
|
|
|
|
2009-01-24 03:17:43 +00:00
|
|
|
def add_command(self, command_string, function, priv_tuple=None,
|
2009-08-16 01:18:58 +00:00
|
|
|
extra_vals=None, auto_help=False, staff_help=False):
|
2008-12-14 01:49:37 +00:00
|
|
|
"""
|
|
|
|
|
Adds a command to the command table.
|
|
|
|
|
|
|
|
|
|
command_string: (string) Command string (IE: WHO, QUIT, look).
|
|
|
|
|
function: (reference) The command's function.
|
|
|
|
|
priv_tuple: (tuple) String tuple of permissions required for command.
|
2009-01-24 03:17:43 +00:00
|
|
|
extra_vals: (dict) Dictionary to add to the Command object.
|
2009-04-11 23:17:44 +00:00
|
|
|
|
|
|
|
|
Auto-help system:
|
|
|
|
|
auto_help (bool): If true, automatically creates/replaces a help topic with the
|
|
|
|
|
same name as the command_string, using the functions's __doc__ property
|
|
|
|
|
for help text.
|
2009-05-01 15:34:43 +00:00
|
|
|
staff_help (bool): Only relevant if auto_help is activated; If True, makes the
|
2009-04-11 23:17:44 +00:00
|
|
|
help topic (and all eventual subtopics) only visible to staff.
|
|
|
|
|
|
|
|
|
|
Note: the auto_help system also supports limited markup. If you divide your __doc__
|
|
|
|
|
with markers of the form <<TOPIC:MyTopic>>, the system will automatically create
|
|
|
|
|
separate help topics for each topic. Your initial text (if you define no TOPIC)
|
|
|
|
|
will still default to the name of your command.
|
|
|
|
|
You can also custon-set the staff_only flag for individual subtopics by
|
|
|
|
|
using the markup <<TOPIC:STAFF:MyTopic>> and <<TOPIC:NOSTAFF:MyTopic>>.
|
2008-12-14 01:49:37 +00:00
|
|
|
"""
|
2009-01-24 03:17:43 +00:00
|
|
|
self.ctable[command_string] = (function, priv_tuple, extra_vals)
|
2009-04-11 23:17:44 +00:00
|
|
|
|
|
|
|
|
if auto_help:
|
|
|
|
|
#add automatic help text from the command's doc string
|
|
|
|
|
topicstr = command_string
|
|
|
|
|
entrytext = function.__doc__
|
2009-05-01 15:34:43 +00:00
|
|
|
add_help(topicstr, entrytext, staff_only=staff_help,
|
2009-04-11 23:17:44 +00:00
|
|
|
force_create=True, auto_help=True)
|
|
|
|
|
|
2008-12-14 01:49:37 +00:00
|
|
|
def get_command_tuple(self, func_name):
|
|
|
|
|
"""
|
|
|
|
|
Returns a reference to the command's tuple. If there are no matches,
|
|
|
|
|
returns false.
|
|
|
|
|
"""
|
|
|
|
|
return self.ctable.get(func_name, False)
|
|
|
|
|
|
2009-05-01 15:34:43 +00:00
|
|
|
|
2008-12-14 01:49:37 +00:00
|
|
|
"""
|
2009-01-27 15:21:15 +00:00
|
|
|
Command tables
|
2008-12-14 01:49:37 +00:00
|
|
|
"""
|
2009-01-27 15:21:15 +00:00
|
|
|
# Global command table, for authenticated users.
|
2008-12-14 01:49:37 +00:00
|
|
|
GLOBAL_CMD_TABLE = CommandTable()
|
2009-01-27 15:21:15 +00:00
|
|
|
# Global unconnected command table, for unauthenticated users.
|
2009-04-11 23:17:44 +00:00
|
|
|
GLOBAL_UNCON_CMD_TABLE = CommandTable()
|