<spanid="evennia-commands-cmdset"></span><h1>evennia.commands.cmdset<aclass="headerlink"href="#module-evennia.commands.cmdset"title="Permalink to this headline">¶</a></h1>
<p>A Command Set (CmdSet) holds a set of commands. The Cmdsets can be
merged and combined to create new sets of commands in a
non-destructive way. This makes them very powerful for implementing
custom game states where different commands (or different variations
of commands) are available to the accounts depending on circumstance.</p>
<p>The available merge operations are partly borrowed from mathematical
Set theory.</p>
<ulclass="simple">
<li><dlclass="simple">
<dt>Union The two command sets are merged so that as many commands as</dt><dd><p>possible of each cmdset ends up in the merged cmdset. Same-name
commands are merged by priority. This is the most common default.
Ex: A1,A3 + B1,B2,B4,B5 = A1,B2,A3,B4,B5</p>
</dd>
</dl>
</li>
<li><dlclass="simple">
<dt>Intersect - Only commands found in <em>both</em> cmdsets (i.e. which have</dt><dd><p>same names) end up in the merged cmdset, with the higher-priority
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.commands.cmdset.</code><codeclass="sig-name descname">CmdSet</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdsetobj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">key</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">mergetype</code><emclass="property"> = 'Union'</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.mergetype"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">priority</code><emclass="property"> = 0</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.priority"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">no_exits</code><emclass="property"> = None</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.no_exits"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">no_objs</code><emclass="property"> = None</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.no_objs"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">no_channels</code><emclass="property"> = None</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.no_channels"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">duplicates</code><emclass="property"> = None</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.duplicates"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">persistent</code><emclass="property"> = False</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.persistent"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">key_mergetypes</code><emclass="property"> = {}</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.key_mergetypes"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">errmessage</code><emclass="property"> = ''</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.errmessage"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmdsetobj</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">key</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.__init__"title="Permalink to this definition">¶</a></dt>
<li><p><strong>cmdsetobj</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>Account</em><em>, </em><em>Object</em><em>, </em><em>optional</em>) – This is the database object
to which this particular instance of cmdset is related. It
is often a character but may also be a regular object, Account
or Session.</p></li>
<li><p><strong>key</strong> (<em>str</em><em>, </em><em>optional</em>) – The idenfier for this cmdset. This
helps if wanting to selectively remov cmdsets.</p></li>
<codeclass="sig-name descname">key</code><emclass="property"> = 'Unnamed CmdSet'</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.key"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">add</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmd</span></em>, <emclass="sig-param"><spanclass="n">allow_duplicates</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.add"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.add"title="Permalink to this definition">¶</a></dt>
<li><p><strong>cmd</strong> (<aclass="reference internal"href="evennia.commands.command.html#evennia.commands.command.Command"title="evennia.commands.command.Command"><em>Command</em></a><em>, </em><em>list</em><em>, </em><em>Cmdset</em>) – This allows for adding one or
<codeclass="sig-name descname">remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmd</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.remove"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove a command instance from the cmdset.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>cmd</strong> (<aclass="reference internal"href="evennia.commands.command.html#evennia.commands.command.Command"title="evennia.commands.command.Command"><em>Command</em></a><em> or </em><em>str</em>) – Either the Command object to remove
<codeclass="sig-name descname">get</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">cmd</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.get"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.get"title="Permalink to this definition">¶</a></dt>
<dd><p>Get a command from the cmdset. This is mostly useful to
check if the command is part of this cmdset or not.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>cmd</strong> (<aclass="reference internal"href="evennia.commands.command.html#evennia.commands.command.Command"title="evennia.commands.command.Command"><em>Command</em></a><em> or </em><em>str</em>) – Either the Command object or its key.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>cmd (Command)</em>– The first matching Command in the set.</p>
<codeclass="sig-name descname">count</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.count"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.count"title="Permalink to this definition">¶</a></dt>
<dd><p>Number of commands in set.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>N (int)</em>– Number of commands in this Cmdset.</p>
<codeclass="sig-name descname">get_system_cmds</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.get_system_cmds"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.get_system_cmds"title="Permalink to this definition">¶</a></dt>
<dd><p>Get system commands in cmdset</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>sys_cmds (list)</em>– The system commands in the set.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>As far as the Cmdset is concerned, system commands are any
commands with a key starting with double underscore __.
<codeclass="sig-name descname">make_unique</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">caller</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.make_unique"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.make_unique"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">get_all_cmd_keys_and_aliases</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">caller</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.get_all_cmd_keys_and_aliases"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.get_all_cmd_keys_and_aliases"title="Permalink to this definition">¶</a></dt>
<dt>A list of all command keys and aliases in this cmdset. If <strong>caller</strong></dt><dd><p>was given, this list will only contain commands to which <strong>caller</strong> passed
<codeclass="sig-name descname">at_cmdset_creation</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/commands/cmdset.html#CmdSet.at_cmdset_creation"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.at_cmdset_creation"title="Permalink to this definition">¶</a></dt>
<dd><p>Hook method - this should be overloaded in the inheriting
class, and should take care of populating the cmdset by use of
<codeclass="sig-name descname">path</code><emclass="property"> = 'evennia.commands.cmdset.CmdSet'</em><aclass="headerlink"href="#evennia.commands.cmdset.CmdSet.path"title="Permalink to this definition">¶</a></dt>