1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/docs/html/bots.html
2019-06-06 14:27:45 +02:00

401 lines
No EOL
23 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.bots &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="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="royalnet.commands" href="commands.html" />
<link rel="prev" title="royalnet.audio" href="audio.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 current"><a class="current reference internal" href="#">royalnet.bots</a><ul class="simple">
</ul>
</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"><a class="reference internal" href="utils.html">royalnet.utils</a></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.bots</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/bots.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-bots">
<h1>royalnet.bots<a class="headerlink" href="#royalnet-bots" title="Permalink to this headline"></a></h1>
<div class="toctree-wrapper compound">
</div>
<span class="target" id="module-royalnet.bots"></span><p>Various bot interfaces, and a generic class to create new ones.</p>
<dl class="class">
<dt id="royalnet.bots.TelegramBot">
<em class="property">class </em><code class="descclassname">royalnet.bots.</code><code class="descname">TelegramBot</code><span class="sig-paren">(</span><em>*</em>, <em>telegram_config: royalnet.bots.telegram.TelegramConfig</em>, <em>royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None</em>, <em>database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None</em>, <em>command_prefix: str = '/'</em>, <em>commands: List[Type[royalnet.utils.command.Command]] = None</em>, <em>missing_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em>, <em>error_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.TelegramBot" title="Permalink to this definition"></a></dt>
<dd><p>A bot that connects to <a class="reference external" href="https://telegram.org/">Telegram</a>.</p>
<dl class="method">
<dt id="royalnet.bots.TelegramBot._call_factory">
<code class="descname">_call_factory</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; Type[royalnet.utils.call.Call]<a class="headerlink" href="#royalnet.bots.TelegramBot._call_factory" title="Permalink to this definition"></a></dt>
<dd><p>Create the TelegramCall class, representing a command call. It should inherit from <a class="reference internal" href="utils.html#royalnet.utils.Call" title="royalnet.utils.Call"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.utils.Call</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The created TelegramCall class.</p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.TelegramBot._handle_update">
<code class="descname">_handle_update</code><span class="sig-paren">(</span><em>update: telegram.update.Update</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.TelegramBot._handle_update" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="royalnet.bots.TelegramBot._init_client">
<code class="descname">_init_client</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.TelegramBot._init_client" title="Permalink to this definition"></a></dt>
<dd><p>Create the <a class="reference external" href="https://python-telegram-bot.readthedocs.io/en/stable/telegram.bot.html#telegram.Bot" title="(in Python Telegram Bot v11.1)"><code class="xref py py-class docutils literal notranslate"><span class="pre">telegram.Bot</span></code></a>, and set the starting offset.</p>
</dd></dl>
<dl class="attribute">
<dt id="royalnet.bots.TelegramBot.botfather_command_string">
<code class="descname">botfather_command_string</code><a class="headerlink" href="#royalnet.bots.TelegramBot.botfather_command_string" title="Permalink to this definition"></a></dt>
<dd><p>Generate a string to be pasted in the “Edit Commands” BotFather prompt.</p>
</dd></dl>
<dl class="attribute">
<dt id="royalnet.bots.TelegramBot.interface_name">
<code class="descname">interface_name</code><em class="property"> = 'telegram'</em><a class="headerlink" href="#royalnet.bots.TelegramBot.interface_name" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="royalnet.bots.TelegramBot.run">
<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.TelegramBot.run" title="Permalink to this definition"></a></dt>
<dd><p>A blocking coroutine that should make the bot start listening to commands and requests.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="royalnet.bots.TelegramConfig">
<em class="property">class </em><code class="descclassname">royalnet.bots.</code><code class="descname">TelegramConfig</code><span class="sig-paren">(</span><em>token: str</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.TelegramConfig" title="Permalink to this definition"></a></dt>
<dd><p>The specific configuration to be used for <code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.database.TelegramBot</span></code>.</p>
</dd></dl>
<dl class="class">
<dt id="royalnet.bots.DiscordBot">
<em class="property">class </em><code class="descclassname">royalnet.bots.</code><code class="descname">DiscordBot</code><span class="sig-paren">(</span><em>*</em>, <em>discord_config: royalnet.bots.discord.DiscordConfig</em>, <em>royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None</em>, <em>database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None</em>, <em>command_prefix: str = '!'</em>, <em>commands: List[Type[royalnet.utils.command.Command]] = None</em>, <em>missing_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em>, <em>error_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot" title="Permalink to this definition"></a></dt>
<dd><p>A bot that connects to <a class="reference external" href="https://discordapp.com/">Discord</a>.</p>
<dl class="method">
<dt id="royalnet.bots.DiscordBot._bot_factory">
<code class="descname">_bot_factory</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; Type[discord.client.Client]<a class="headerlink" href="#royalnet.bots.DiscordBot._bot_factory" title="Permalink to this definition"></a></dt>
<dd><p>Create a custom DiscordClient class inheriting from <a class="reference external" href="https://discordpy.readthedocs.io/en/latest/api.html#discord.Client" title="(in discord.py v1.2.0a)"><code class="xref py py-class docutils literal notranslate"><span class="pre">discord.Client</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot._call_factory">
<code class="descname">_call_factory</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; Type[royalnet.utils.call.Call]<a class="headerlink" href="#royalnet.bots.DiscordBot._call_factory" title="Permalink to this definition"></a></dt>
<dd><p>Create the TelegramCall class, representing a command call. It should inherit from <a class="reference internal" href="utils.html#royalnet.utils.Call" title="royalnet.utils.Call"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.utils.Call</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The created TelegramCall class.</p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot._init_client">
<code class="descname">_init_client</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot._init_client" title="Permalink to this definition"></a></dt>
<dd><p>Create an instance of the DiscordClient class created in <a class="reference internal" href="#royalnet.bots.DiscordBot._bot_factory" title="royalnet.bots.DiscordBot._bot_factory"><code class="xref py py-func docutils literal notranslate"><span class="pre">royalnet.bots.DiscordBot._bot_factory()</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot._init_voice">
<code class="descname">_init_voice</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot._init_voice" title="Permalink to this definition"></a></dt>
<dd><p>Initialize the variables needed for the connection to voice chat.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot.add_to_music_data">
<code class="descname">add_to_music_data</code><span class="sig-paren">(</span><em>audio_sources: List[royalnet.audio.royalpcmaudio.RoyalPCMAudio], guild: discord.guild.Guild</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot.add_to_music_data" title="Permalink to this definition"></a></dt>
<dd><p>Add a file to the corresponding music_data object.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot.advance_music_data">
<code class="descname">advance_music_data</code><span class="sig-paren">(</span><em>guild: discord.guild.Guild</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot.advance_music_data" title="Permalink to this definition"></a></dt>
<dd><p>Try to play the next song, while it exists. Otherwise, just return.</p>
</dd></dl>
<dl class="attribute">
<dt id="royalnet.bots.DiscordBot.interface_name">
<code class="descname">interface_name</code><em class="property"> = 'discord'</em><a class="headerlink" href="#royalnet.bots.DiscordBot.interface_name" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot.run">
<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot.run" title="Permalink to this definition"></a></dt>
<dd><p>Login to Discord, then run the bot.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.DiscordBot.update_activity_with_source_title">
<code class="descname">update_activity_with_source_title</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordBot.update_activity_with_source_title" title="Permalink to this definition"></a></dt>
<dd><p>Change the bots presence (using <code class="xref py py-func docutils literal notranslate"><span class="pre">discord.Client.change_presence()</span></code>) to match the current listening status.</p>
<p>If multiple guilds are using the bot, the bot will always have an empty presence.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="royalnet.bots.DiscordConfig">
<em class="property">class </em><code class="descclassname">royalnet.bots.</code><code class="descname">DiscordConfig</code><span class="sig-paren">(</span><em>token: str</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.DiscordConfig" title="Permalink to this definition"></a></dt>
<dd><p>The specific configuration to be used for <a class="reference internal" href="#royalnet.bots.DiscordBot" title="royalnet.bots.DiscordBot"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.bots.DiscordBot</span></code></a>.</p>
</dd></dl>
<dl class="class">
<dt id="royalnet.bots.GenericBot">
<em class="property">class </em><code class="descclassname">royalnet.bots.</code><code class="descname">GenericBot</code><span class="sig-paren">(</span><em>*</em>, <em>royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None</em>, <em>database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None</em>, <em>command_prefix: str</em>, <em>commands: List[Type[royalnet.utils.command.Command]] = None</em>, <em>missing_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em>, <em>error_command: Type[royalnet.utils.command.Command] = &lt;class 'royalnet.commands.null.NullCommand'&gt;</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.GenericBot" title="Permalink to this definition"></a></dt>
<dd><p>A generic bot class, to be used as base for the other more specific classes, such as <span class="xref std std-ref">royalnet.bots.TelegramBot</span> and <span class="xref std std-ref">royalnet.bots.DiscordBot</span>.</p>
<dl class="method">
<dt id="royalnet.bots.GenericBot._call_factory">
<code class="descname">_call_factory</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; Type[royalnet.utils.call.Call]<a class="headerlink" href="#royalnet.bots.GenericBot._call_factory" title="Permalink to this definition"></a></dt>
<dd><p>Create the TelegramCall class, representing a command call. It should inherit from <a class="reference internal" href="utils.html#royalnet.utils.Call" title="royalnet.utils.Call"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.utils.Call</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The created TelegramCall class.</p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot._init_commands">
<code class="descname">_init_commands</code><span class="sig-paren">(</span><em>command_prefix: str, commands: List[Type[royalnet.utils.command.Command]], missing_command: Type[royalnet.utils.command.Command], error_command: Type[royalnet.utils.command.Command]</em><span class="sig-paren">)</span> &#x2192; None<a class="headerlink" href="#royalnet.bots.GenericBot._init_commands" title="Permalink to this definition"></a></dt>
<dd><p>Generate the <code class="docutils literal notranslate"><span class="pre">commands</span></code> dictionary required to handle incoming messages, and the <code class="docutils literal notranslate"><span class="pre">network_handlers</span></code> dictionary required to handle incoming requests.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot._init_database">
<code class="descname">_init_database</code><span class="sig-paren">(</span><em>commands: List[Type[royalnet.utils.command.Command]], database_config: royalnet.database.databaseconfig.DatabaseConfig</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.GenericBot._init_database" title="Permalink to this definition"></a></dt>
<dd><p>Create an <a class="reference internal" href="database.html#royalnet.database.Alchemy" title="royalnet.database.Alchemy"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.database.Alchemy</span></code></a> with the tables required by the commands. Then, find the chain that links the <code class="docutils literal notranslate"><span class="pre">master_table</span></code> to the <code class="docutils literal notranslate"><span class="pre">identity_table</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot._init_royalnet">
<code class="descname">_init_royalnet</code><span class="sig-paren">(</span><em>royalnet_config: royalnet.network.royalnetconfig.RoyalnetConfig</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.GenericBot._init_royalnet" title="Permalink to this definition"></a></dt>
<dd><p>Create a <a class="reference internal" href="network.html#royalnet.network.RoyalnetLink" title="royalnet.network.RoyalnetLink"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.network.RoyalnetLink</span></code></a>, and run it as a <a class="reference external" href="https://docs.python.org/3.7/library/asyncio-task.html#asyncio.Task" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot._network_handler">
<code class="descname">_network_handler</code><span class="sig-paren">(</span><em>request_dict: dict</em><span class="sig-paren">)</span> &#x2192; dict<a class="headerlink" href="#royalnet.bots.GenericBot._network_handler" title="Permalink to this definition"></a></dt>
<dd><p>Handle a single <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a> received from the <a class="reference internal" href="network.html#royalnet.network.RoyalnetLink" title="royalnet.network.RoyalnetLink"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.network.RoyalnetLink</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Another <a class="reference external" href="https://docs.python.org/3.7/library/stdtypes.html#dict" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, formatted as a <a class="reference internal" href="network.html#royalnet.network.Response" title="royalnet.network.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">royalnet.network.Response</span></code></a>.</p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot.call">
<code class="descname">call</code><span class="sig-paren">(</span><em>command_name: str</em>, <em>channel</em>, <em>parameters: List[str] = None</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.GenericBot.call" title="Permalink to this definition"></a></dt>
<dd><p>Call the command with the specified name.</p>
<p>If it doesnt exist, call <code class="docutils literal notranslate"><span class="pre">self.missing_command</span></code>.</p>
<p>If an exception is raised during the execution of the command, call <code class="docutils literal notranslate"><span class="pre">self.error_command</span></code>.</p>
</dd></dl>
<dl class="attribute">
<dt id="royalnet.bots.GenericBot.interface_name">
<code class="descname">interface_name</code><em class="property"> = NotImplemented</em><a class="headerlink" href="#royalnet.bots.GenericBot.interface_name" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="method">
<dt id="royalnet.bots.GenericBot.run">
<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#royalnet.bots.GenericBot.run" title="Permalink to this definition"></a></dt>
<dd><p>A blocking coroutine that should make the bot start listening to commands and requests.</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="commands.html" class="btn btn-neutral float-right" title="royalnet.commands" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="audio.html" class="btn btn-neutral float-left" title="royalnet.audio" 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>