evennia.commands.command

The base Command class.

All commands in Evennia inherit from the ‘Command’ class in this module.

exception evennia.commands.command.InterruptCommand[source]

Bases: Exception

Cleanly interrupt a command.

class evennia.commands.command.CommandMeta(*args, **kwargs)[source]

Bases: type

The metaclass cleans up all properties on the class

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class evennia.commands.command.Command(**kwargs)[source]

Bases: object

(you may see this if a child command had no help text defined)

Usage:

command [args]

This is the base command class. Inherit from this to create new commands.

The cmdhandler makes the following variables available to the command methods (so you can always assume them to be there):

self.caller - the game object calling the command self.cmdstring - the command name used to trigger this command (allows

you to know which alias was used, for example)

self.args - everything supplied to the command following the cmdstring

(this is usually what is parsed in self.parse())

self.cmdset - the merged cmdset from which this command was matched (useful only

seldomly, notably for help-type commands, to create dynamic help entries and lists)

self.cmdset_source - the specific cmdset this command was matched from. self.obj - the object on which this command is defined. If a default command,

this is usually the same as caller.

self.raw_string - the full raw string input, including the command name,

any args and no parsing.

The following class properties can/should be defined on your child class:

key - identifier for command (e.g. “look”) aliases - (optional) list of aliases (e.g. [“l”, “loo”]) locks - lock string (default is “cmd:all()”) help_category - how to organize this help entry in help system

(default is “General”)

auto_help - defaults to True. Allows for turning off auto-help generation arg_regex - (optional) raw string regex defining how the argument part of

the command should look in order to match for this command (e.g. must it be a space between cmdname and arg?)

auto_help_display_key - (optional) if given, this replaces the string shown

in the auto-help listing. This is particularly useful for system-commands whose actual key is not really meaningful.

(Note that if auto_help is on, this initial string is also used by the system to create the help entry for the command, so it’s a good idea to format it similar to this one). This behavior can be changed by overriding the method ‘get_help’ of a command: by default, this method returns cmd.__doc__ (that is, this very docstring, or the docstring of your command). You can, however, extend or replace this without disabling auto_help.

key = 'command'
aliases = []
locks = 'cmd:all();'
help_category = 'general'
auto_help = True
is_exit = False
arg_regex = re.compile('^[ /]|\\n|$', re.IGNORECASE)
msg_all_sessions = False
retain_instance = False
__init__(**kwargs)[source]

The lockhandler works the same as for objects. optional kwargs will be set as properties on the Command at runtime, overloading evential same-named class properties.

lockhandler[source]
set_key(new_key)[source]

Update key.

Parameters

new_key (str) – The new key.

Notes

This is necessary to use to make sure the optimization caches are properly updated as well.

set_aliases(new_aliases)[source]

Replace aliases with new ones.

Parameters

new_aliases (str or list) – Either a ;-separated string or a list of aliases. These aliases will replace the existing ones, if any.

Notes

This is necessary to use to make sure the optimization caches are properly updated as well.

match(cmdname, include_prefixes=True)[source]

This is called by the system when searching the available commands, in order to determine if this is the one we wanted. cmdname was previously extracted from the raw string by the system.

Parameters

cmdname (str) – Always lowercase when reaching this point.

Kwargs:
include_prefixes (bool): If false, will compare against the _noprefix

variants of commandnames.

Returns

result (bool) – Match result.

access(srcobj, access_type='cmd', default=False)[source]

This hook is called by the cmdhandler to determine if srcobj is allowed to execute this command. It should return a boolean value and is not normally something that need to be changed since it’s using the Evennia permission system directly.

Parameters
  • srcobj (Object) – Object trying to gain permission

  • access_type (str, optional) – The lock type to check.

  • default (bool, optional) – The fallback result if no lock of matching access_type is found on this Command.

msg(text=None, to_obj=None, from_obj=None, session=None, **kwargs)[source]

This is a shortcut instead of calling msg() directly on an object - it will detect if caller is an Object or an Account and also appends self.session automatically if self.msg_all_sessions is False.

Parameters
  • text (str, optional) – Text string of message to send.

  • to_obj (Object, optional) – Target object of message. Defaults to self.caller.

  • from_obj (Object, optional) – Source of message. Defaults to to_obj.

  • session (Session, optional) – Supply data only to a unique session (ignores the value of self.msg_all_sessions).

Keyword Arguments
  • options (dict) – Options to the protocol.

  • any (any) – All other keywords are interpreted as th name of send-instructions.

execute_cmd(raw_string, session=None, obj=None, **kwargs)[source]

A shortcut of execute_cmd on the caller. It appends the session automatically.

Parameters
  • raw_string (str) – Execute this string as a command input.

  • session (Session, optional) – If not given, the current command’s Session will be used.

  • obj (Object or Account, optional) – Object or Account on which to call the execute_cmd. If not given, self.caller will be used.

Keyword Arguments
  • keyword arguments will be added to the found command (Other) –

  • instace as variables before it executes. This is (object) –

  • by default Evennia but may be used to set flags and (unused) –

  • operating paramaters for commands at run-time. (change) –

at_pre_cmd()[source]

This hook is called before self.parse() on all commands. If this hook returns anything but False/None, the command sequence is aborted.

at_post_cmd()[source]

This hook is called after the command has finished executing (after self.func()).

parse()[source]

Once the cmdhandler has identified this as the command we want, this function is run. If many of your commands have a similar syntax (for example ‘cmd arg1 = arg2’) you should simply define this once and just let other commands of the same form inherit from this. See the docstring of this module for which object properties are available to use (notably self.args).

get_command_info()[source]

This is the default output of func() if no func() overload is done. Provided here as a separate method so that it can be called for debugging purposes when making commands.

func()[source]

This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())

get_extra_info(caller, **kwargs)[source]

Display some extra information that may help distinguish this command from others, for instance, in a disambiguity prompt.

If this command is a potential match in an ambiguous situation, one distinguishing feature may be its attachment to a nearby object, so we include this if available.

Parameters
  • caller (TypedObject) – The caller who typed an ambiguous

  • handed to the search function. (term) –

Returns

A string with identifying information to disambiguate the object, conventionally with a preceding space.

get_help(caller, cmdset)[source]

Return the help message for this command and this caller.

By default, return self.__doc__ (the docstring just under the class definition). You can override this behavior, though, and even customize it depending on the caller, or other commands the caller can use.

Parameters
  • caller (Object or Account) – the caller asking for help on the command.

  • cmdset (CmdSet) – the command set (if you need additional commands).

Returns

docstring (str) – the help text to provide the caller for this command.

web_get_detail_url()[source]

Returns the URI path for a View that allows users to view details for this object.

ex. Oscar (Character) = ‘/characters/oscar/1/’

For this to work, the developer must have defined a named view somewhere in urls.py that follows the format ‘modelname-action’, so in this case a named view of ‘character-detail’ would be referenced by this method.

ex.

url(r'characters/(?P<slug>[\w\d\-]+)/(?P<pk>[0-9]+)/$',
    CharDetailView.as_view(), name='character-detail')

If no View has been created and defined in urls.py, returns an HTML anchor.

This method is naive and simply returns a path. Securing access to the actual view and limiting who can view this object is the developer’s responsibility.

Returns

path (str) – URI path to object detail page, if defined.

web_get_admin_url()[source]

Returns the URI path for the Django Admin page for this object.

ex. Account#1 = ‘/admin/accounts/accountdb/1/change/’

Returns

path (str) – URI path to Django Admin page for object.

client_width()[source]

Get the client screenwidth for the session using this command.

Returns

client width (int) – The width (in characters) of the client window.

styled_table(*args, **kwargs)[source]

Create an EvTable styled by on user preferences.

Parameters

*args (str) – Column headers. If not colored explicitly, these will get colors from user options.

Keyword Arguments

any (str, int or dict) – EvTable options, including, optionally a table dict detailing the contents of the table.

Returns

table (EvTable)

An initialized evtable entity, either complete (if using table kwarg)

or incomplete and ready for use with .add_row or .add_collumn.

styled_header(*args, **kwargs)[source]

Create a pretty header.

styled_separator(*args, **kwargs)[source]

Create a separator.

Create a pretty footer.

lock_storage = 'cmd:all();'
save_for_next = False
search_index_entry = {'aliases': '', 'category': 'general', 'key': 'command', 'no_prefix': ' ', 'tags': '', 'text': '\n ## Base command\n\n (you may see this if a child command had no help text defined)\n\n Usage:\n command [args]\n\n This is the base command class. Inherit from this\n to create new commands.\n\n The cmdhandler makes the following variables available to the\n command methods (so you can always assume them to be there):\n\n self.caller - the game object calling the command\n self.cmdstring - the command name used to trigger this command (allows\n you to know which alias was used, for example)\n self.args - everything supplied to the command following the cmdstring\n (this is usually what is parsed in self.parse())\n self.cmdset - the merged cmdset from which this command was matched (useful only\n seldomly, notably for help-type commands, to create dynamic\n help entries and lists)\n self.cmdset_source - the specific cmdset this command was matched from.\n self.obj - the object on which this command is defined. If a default command,\n this is usually the same as caller.\n self.raw_string - the full raw string input, including the command name,\n any args and no parsing.\n\n The following class properties can/should be defined on your child class:\n\n key - identifier for command (e.g. "look")\n aliases - (optional) list of aliases (e.g. ["l", "loo"])\n locks - lock string (default is "cmd:all()")\n help_category - how to organize this help entry in help system\n (default is "General")\n auto_help - defaults to True. Allows for turning off auto-help generation\n arg_regex - (optional) raw string regex defining how the argument part of\n the command should look in order to match for this command\n (e.g. must it be a space between cmdname and arg?)\n auto_help_display_key - (optional) if given, this replaces the string shown\n in the auto-help listing. This is particularly useful for system-commands\n whose actual key is not really meaningful.\n\n (Note that if auto_help is on, this initial string is also used by the\n system to create the help entry for the command, so it\'s a good idea to\n format it similar to this one). This behavior can be changed by\n overriding the method \'get_help\' of a command: by default, this\n method returns cmd.__doc__ (that is, this very docstring, or\n the docstring of your command). You can, however, extend or\n replace this without disabling auto_help.\n '}