1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/docs/html/utils.html
2019-08-25 17:44:47 +02:00

383 lines
No EOL
19 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>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>royalnet.utils &mdash; Royalnet documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/rygdocs.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="royalnet.error" href="error.html" />
<link rel="prev" title="royalnet.network" href="network.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Royalnet
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="audio.html">royalnet.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="bots.html">royalnet.bots</a></li>
<li class="toctree-l1"><a class="reference internal" href="commands.html">royalnet.commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="database.html">royalnet.database</a></li>
<li class="toctree-l1"><a class="reference internal" href="network.html">royalnet.network</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">royalnet.utils</a><ul class="simple">
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="error.html">royalnet.error</a></li>
<li class="toctree-l1"><a class="reference internal" href="web.html">royalnet.web</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Royalnet</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>royalnet.utils</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/utils.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="royalnet-utils">
<h1>royalnet.utils<a class="headerlink" href="#royalnet-utils" title="Permalink to this headline"></a></h1>
<div class="toctree-wrapper compound">
</div>
<span class="target" id="module-royalnet.utils"></span><p>Miscellaneous useful functions and classes.</p>
<dl class="function">
<dt id="royalnet.utils.asyncify">
<em class="property">async </em><code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">asyncify</code><span class="sig-paren">(</span><em class="sig-param">function: Callable</em>, <em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.utils.asyncify" title="Permalink to this definition"></a></dt>
<dd><p>Convert a function into a coroutine.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The coroutine cannot be cancelled, and any attempts to do so will result in unexpected outputs.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.safeformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">safeformat</code><span class="sig-paren">(</span><em class="sig-param">string: str</em>, <em class="sig-param">**words: str</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.safeformat" title="Permalink to this definition"></a></dt>
<dd><p><code class="xref py py-func docutils literal notranslate"><span class="pre">str.format()</span></code> something, but ignore missing keys instead of raising an error.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>string</strong> The base string to be formatted.</p></li>
<li><p><strong>words</strong> The words to format the string with.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The formatted string.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.cdj">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">cdj</code><span class="sig-paren">(</span><em class="sig-param">class_: Any</em><span class="sig-paren">)</span> &#x2192; dict<a class="headerlink" href="#royalnet.utils.cdj" title="Permalink to this definition"></a></dt>
<dd><p>Return a dict of the class attributes without the <code class="docutils literal notranslate"><span class="pre">__module__</span></code>, <code class="docutils literal notranslate"><span class="pre">__dict__</span></code>, <code class="docutils literal notranslate"><span class="pre">__weakref__</span></code> and <code class="docutils literal notranslate"><span class="pre">__doc__</span></code> keys, to be used while generating dynamically SQLAlchemy declarative table classes.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>class_</strong> The object that you want to dict-ify.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The class dict.</p>
</dd>
</dl>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>You cant dict-ify classes with <code class="docutils literal notranslate"><span class="pre">__slots__</span></code>!</p>
</div>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.sleep_until">
<em class="property">async </em><code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">sleep_until</code><span class="sig-paren">(</span><em class="sig-param">dt: datetime.datetime</em><span class="sig-paren">)</span> &#x2192; None<a class="headerlink" href="#royalnet.utils.sleep_until" title="Permalink to this definition"></a></dt>
<dd><p>Block the call until the specified datetime.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Accurate only to seconds.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.plusformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">plusformat</code><span class="sig-paren">(</span><em class="sig-param">i: int</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.plusformat" title="Permalink to this definition"></a></dt>
<dd><p>Convert an <a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> to a <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, prepending a <code class="docutils literal notranslate"><span class="pre">+</span></code> if its greater than 0.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i</strong> the <a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> to convert.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The resulting <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p>
</dd>
</dl>
</dd></dl>
<dl class="class">
<dt id="royalnet.utils.NetworkHandler">
<em class="property">class </em><code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">NetworkHandler</code><a class="headerlink" href="#royalnet.utils.NetworkHandler" title="Permalink to this definition"></a></dt>
<dd><p>The NetworkHandler functions are called when a specific Message type is received.</p>
<dl class="attribute">
<dt id="royalnet.utils.NetworkHandler.message_type">
<code class="sig-name descname">message_type</code><em class="property"> = NotImplemented</em><a class="headerlink" href="#royalnet.utils.NetworkHandler.message_type" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.andformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">andformat</code><span class="sig-paren">(</span><em class="sig-param">l: List[str], middle=', ', final=' and '</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.andformat" title="Permalink to this definition"></a></dt>
<dd><p>Convert a <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> to a <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> by adding <code class="docutils literal notranslate"><span class="pre">final</span></code> between the last two elements and <code class="docutils literal notranslate"><span class="pre">middle</span></code> between the others.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>l</strong> the input <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#list" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>.</p></li>
<li><p><strong>middle</strong> the <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> to be added between the middle elements.</p></li>
<li><p><strong>final</strong> the <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> to be added between the last two elements.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The resulting <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt>
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">plusformat</code><span class="sig-paren">(</span><em class="sig-param">i: int</em><span class="sig-paren">)</span> &#x2192; str</dt>
<dd><p>Convert an <a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> to a <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, prepending a <code class="docutils literal notranslate"><span class="pre">+</span></code> if its greater than 0.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>i</strong> the <a class="reference external" href="https://docs.python.org/3.7/library/functions.html#int" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> to convert.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The resulting <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#str" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.fileformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">fileformat</code><span class="sig-paren">(</span><em class="sig-param">string: str</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.fileformat" title="Permalink to this definition"></a></dt>
<dd><p>Ensure a string can be used as a filename by replacing all non-word characters with underscores.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>string</strong> the input string.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A valid filename string.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.ytdldateformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">ytdldateformat</code><span class="sig-paren">(</span><em class="sig-param">string: Optional[str], separator: str = '-'</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.ytdldateformat" title="Permalink to this definition"></a></dt>
<dd><p>Convert the weird date string returned by <code class="docutils literal notranslate"><span class="pre">youtube-dl</span></code> into the <code class="docutils literal notranslate"><span class="pre">YYYY-MM-DD</span></code> format.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>string</strong> the input string, in the <code class="docutils literal notranslate"><span class="pre">YYYYMMDD</span></code> format.</p></li>
<li><p><strong>separator</strong> the string to add between the years, the months and the days. Defaults to <code class="docutils literal notranslate"><span class="pre">-</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The resulting string, in the format <code class="docutils literal notranslate"><span class="pre">YYYY-MM-DD</span></code> format.</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.numberemojiformat">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">numberemojiformat</code><span class="sig-paren">(</span><em class="sig-param">l: List[str]</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.numberemojiformat" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="royalnet.utils.telegram_escape">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">telegram_escape</code><span class="sig-paren">(</span><em class="sig-param">string: str</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.telegram_escape" title="Permalink to this definition"></a></dt>
<dd><p>Escape a string to be sent through Telegram, and format it using RoyalCode.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Currently escapes everything, even items in code blocks.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="royalnet.utils.discord_escape">
<code class="sig-prename descclassname">royalnet.utils.</code><code class="sig-name descname">discord_escape</code><span class="sig-paren">(</span><em class="sig-param">string: str</em><span class="sig-paren">)</span> &#x2192; str<a class="headerlink" href="#royalnet.utils.discord_escape" title="Permalink to this definition"></a></dt>
<dd><p>Escape a string to be sent through Discord, and format it using RoyalCode.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Currently escapes everything, even items in code blocks.</p>
</div>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="error.html" class="btn btn-neutral float-right" title="royalnet.error" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="network.html" class="btn btn-neutral float-left" title="royalnet.network" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2019, Stefano Pigozzi
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>