<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
<spanid="evennia-scripts-monitorhandler"></span><h1>evennia.scripts.monitorhandler<aclass="headerlink"href="#module-evennia.scripts.monitorhandler"title="Permalink to this headline">¶</a></h1>
<p>Monitors - catch changes to model fields and Attributes.</p>
<p>The MONITOR_HANDLER singleton from this module offers the following
functionality:</p>
<ulclass="simple">
<li><dlclass="simple">
<dt>Field-monitor - track a object’s specific database field and perform</dt><dd><p>an action whenever that field <em>changes</em> for whatever reason.</p>
</dd>
</dl>
</li>
<li><dlclass="simple">
<dt>Attribute-monitor tracks an object’s specific Attribute and perform</dt><dd><p>an action whenever that Attribute <em>changes</em> for whatever reason.</p>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.scripts.monitorhandler.</code><codeclass="sig-name descname">MonitorHandler</code><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.__init__"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">save</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.save"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.save"title="Permalink to this definition">¶</a></dt>
<dd><p>Store our monitors to the database. This is called
by the server process.</p>
<p>Since dbserialize can’t handle defaultdicts, we convert to an
intermediary save format ((obj,fieldname, idstring, callback, kwargs), …)</p>
<codeclass="sig-name descname">restore</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">server_reload</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.restore"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.restore"title="Permalink to this definition">¶</a></dt>
<dd><p>Restore our monitors after a reload. This is called
by the server process.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>server_reload</strong> (<em>bool</em><em>, </em><em>optional</em>) – If this is False, it means
<codeclass="sig-name descname">at_update</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">fieldname</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.at_update"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.at_update"title="Permalink to this definition">¶</a></dt>
<dd><p>Called by the field/attribute as it saves.</p>
<codeclass="sig-name descname">add</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">fieldname</span></em>, <emclass="sig-param"><spanclass="n">callback</span></em>, <emclass="sig-param"><spanclass="n">idstring</span><spanclass="o">=</span><spanclass="default_value">''</span></em>, <emclass="sig-param"><spanclass="n">persistent</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.add"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.add"title="Permalink to this definition">¶</a></dt>
<dd><p>Add monitoring to a given field or Attribute. A field must
be specified with the full db_* name or it will be assumed
to be an Attribute (so <strong>db_key</strong>, not just <strong>key</strong>).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>Typeclassed Entity</em>) – The entity on which to monitor a
field or Attribute.</p></li>
<li><p><strong>fieldname</strong> (<em>str</em>) – Name of field (db_*) or Attribute to monitor.</p></li>
<li><p><strong>callback</strong> (<em>callable</em>) – A callable on the form <ahref="#id1"><spanclass="problematic"id="id2">**</span></a>callable(<ahref="#id3"><spanclass="problematic"id="id4">**</span></a>kwargs),
where kwargs holds keys fieldname and obj.</p></li>
<li><p><strong>idstring</strong> (<em>str</em><em>, </em><em>optional</em>) – An id to separate this monitor from other monitors
of the same field and object.</p></li>
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – If False, the monitor will survive
a server reload but not a cold restart. This is default.</p></li>
<li><p><strong>category</strong> (<em>str</em><em>, </em><em>optional</em>) – This is only used if <strong>fieldname</strong> refers to
an Attribute (i.e. it does not start with <strong>db_</strong>). You must specify this
if you want to target an Attribute with a category.</p></li>
</ul>
</dd>
<dtclass="field-even">Keyword Arguments</dt>
<ddclass="field-even"><ulclass="simple">
<li><p><strong>session</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a>) – If this keyword is given, the monitorhandler will
correctly analyze it and remove the monitor if after a reload/reboot
the session is no longer valid.</p></li>
<li><p><strong>any</strong> (<em>any</em>) – Any other kwargs are passed on to the callback. Remember that
<codeclass="sig-name descname">remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">fieldname</span></em>, <emclass="sig-param"><spanclass="n">idstring</span><spanclass="o">=</span><spanclass="default_value">''</span></em>, <emclass="sig-param"><spanclass="n">category</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.remove"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">clear</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.clear"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.clear"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">all</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/scripts/monitorhandler.html#MonitorHandler.all"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.scripts.monitorhandler.MonitorHandler.all"title="Permalink to this definition">¶</a></dt>
<dd><p>List all monitors or all monitors of a given object.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>obj</strong> (<em>Object</em>) – The object on which to list all monitors.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>monitors (list)</em>– The handled monitors.</p>
<pclass="last">You are reading an old version of the Evennia documentation. <ahref="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
</div>
<divclass="footer"role="contentinfo">
© Copyright 2023, The Evennia developer community.
Created using <ahref="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.