evennia.commands.command

The base Command class.

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

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

Base command

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)

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

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

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

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

cmd.obj - the object on which this command is defined. If a default command,

this is usually the same as caller.

cmd.rawstring - the full raw string input, including 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 = None
msg_all_sessions = 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)[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.

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.

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.

client_height()[source]

Get the client screenheight for the session using this command.

Returns

client height (int) – The height (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
exception evennia.commands.command.InterruptCommand[source]

Bases: Exception

Cleanly interrupt a command.