evennia/docs/0.x/api/evennia.commands.cmdhandler.html
2023-12-20 19:10:09 +01:00

211 lines
No EOL
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>evennia.commands.cmdhandler &#8212; Evennia 0.9.5 documentation</title>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "tex2jax_process|mathjax_process|math|output_area"}})</script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdhandler</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-evennia.commands.cmdhandler">
<span id="evennia-commands-cmdhandler"></span><h1>evennia.commands.cmdhandler<a class="headerlink" href="#module-evennia.commands.cmdhandler" title="Permalink to this headline"></a></h1>
<p>Command handler</p>
<p>This module contains the infrastructure for accepting commands on the
command line. The processing of a command works as follows:</p>
<ol class="arabic">
<li><p>The calling object (caller) is analyzed based on its callertype.</p></li>
<li><p>Cmdsets are gathered from different sources:
- channels: all available channel names are auto-created into a cmdset, to allow</p>
<blockquote>
<div><p>for giving the channel name and have the following immediately
sent to the channel. The sending is performed by the CMD_CHANNEL
system command.</p>
</div></blockquote>
<ul class="simple">
<li><p>object cmdsets: all objects at callers location are scanned for non-empty
cmdsets. This includes cmdsets on exits.</p></li>
<li><p>caller: the caller is searched for its own currently active cmdset.</p></li>
<li><p>account: lastly the cmdsets defined on caller.account are added.</p></li>
</ul>
</li>
<li><p>The collected cmdsets are merged together to a combined, current cmdset.</p></li>
<li><p>If the input string is empty -&gt; check for CMD_NOINPUT command in
current cmdset or fallback to error message. Exit.</p></li>
<li><p>The Command Parser is triggered, using the current cmdset to analyze the
input string for possible command matches.</p></li>
<li><p>If multiple matches are found -&gt; check for CMD_MULTIMATCH in current
cmdset, or fallback to error message. Exit.</p></li>
<li><p>If no match was found -&gt; check for CMD_NOMATCH in current cmdset or
fallback to error message. Exit.</p></li>
<li><p>A single match was found. If this is a channel-command (i.e. the
ommand name is that of a channel), &gt; check for CMD_CHANNEL in
current cmdset or use channelhandler default. Exit.</p></li>
<li><p>At this point we have found a normal command. We assign useful variables to it that
will be available to the command coder at run-time.</p></li>
</ol>
<ol class="arabic simple" start="12">
<li><p>We have a unique cmdobject, primed for use. Call all hooks:</p></li>
</ol>
<blockquote>
<div><p><strong>at_pre_cmd()</strong>, <strong>cmdobj.parse()</strong>, <strong>cmdobj.func()</strong> and finally <strong>at_post_cmd()</strong>.</p>
</div></blockquote>
<ol class="arabic simple" start="13">
<li><p>Return deferred that will fire with the return from <strong>cmdobj.func()</strong> (unused by default).</p></li>
</ol>
<dl class="py function">
<dt id="evennia.commands.cmdhandler.cmdhandler">
<code class="sig-prename descclassname">evennia.commands.cmdhandler.</code><code class="sig-name descname">cmdhandler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">called_by</span></em>, <em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="n">_testing</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">callertype</span><span class="o">=</span><span class="default_value">'session'</span></em>, <em class="sig-param"><span class="n">session</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cmdobj</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cmdobj_key</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdhandler.html#cmdhandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdhandler.cmdhandler" title="Permalink to this definition"></a></dt>
<dd><p>This is the main mechanism that handles any string sent to the engine.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>called_by</strong> (<a class="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> or </em><em>Object</em>) Object from which this
command was called. which this was called from. What this is
depends on the game state.</p></li>
<li><p><strong>raw_string</strong> (<em>str</em>) The command string as given on the command line.</p></li>
<li><p><strong>_testing</strong> (<em>bool</em><em>, </em><em>optional</em>) Used for debug purposes and decides if we
should actually execute the command or not. If True, the
command instance will be returned.</p></li>
<li><p><strong>callertype</strong> (<em>str</em><em>, </em><em>optional</em>) One of “session”, “account” or
“object”. These are treated in decending order, so when the
Session is the caller, it will merge its own cmdset into
cmdsets from both Account and eventual puppeted Object (and
cmdsets in its room etc). An Account will only include its own
cmdset and the Objects and so on. Merge order is the same
order, so that Object cmdsets are merged in last, giving them
precendence for same-name and same-prio commands.</p></li>
<li><p><strong>session</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) Relevant if callertype is “account” - the session will help
retrieve the correct cmdsets from puppeted objects.</p></li>
<li><p><strong>cmdobj</strong> (<a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><em>Command</em></a><em>, </em><em>optional</em>) If given a command instance, this will be executed using
<strong>called_by</strong> as the caller, <strong>raw_string</strong> representing its arguments and (optionally)
<strong>cmdobj_key</strong> as its input command name. No cmdset lookup will be performed but
all other options apply as normal. This allows for running a specific Command
within the command system mechanism.</p></li>
<li><p><strong>cmdobj_key</strong> (<em>string</em><em>, </em><em>optional</em>) Used together with <strong>cmdobj</strong> keyword to specify
which cmdname should be assigned when calling the specified Command instance. This
is made available as <strong>self.cmdstring</strong> when the Command runs.
If not given, the command will be assumed to be called as <strong>cmdobj.key</strong>.</p></li>
</ul>
</dd>
<dt class="field-even">Keyword Arguments</dt>
<dd class="field-even"><p><strong>kwargs</strong> (<em>any</em>) other keyword arguments will be assigned as named variables on the
retrieved command object <em>before</em> it is executed. This is unused
in default Evennia but may be used by code to set custom flags or
special operating conditions for a command as it executes.</p>
</dd>
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p><em>deferred (Deferred)</em> This deferred is fired with the return
value of the commands <strong>func</strong> method. This is not used in
default Evennia.</p>
</dd>
</dl>
</dd></dl>
<dl class="py exception">
<dt id="evennia.commands.cmdhandler.InterruptCommand">
<em class="property">exception </em><code class="sig-prename descclassname">evennia.commands.cmdhandler.</code><code class="sig-name descname">InterruptCommand</code><a class="reference internal" href="../_modules/evennia/commands/command.html#InterruptCommand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdhandler.InterruptCommand" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
<p>Cleanly interrupt a command.</p>
</dd></dl>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
</a></p>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
<div role="note" aria-label="source link">
<!--h3>This Page</h3-->
<ul class="this-page-menu">
<li><a href="../_sources/api/evennia.commands.cmdhandler.md.txt"
rel="nofollow">Show Page Source</a></li>
</ul>
</div><h3>Links</h3>
<ul>
<li><a href="https://www.evennia.com">Home page</a> </li>
<li><a href="https://github.com/evennia/evennia">Evennia Github</a> </li>
<li><a href="http://games.evennia.com">Game Index</a> </li>
<li><a href="http://webchat.freenode.net/?channels=evennia&uio=MT1mYWxzZSY5PXRydWUmMTE9MTk1JjEyPXRydWUbb">IRC</a> -
<a href="https://discord.gg/NecFePw">Discord</a> -
<a href="https://groups.google.com/forum/#%21forum/evennia">Forums</a>
</li>
<li><a href="http://evennia.blogspot.com/">Evennia Dev blog</a> </li>
</ul>
<h3>Versions</h3>
<ul>
<li><a href="../../1.0-dev/api/evennia.commands.cmdhandler.html">1.0-dev (develop branch)</a></li>
<li><a href="evennia.commands.cmdhandler.html">0.9.5 (v0.9.5 branch)</a></li>
</ul>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 0.9.5</a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdhandler</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2020, The Evennia developer community.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
</div>
</body>
</html>