diff --git a/docs/doctrees/apireference.doctree b/docs/doctrees/apireference.doctree new file mode 100644 index 00000000..add902de Binary files /dev/null and b/docs/doctrees/apireference.doctree differ diff --git a/docs/doctrees/audio.doctree b/docs/doctrees/audio.doctree deleted file mode 100644 index 94fa5b28..00000000 Binary files a/docs/doctrees/audio.doctree and /dev/null differ diff --git a/docs/doctrees/bots.doctree b/docs/doctrees/bots.doctree deleted file mode 100644 index e38b078e..00000000 Binary files a/docs/doctrees/bots.doctree and /dev/null differ diff --git a/docs/doctrees/commands.doctree b/docs/doctrees/commands.doctree deleted file mode 100644 index 2d86f9b6..00000000 Binary files a/docs/doctrees/commands.doctree and /dev/null differ diff --git a/docs/doctrees/creatingacommand.doctree b/docs/doctrees/creatingacommand.doctree new file mode 100644 index 00000000..bdc5f93c Binary files /dev/null and b/docs/doctrees/creatingacommand.doctree differ diff --git a/docs/doctrees/database.doctree b/docs/doctrees/database.doctree deleted file mode 100644 index 02f9c1e9..00000000 Binary files a/docs/doctrees/database.doctree and /dev/null differ diff --git a/docs/doctrees/environment.pickle b/docs/doctrees/environment.pickle index 0ab02885..f695f38c 100644 Binary files a/docs/doctrees/environment.pickle and b/docs/doctrees/environment.pickle differ diff --git a/docs/doctrees/error.doctree b/docs/doctrees/error.doctree deleted file mode 100644 index c0e1c833..00000000 Binary files a/docs/doctrees/error.doctree and /dev/null differ diff --git a/docs/doctrees/index.doctree b/docs/doctrees/index.doctree index d7ff3768..537d5ccb 100644 Binary files a/docs/doctrees/index.doctree and b/docs/doctrees/index.doctree differ diff --git a/docs/doctrees/network.doctree b/docs/doctrees/network.doctree deleted file mode 100644 index d544ba0b..00000000 Binary files a/docs/doctrees/network.doctree and /dev/null differ diff --git a/docs/doctrees/utils.doctree b/docs/doctrees/utils.doctree deleted file mode 100644 index ac7d0719..00000000 Binary files a/docs/doctrees/utils.doctree and /dev/null differ diff --git a/docs/doctrees/web.doctree b/docs/doctrees/web.doctree deleted file mode 100644 index 504b7ce8..00000000 Binary files a/docs/doctrees/web.doctree and /dev/null differ diff --git a/docs/html/_sources/apireference.rst.txt b/docs/html/_sources/apireference.rst.txt new file mode 100644 index 00000000..78f973f2 --- /dev/null +++ b/docs/html/_sources/apireference.rst.txt @@ -0,0 +1,70 @@ +API Reference +==================================== + +These pages were automatically generated from docstrings in code. + +They might be outdated, or incomplete. + +Audio +------------------------------------ + +.. automodule:: royalnet.audio + :members: + :undoc-members: + :private-members: + +Bots +------------------------------------ + +.. automodule:: royalnet.bots + :members: + :undoc-members: + :private-members: + +Commands +------------------------------------ + +.. automodule:: royalnet.commands + :members: + :undoc-members: + :private-members: + +Database +------------------------------------ + +.. automodule:: royalnet.database + :members: + :undoc-members: + :private-members: + +Network +------------------------------------ + +.. automodule:: royalnet.network + :members: + :undoc-members: + :private-members: + +Utils +------------------------------------ + +.. automodule:: royalnet.utils + :members: + :undoc-members: + :private-members: + +Web +------------------------------------ + +.. automodule:: royalnet.web + :members: + :undoc-members: + :private-members: + +Error +------------------------------------ + +.. automodule:: royalnet.error + :members: + :undoc-members: + :private-members: diff --git a/docs/html/_sources/audio.rst.txt b/docs/html/_sources/audio.rst.txt deleted file mode 100644 index 1b163fe9..00000000 --- a/docs/html/_sources/audio.rst.txt +++ /dev/null @@ -1,12 +0,0 @@ -royalnet.audio -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.audio - :members: - :private-members: - :undoc-members: - diff --git a/docs/html/_sources/bots.rst.txt b/docs/html/_sources/bots.rst.txt deleted file mode 100644 index 42f1173b..00000000 --- a/docs/html/_sources/bots.rst.txt +++ /dev/null @@ -1,11 +0,0 @@ -royalnet.bots -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.bots - :members: - :private-members: - :undoc-members: diff --git a/docs/html/_sources/commands.rst.txt b/docs/html/_sources/commands.rst.txt deleted file mode 100644 index 9f8befe2..00000000 --- a/docs/html/_sources/commands.rst.txt +++ /dev/null @@ -1,11 +0,0 @@ -royalnet.commands -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.commands - :members: - :private-members: - :special-members: diff --git a/docs/html/_sources/creatingacommand.rst.txt b/docs/html/_sources/creatingacommand.rst.txt new file mode 100644 index 00000000..341e2437 --- /dev/null +++ b/docs/html/_sources/creatingacommand.rst.txt @@ -0,0 +1,66 @@ +.. currentmodule:: royalnet.commands + +Royalnet Commands +==================================== + +A Royalnet Command is a small script that is run whenever a specific message is sent to a Royalnet interface. + +A Command code looks like this: :: + + from royalnet.commands import Command + + class PingCommand(Command): + name = "ping" + + description = "Play ping-pong with the bot." + + def __init__(self, interface): + # This code is run just once, while the bot is starting + super().__init__() + + async def run(self, args, data): + # This code is run every time the command is called + await data.reply("Pong!") + + +Creating a new Command +------------------------------------ + +First, think of a ``name`` for your command. +It's the name your command will be called with: for example, the "spaghetti" command will be called by typing **/spaghetti** in chat. +Try to keep the name as short as possible, while staying specific enough so no other command will have the same name. + +Next, create a new Python file with the ``name`` you have thought of. +The previously mentioned "spaghetti" command should have a file called ``spaghetti.py``. + +Then, in the first row of the file, import the :py:class:`Command` class from :py:mod:`royalnet`, and create a new class inheriting from it: :: + + from royalnet.commands import Command + + class SpaghettiCommand(Command): + ... + +Inside the class, override the attributes ``name`` and ``description`` with respectively the **name of the command** and a **small description of what the command will do**: :: + + from royalnet.commands import Command + + class SpaghettiCommand(Command): + name = "spaghetti" + + description = "Send a spaghetti emoji in the chat." + +Now override the :py:meth:`Command.run` method, adding the code you want the bot to run when the command is called. + +To send a message in the chat the command was called in, you can use the :py:meth:`CommandData.reply` method: :: + + from royalnet.commands import Command + + class SpaghettiCommand(Command): + name = "spaghetti" + + description = "Send a spaghetti emoji in the chat." + + async def run(self, args, data): + data.reply("🍝") + +And it's done! The command is now ready to be used in a bot! diff --git a/docs/html/_sources/database.rst.txt b/docs/html/_sources/database.rst.txt deleted file mode 100644 index 64293c67..00000000 --- a/docs/html/_sources/database.rst.txt +++ /dev/null @@ -1,20 +0,0 @@ -royalnet.database -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.database - :members: - :private-members: - :undoc-members: - - -Tables ------------------------------------- - -.. automodule:: royalnet.database.tables - :members: - :private-members: - :undoc-members: diff --git a/docs/html/_sources/error.rst.txt b/docs/html/_sources/error.rst.txt deleted file mode 100644 index 044a1511..00000000 --- a/docs/html/_sources/error.rst.txt +++ /dev/null @@ -1,11 +0,0 @@ -royalnet.error -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.error - :members: - :private-members: - :undoc-members: diff --git a/docs/html/_sources/index.rst.txt b/docs/html/_sources/index.rst.txt index 5e7c7391..38a3a7d3 100644 --- a/docs/html/_sources/index.rst.txt +++ b/docs/html/_sources/index.rst.txt @@ -1,17 +1,13 @@ royalnet ==================================== +Welcome to the documentation of Royalnet! + .. toctree:: :maxdepth: 2 - audio - bots - commands - database - network - utils - error - web + creatingacommand + apireference Some useful links diff --git a/docs/html/_sources/network.rst.txt b/docs/html/_sources/network.rst.txt deleted file mode 100644 index 5c07dbbe..00000000 --- a/docs/html/_sources/network.rst.txt +++ /dev/null @@ -1,12 +0,0 @@ -royalnet.network -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.network - :members: - :private-members: - :undoc-members: - diff --git a/docs/html/_sources/utils.rst.txt b/docs/html/_sources/utils.rst.txt deleted file mode 100644 index 1deb9cbc..00000000 --- a/docs/html/_sources/utils.rst.txt +++ /dev/null @@ -1,12 +0,0 @@ -royalnet.utils -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.utils - :members: - :private-members: - :undoc-members: - diff --git a/docs/html/_sources/web.rst.txt b/docs/html/_sources/web.rst.txt deleted file mode 100644 index cabaf108..00000000 --- a/docs/html/_sources/web.rst.txt +++ /dev/null @@ -1,20 +0,0 @@ -royalnet.web -==================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: royalnet.web - :members: - :private-members: - :undoc-members: - - -Royalprints ------------------------------------- - -.. automodule:: royalnet.web.royalprints - :members: - :private-members: - :undoc-members: diff --git a/docs/html/apireference.html b/docs/html/apireference.html new file mode 100644 index 00000000..5f1d467b --- /dev/null +++ b/docs/html/apireference.html @@ -0,0 +1,1389 @@ + + + + + + + + + + + API Reference — Royalnet documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

API ReferenceΒΆ

+

These pages were automatically generated from docstrings in code.

+

They might be outdated, or incomplete.

+
+

AudioΒΆ

+

Video and audio downloading related classes, mainly used for Discord voice bots.

+
+
+class royalnet.audio.YtdlInfo(info: Dict[str, Any])ΒΆ
+

A wrapper around youtube_dl extracted info.

+
+
+__init__(info: Dict[str, Any])ΒΆ
+

Create a YtdlInfo from the dict returned by the youtube_dl.YoutubeDL.extract_info() function.

+
+

Warning

+

Does not download the info, for that use royalnet.audio.YtdlInfo.retrieve_for_url().

+
+
+ +
+
+_default_ytdl_args = {'ignoreerrors': True, 'no_warnings': True, 'noplaylist': True, 'outtmpl': '%(title)s-%(id)s.%(ext)s', 'quiet': True}ΒΆ
+
+ +
+
+classmethod retrieve_for_url(url, **ytdl_args) → List[royalnet.audio.ytdlinfo.YtdlInfo]ΒΆ
+

Fetch the info for an url through YoutubeDL.

+
+
Returns
+

A list containing the infos for the requested videos.

+
+
+
+ +
+
+to_discord_embed() → discord.embeds.EmbedΒΆ
+

Return this info as a discord.Embed.

+
+ +
+ +
+
+class royalnet.audio.YtdlFile(url: str, info: Optional[royalnet.audio.ytdlinfo.YtdlInfo] = None, filename: Optional[str] = None)ΒΆ
+

Information about a youtube-dl downloaded file.

+
+
+_default_ytdl_args = {'ignoreerrors': True, 'no_warnings': True, 'noplaylist': True, 'outtmpl': '%(epoch)s-%(title)s-%(id)s.%(ext)s', 'quiet': True}ΒΆ
+
+ +
+
+delete()ΒΆ
+
+ +
+
+download_file(**ytdl_args) → NoneΒΆ
+
+ +
+
+classmethod download_from_url(url: str, **ytdl_args) → List[royalnet.audio.ytdlfile.YtdlFile]ΒΆ
+
+ +
+
+has_info() → boolΒΆ
+
+ +
+
+is_downloaded() → boolΒΆ
+
+ +
+
+open()ΒΆ
+
+ +
+
+update_info(**ytdl_args) → NoneΒΆ
+
+ +
+ +
+
+class royalnet.audio.FileAudioSource(file)ΒΆ
+

A discord.AudioSource that uses a io.BufferedIOBase as an input instead of memory.

+

The stream should be in the usual PCM encoding.

+
+

Warning

+

This AudioSource will consume (and close) the passed stream.

+
+
+
+is_opus()ΒΆ
+

This audio file isn’t Opus-encoded, but PCM-encoded.

+
+
Returns
+

False.

+
+
+
+ +
+
+read()ΒΆ
+

Reads 20ms worth of audio.

+

If the audio is complete, then returning an empty bytes-like object to signal this is the way to do so.

+
+ +
+ +
+
+class royalnet.audio.YtdlDiscord(ytdl_file: royalnet.audio.ytdlfile.YtdlFile)ΒΆ
+
+
+convert_to_pcm() → NoneΒΆ
+
+ +
+
+classmethod create_and_ready_from_url(url, **ytdl_args) → List[royalnet.audio.ytdldiscord.YtdlDiscord]ΒΆ
+
+ +
+
+classmethod create_from_url(url, **ytdl_args) → List[royalnet.audio.ytdldiscord.YtdlDiscord]ΒΆ
+
+ +
+
+delete() → NoneΒΆ
+
+ +
+
+property infoΒΆ
+
+ +
+
+pcm_available()ΒΆ
+
+ +
+
+ready_up()ΒΆ
+
+ +
+
+spawn_audiosource() → royalnet.audio.fileaudiosource.FileAudioSourceΒΆ
+
+ +
+ +
+
+class royalnet.audio.YtdlMp3(ytdl_file: royalnet.audio.ytdlfile.YtdlFile)ΒΆ
+
+
+convert_to_mp3() → NoneΒΆ
+
+ +
+
+classmethod create_and_ready_from_url(url, **ytdl_args) → List[royalnet.audio.ytdlmp3.YtdlMp3]ΒΆ
+
+ +
+
+classmethod create_from_url(url, **ytdl_args) → List[royalnet.audio.ytdlmp3.YtdlMp3]ΒΆ
+
+ +
+
+delete() → NoneΒΆ
+
+ +
+
+property infoΒΆ
+
+ +
+
+pcm_available()ΒΆ
+
+ +
+
+ready_up()ΒΆ
+
+ +
+ +
+
+

BotsΒΆ

+

Various bot interfaces, and a generic class to create new ones.

+
+
+class royalnet.bots.TelegramBot(*, telegram_config: royalnet.bots.telegram.TelegramConfig, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, sentry_dsn: Optional[str] = None, commands: List[Type[royalnet.commands.command.Command]] = None)ΒΆ
+

A bot that connects to Telegram.

+
+
+_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
+
+ +
+
+async _handle_update(update: telegram.update.Update)ΒΆ
+
+ +
+
+_init_client()ΒΆ
+

Create the telegram.Bot, and set the starting offset.

+
+ +
+
+_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
+
+ +
+
+interface_name = 'telegram'ΒΆ
+
+ +
+
+async run()ΒΆ
+

A blocking coroutine that should make the bot start listening to commands and requests.

+
+ +
+ +
+
+class royalnet.bots.TelegramConfig(token: str)ΒΆ
+

The specific configuration to be used for royalnet.database.TelegramBot.

+
+ +
+
+class royalnet.bots.DiscordBot(*, discord_config: royalnet.bots.discord.DiscordConfig, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, sentry_dsn: Optional[str] = None, commands: List[Type[royalnet.commands.command.Command]] = None)ΒΆ
+

A bot that connects to Discord.

+
+
+_bot_factory() → Type[discord.client.Client]ΒΆ
+

Create a custom DiscordClient class inheriting from discord.Client.

+
+ +
+
+_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
+
+ +
+
+_init_client()ΒΆ
+

Create an instance of the DiscordClient class created in royalnet.bots.DiscordBot._bot_factory().

+
+ +
+
+_init_voice()ΒΆ
+

Initialize the variables needed for the connection to voice chat.

+
+ +
+
+_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
+
+ +
+
+async add_to_music_data(dfiles: List[royalnet.audio.ytdldiscord.YtdlDiscord], guild: discord.guild.Guild)ΒΆ
+

Add a list of royalnet.audio.YtdlDiscord to the corresponding music_data object.

+
+ +
+
+async advance_music_data(guild: discord.guild.Guild)ΒΆ
+

Try to play the next song, while it exists. Otherwise, just return.

+
+ +
+
+interface_name = 'discord'ΒΆ
+
+ +
+
+async run()ΒΆ
+

Login to Discord, then run the bot.

+
+ +
+
+async update_activity_with_source_title()ΒΆ
+

Change the bot’s presence (using discord.Client.change_presence()) to match the current listening status.

+

If multiple guilds are using the bot, the bot will always have an empty presence.

+
+ +
+ +
+
+class royalnet.bots.DiscordConfig(token: str)ΒΆ
+

The specific configuration to be used for royalnet.bots.DiscordBot.

+
+ +
+
+class royalnet.bots.GenericBot(*, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, commands: List[Type[royalnet.commands.command.Command]] = None, sentry_dsn: Optional[str] = None, loop: asyncio.events.AbstractEventLoop = None)ΒΆ
+

A generic bot class, to be used as base for the other more specific classes, such as +royalnet.bots.TelegramBot and royalnet.bots.DiscordBot.

+
+
+_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
+
+ +
+
+_init_commands(commands: List[Type[royalnet.commands.command.Command]]) → NoneΒΆ
+

Generate the commands dictionary required to handle incoming messages, and the network_handlers +dictionary required to handle incoming requests.

+
+ +
+
+_init_database(commands: List[Type[royalnet.commands.command.Command]], database_config: royalnet.database.databaseconfig.DatabaseConfig)ΒΆ
+

Create an royalnet.database.Alchemy with the tables required by the commands. Then, +find the chain that links the master_table to the identity_table.

+
+ +
+
+_init_royalnet(royalnet_config: royalnet.network.royalnetconfig.RoyalnetConfig)ΒΆ
+

Create a royalnet.network.RoyalnetLink, and run it as a asyncio.Task.

+
+ +
+
+_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
+
+ +
+
+async _network_handler(request_dict: dict) → dictΒΆ
+

Handle a single dict received from the royalnet.network.RoyalnetLink.

+
+
Returns
+

Another dict, formatted as a royalnet.network.Response.

+
+
+
+ +
+
+interface_name = NotImplementedΒΆ
+
+ +
+
+async run()ΒΆ
+

A blocking coroutine that should make the bot start listening to commands and requests.

+
+ +
+ +
+
+

CommandsΒΆ

+
+
+class royalnet.commands.CommandInterfaceΒΆ
+
+
+alchemy = NotImplementedΒΆ
+
+ +
+
+bot = NotImplementedΒΆ
+
+ +
+
+loop = NotImplementedΒΆ
+
+ +
+
+name = NotImplementedΒΆ
+
+ +
+
+async net_request(message, destination: str) → dictΒΆ
+

Send data through a royalnet.network.RoyalnetLink and wait for a +royalnet.network.Reply.

+
+
Parameters
+
    +
  • message – The data to be sent. Must be pickle-able.

  • +
  • destination – The destination of the request, either in UUID format or node name.

  • +
+
+
+
+ +
+
+prefix = NotImplementedΒΆ
+
+ +
+
+register_net_handler(message_type: str, network_handler: Callable)ΒΆ
+

Register a new handler for messages received through Royalnet.

+
+ +
+
+unregister_net_handler(message_type: str)ΒΆ
+

Remove a Royalnet handler.

+
+ +
+ +
+
+class royalnet.commands.Command(interface: royalnet.commands.commandinterface.CommandInterface)ΒΆ
+
+
+description = NotImplementedΒΆ
+

A small description of the command, to be displayed when the command is being autocompleted.

+
+ +
+
+name = NotImplementedΒΆ
+

The main name of the command. +To have /example on Telegram, the name should be example.

+
+ +
+
+require_alchemy_tables = {}ΒΆ
+

A set of royalnet.database tables that must exist for this command to work.

+
+ +
+
+async run(args: royalnet.commands.commandargs.CommandArgs, data: royalnet.commands.commanddata.CommandData) → NoneΒΆ
+
+ +
+
+syntax = ''ΒΆ
+

The syntax of the command, to be displayed when a royalnet.error.InvalidInputError is raised, +in the format (required_arg) [optional_arg].

+
+ +
+ +
+
+class royalnet.commands.CommandDataΒΆ
+
+
+async get_author(error_if_none: bool = False)ΒΆ
+

Try to find the identifier of the user that sent the message. +That probably means, the database row identifying the user.

+
+
Parameters
+

error_if_none – Raise a royalnet.error.UnregisteredError if this is True and the call has no author.

+
+
Raises
+

royalnet.error.UnregisteredError –

+
+
+
+ +
+
+async reply(text: str) → NoneΒΆ
+

Send a text message to the channel where the call was made.

+
+
Parameters
+

text – The text to be sent, possibly formatted in the weird undescribed markup that I’m using.

+
+
+
+ +
+ +
+
+class royalnet.commands.CommandArgsΒΆ
+

An interface to access the arguments of a command with ease.

+
+
+__getitem__(item)ΒΆ
+

Arguments can be accessed with an array notation, such as args[0].

+
+
Raises
+

royalnet.error.InvalidInputError – if the requested argument does not exist.

+
+
+
+ +
+
+joined(*, require_at_least=0) → strΒΆ
+

Get the arguments as a space-joined string.

+
+
Parameters
+

require_at_least – the minimum amount of arguments required, will raise royalnet.error.InvalidInputError if the requirement is not fullfilled.

+
+
Raises
+

royalnet.error.InvalidInputError – if there are less than require_at_least arguments.

+
+
Returns
+

The space-joined string.

+
+
+
+ +
+
+match(pattern: Union[str, Pattern]) → Sequence[AnyStr]ΒΆ
+

Match the royalnet.utils.commandargs.joined() to a regex pattern.

+
+
Parameters
+

pattern – The regex pattern to be passed to re.match().

+
+
Raises
+

royalnet.error.InvalidInputError – if the pattern doesn’t match.

+
+
Returns
+

The matched groups, as returned by re.Match.groups().

+
+
+
+ +
+
+optional(index: int, default=None)ΒΆ
+

Get the argument at a specific index, but don’t raise an error if nothing is found, instead returning the default value.

+
+
Parameters
+
    +
  • index – The index of the argument you want to retrieve.

  • +
  • default – The value returned if the argument is missing.

  • +
+
+
Returns
+

Either the argument or the default value, defaulting to None.

+
+
+
+ +
+ +
+
+

DatabaseΒΆ

+

Relational database classes and methods.

+
+
+class royalnet.database.Alchemy(database_uri: str, tables: Set)ΒΆ
+

A wrapper around SQLAlchemy declarative that allows to use multiple databases at once while maintaining a single table-class for both of them.

+
+
+__init__(database_uri: str, tables: Set)ΒΆ
+

Create a new Alchemy object.

+
+
Parameters
+
+
+
+
+ +
+
+_create_tables(tables: Set)ΒΆ
+
+ +
+
+session_acm()ΒΆ
+

Use Alchemy as a asyncronous context manager (to be used in async with statements).

+
+ +
+
+session_cm()ΒΆ
+

Use Alchemy as a context manager (to be used in with statements).

+
+ +
+ +
+
+royalnet.database.relationshiplinkchain(starting_class, ending_class) → Optional[tuple]ΒΆ
+

Find the path to follow to get from the starting table to the ending table.

+
+ +
+
+class royalnet.database.DatabaseConfig(database_uri: str, master_table: Type, identity_table: Type, identity_column_name: str)ΒΆ
+

The configuration to be used for the royalnet.database.Alchemy component of royalnet.bots.GenericBot.

+
+ +
+
+

NetworkΒΆ

+

Royalnet (websocket) related classes.

+
+ +
+
+async connect()ΒΆ
+

Connect to the royalnet.network.RoyalnetServer at self.master_uri.

+
+ +
+
+async identify() → NoneΒΆ
+
+ +
+
+async receive() → royalnet.network.package.PackageΒΆ
+

Recieve a Package from the royalnet.network.RoyalnetServer.

+
+
Raises
+

royalnet.network.royalnetlink.ConnectionClosedError –

+
+
+
+ +
+
+async request(message, destination)ΒΆ
+
+ +
+
+async run(loops: numbers.Real = inf)ΒΆ
+

Blockingly run the Link.

+
+ +
+
+async send(package: royalnet.network.package.Package)ΒΆ
+
+ +
+ +
+
+exception royalnet.network.NetworkError(error_data: dict, *args)ΒΆ
+
+ +
+
+exception royalnet.network.NotConnectedErrorΒΆ
+

The royalnet.network.RoyalnetLink is not connected to a royalnet.network.RoyalnetServer.

+
+ +
+
+exception royalnet.network.NotIdentifiedErrorΒΆ
+

The royalnet.network.RoyalnetLink has not identified yet to a royalnet.network.RoyalnetServer.

+
+ +
+
+class royalnet.network.Package(data: dict, *, source: str, destination: str, source_conv_id: Optional[str] = None, destination_conv_id: Optional[str] = None)ΒΆ
+

A Royalnet package, the data type with which a royalnet.network.RoyalnetLink communicates with a royalnet.network.RoyalnetServer or another link. +Contains info about the source and the destination.

+
+
+__init__(data: dict, *, source: str, destination: str, source_conv_id: Optional[str] = None, destination_conv_id: Optional[str] = None)ΒΆ
+

Create a Package.

+
+
Parameters
+
    +
  • data – The data that should be sent. Usually a royalnet.network.Message.

  • +
  • source – The nid of the node that created this Package.

  • +
  • destination – The link_type of the destination node, or alternatively, the nid of the node. Can also be the NULL value to send the message to nobody.

  • +
  • source_conv_id – The conversation id of the node that created this package. Akin to the sequence number on IP packets.

  • +
  • destination_conv_id – The conversation id of the node that this Package is a reply to.

  • +
+
+
+
+ +
+
+static from_dict(d) → royalnet.network.package.PackageΒΆ
+

Create a Package from a dictionary.

+
+ +
+
+static from_json_bytes(b: bytes) → royalnet.network.package.PackageΒΆ
+

Create a Package from UTF8-encoded JSON bytes.

+
+ +
+
+static from_json_string(string: str) → royalnet.network.package.PackageΒΆ
+

Create a Package from a JSON string.

+
+ +
+
+reply(data) → royalnet.network.package.PackageΒΆ
+

Reply to this Package with another Package.

+
+
Parameters
+

data – The data that should be sent. Usually a royalnet.network.Message.

+
+
Returns
+

The reply Package.

+
+
+
+ +
+
+to_dict() → dictΒΆ
+

Convert the Package into a dictionary.

+
+ +
+
+to_json_bytes() → bytesΒΆ
+

Convert the Package into UTF8-encoded JSON bytes.

+
+ +
+
+to_json_string() → strΒΆ
+

Convert the Package into a JSON string.

+
+ +
+ +
+
+class royalnet.network.RoyalnetServer(address: str, port: int, required_secret: str, *, loop: asyncio.events.AbstractEventLoop = None)ΒΆ
+
+
+find_client(*, nid: str = None, link_type: str = None) → List[royalnet.network.royalnetserver.ConnectedClient]ΒΆ
+
+ +
+
+find_destination(package: royalnet.network.package.Package) → List[royalnet.network.royalnetserver.ConnectedClient]ΒΆ
+

Find a list of destinations for the package.

+
+
Parameters
+

package – The package to find the destination of.

+
+
Returns
+

A list of ConnectedClients to send the package to.

+
+
+
+ +
+
+async listener(websocket: websockets.server.WebSocketServerProtocol, path)ΒΆ
+
+ +
+
+async route_package(package: royalnet.network.package.Package) → NoneΒΆ
+

Executed every time a package is received and must be routed somewhere.

+
+ +
+
+async serve()ΒΆ
+
+ +
+
+async start()ΒΆ
+
+ +
+ +
+
+class royalnet.network.RoyalnetConfig(master_uri: str, master_secret: str)ΒΆ
+
+ +
+
+exception royalnet.network.ConnectionClosedErrorΒΆ
+

The royalnet.network.RoyalnetLink’s connection was closed unexpectedly. The link can’t be used anymore.

+
+ +
+
+class royalnet.network.Request(handler: str, data: dict)ΒΆ
+

A request sent from a royalnet.network.RoyalnetLink to another.

+

It contains the name of the requested handler, in addition to the data.

+
+
+static from_dict(d: dict)ΒΆ
+
+ +
+
+to_dict()ΒΆ
+
+ +
+ +
+
+class royalnet.network.ResponseΒΆ
+

A base class to be inherited by all other response types.

+
+
+classmethod from_dict(d: dict) → royalnet.network.response.ResponseΒΆ
+

Recreate the response from a received dict.

+
+ +
+
+raise_on_error()ΒΆ
+

Raise an Exception if the Response is an error, do nothing otherwise.

+
+ +
+
+to_dict() → dictΒΆ
+

Prepare the Response to be sent by converting it to a JSONable dict.

+
+ +
+ +
+
+class royalnet.network.ResponseSuccess(data: Optional[dict] = None)ΒΆ
+

A response to a successful royalnet.network.Request.

+
+
+raise_on_error()ΒΆ
+

Raise an Exception if the Response is an error, do nothing otherwise.

+
+ +
+ +
+
+class royalnet.network.ResponseError(name: str, description: str, extra_info: Optional[dict] = None)ΒΆ
+

A response to a invalid royalnet.network.Request.

+
+
+raise_on_error()ΒΆ
+

Raise an Exception if the Response is an error, do nothing otherwise.

+
+ +
+ +
+
+

UtilsΒΆ

+

Miscellaneous useful functions and classes.

+
+
+async royalnet.utils.asyncify(function: Callable, *args, **kwargs)ΒΆ
+

Convert a function into a coroutine.

+
+

Warning

+

The coroutine cannot be cancelled, and any attempts to do so will result in unexpected outputs.

+
+
+ +
+
+royalnet.utils.safeformat(string: str, **words: str) → strΒΆ
+

str.format() something, but ignore missing keys instead of raising an error.

+
+
Parameters
+
    +
  • string – The base string to be formatted.

  • +
  • words – The words to format the string with.

  • +
+
+
Returns
+

The formatted string.

+
+
+
+ +
+
+royalnet.utils.cdj(class_: Any) → dictΒΆ
+

Return a dict of the class attributes without the __module__, __dict__, __weakref__ and __doc__ keys, to be used while generating dynamically SQLAlchemy declarative table classes.

+
+
Parameters
+

class_ – The object that you want to dict-ify.

+
+
Returns
+

The class dict.

+
+
+
+

Warning

+

You can’t dict-ify classes with __slots__!

+
+
+ +
+
+async royalnet.utils.sleep_until(dt: datetime.datetime) → NoneΒΆ
+

Block the call until the specified datetime.

+
+

Warning

+

Accurate only to seconds.

+
+
+ +
+
+royalnet.utils.plusformat(i: int) → strΒΆ
+

Convert an int to a str, prepending a + if it’s greater than 0.

+
+
Parameters
+

i – the int to convert.

+
+
Returns
+

The resulting str.

+
+
+
+ +
+
+class royalnet.utils.NetworkHandlerΒΆ
+

The NetworkHandler functions are called when a specific Message type is received.

+
+
+message_type = NotImplementedΒΆ
+
+ +
+ +
+
+royalnet.utils.andformat(l: List[str], middle=', ', final=' and ') → strΒΆ
+

Convert a list to a str by adding final between the last two elements and middle between the others.

+
+
Parameters
+
    +
  • l – the input list.

  • +
  • middle – the str to be added between the middle elements.

  • +
  • final – the str to be added between the last two elements.

  • +
+
+
Returns
+

The resulting str.

+
+
+
+ +
+
+royalnet.utils.plusformat(i: int) → str
+

Convert an int to a str, prepending a + if it’s greater than 0.

+
+
Parameters
+

i – the int to convert.

+
+
Returns
+

The resulting str.

+
+
+
+ +
+
+royalnet.utils.fileformat(string: str) → strΒΆ
+

Ensure a string can be used as a filename by replacing all non-word characters with underscores.

+
+
Parameters
+

string – the input string.

+
+
Returns
+

A valid filename string.

+
+
+
+ +
+
+royalnet.utils.ytdldateformat(string: Optional[str], separator: str = '-') → strΒΆ
+

Convert the weird date string returned by youtube-dl into the YYYY-MM-DD format.

+
+
Parameters
+
    +
  • string – the input string, in the YYYYMMDD format.

  • +
  • separator – the string to add between the years, the months and the days. Defaults to -.

  • +
+
+
Returns
+

The resulting string, in the format YYYY-MM-DD format.

+
+
+
+ +
+
+royalnet.utils.numberemojiformat(l: List[str]) → strΒΆ
+
+ +
+
+royalnet.utils.telegram_escape(string: str) → strΒΆ
+

Escape a string to be sent through Telegram, and format it using RoyalCode.

+
+

Warning

+

Currently escapes everything, even items in code blocks.

+
+
+ +
+
+royalnet.utils.discord_escape(string: str) → strΒΆ
+

Escape a string to be sent through Discord, and format it using RoyalCode.

+
+

Warning

+

Currently escapes everything, even items in code blocks.

+
+
+ +
+
+royalnet.utils.splitstring(s: str, max: int) → List[str]ΒΆ
+
+ +
+
+royalnet.utils.parse_5etools_entry(entry) → strΒΆ
+
+ +
+
+royalnet.utils.ordinalformat(number: int)ΒΆ
+
+ +
+
+

WebΒΆ

+
+
+royalnet.web.create_app(config_obj: Type, blueprints: List[royalnet.web.royalprint.Royalprint])ΒΆ
+

Create a flask.Flask application object.

+

Gets the app.secret_key from the SECRET_KEY envvar.

+

Also requires a DB_PATH key in config_obj to initialize the database connection.

+
+

Warning

+

The code for this class was written at 1 AM, and I have no clue of how and why it works or even if it really does work. +Use with caution?

+
+
+
Parameters
+
    +
  • config_obj – The object to be passed to flask.Flask.config.from_object().

  • +
  • blueprints – A list of blueprints to be registered to the application.

  • +
+
+
Returns
+

The created flask.Flask.

+
+
+
+ +
+
+class royalnet.web.Royalprint(name, import_name, static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, root_path=None, required_tables: Optional[set] = None)ΒΆ
+

An edited flask.Blueprint containing an additional required_tables parameter.

+
+ +
+
+

ErrorΒΆ

+
+
+exception royalnet.error.CurrentlyDisabledErrorΒΆ
+

This feature is temporarely disabled and is not available right now.

+
+ +
+
+exception royalnet.error.ExternalErrorΒΆ
+

Something went wrong in a non-Royalnet component and the command execution cannot be completed.

+
+ +
+
+exception royalnet.error.FileTooBigErrorΒΆ
+

The file to be downloaded would be too big to store; therefore, it has been skipped.

+
+ +
+
+exception royalnet.error.InvalidConfigErrorΒΆ
+

The bot has not been configured correctly, therefore the command can not function.

+
+ +
+
+exception royalnet.error.InvalidInputErrorΒΆ
+

The command has received invalid input and cannot complete.

+
+ +
+
+exception royalnet.error.NoneFoundErrorΒΆ
+

The element that was being looked for was not found.

+
+ +
+
+exception royalnet.error.RoyalnetRequestError(error: ResponseError)ΒΆ
+

An error was raised while handling the Royalnet request.

+

This exception contains the royalnet.network.ResponseError that was returned by the other Link.

+
+ +
+
+exception royalnet.error.RoyalnetResponseErrorΒΆ
+

The royalnet.network.Response that was received is invalid.

+
+ +
+
+exception royalnet.error.TooManyFoundErrorΒΆ
+

Multiple elements matching the request were found, and only one was expected.

+
+ +
+
+exception royalnet.error.UnregisteredErrorΒΆ
+

The command required a registered user, and the user was not registered.

+
+ +
+
+exception royalnet.error.UnsupportedErrorΒΆ
+

The command is not supported for the specified interface.

+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/docs/html/audio.html b/docs/html/audio.html deleted file mode 100644 index 5daf13b8..00000000 --- a/docs/html/audio.html +++ /dev/null @@ -1,413 +0,0 @@ - - - - - - - - - - - royalnet.audio — Royalnet documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - -
- -
- - - - - - - - - - - - - - - - - -
- - - - -
-
-
-
- -
-

royalnet.audioΒΆ

-
-
-

Video and audio downloading related classes, mainly used for Discord voice bots.

-
-
-class royalnet.audio.YtdlInfo(info: Dict[str, Any])ΒΆ
-

A wrapper around youtube_dl extracted info.

-
-
-__init__(info: Dict[str, Any])ΒΆ
-

Create a YtdlInfo from the dict returned by the youtube_dl.YoutubeDL.extract_info() function.

-
-

Warning

-

Does not download the info, for that use royalnet.audio.YtdlInfo.retrieve_for_url().

-
-
- -
-
-_default_ytdl_args = {'ignoreerrors': True, 'no_warnings': True, 'noplaylist': True, 'outtmpl': '%(title)s-%(id)s.%(ext)s', 'quiet': True}ΒΆ
-
- -
-
-classmethod retrieve_for_url(url, **ytdl_args) → List[royalnet.audio.ytdlinfo.YtdlInfo]ΒΆ
-

Fetch the info for an url through YoutubeDL.

-
-
Returns
-

A list containing the infos for the requested videos.

-
-
-
- -
-
-to_discord_embed() → discord.embeds.EmbedΒΆ
-

Return this info as a discord.Embed.

-
- -
- -
-
-class royalnet.audio.YtdlFile(url: str, info: Optional[royalnet.audio.ytdlinfo.YtdlInfo] = None, filename: Optional[str] = None)ΒΆ
-

Information about a youtube-dl downloaded file.

-
-
-_default_ytdl_args = {'ignoreerrors': True, 'no_warnings': True, 'noplaylist': True, 'outtmpl': '%(epoch)s-%(title)s-%(id)s.%(ext)s', 'quiet': True}ΒΆ
-
- -
-
-delete()ΒΆ
-
- -
-
-download_file(**ytdl_args) → NoneΒΆ
-
- -
-
-classmethod download_from_url(url: str, **ytdl_args) → List[royalnet.audio.ytdlfile.YtdlFile]ΒΆ
-
- -
-
-has_info() → boolΒΆ
-
- -
-
-is_downloaded() → boolΒΆ
-
- -
-
-open()ΒΆ
-
- -
-
-update_info(**ytdl_args) → NoneΒΆ
-
- -
- -
-
-class royalnet.audio.FileAudioSource(file)ΒΆ
-

A discord.AudioSource that uses a io.BufferedIOBase as an input instead of memory.

-

The stream should be in the usual PCM encoding.

-
-

Warning

-

This AudioSource will consume (and close) the passed stream.

-
-
-
-is_opus()ΒΆ
-

This audio file isn’t Opus-encoded, but PCM-encoded.

-
-
Returns
-

False.

-
-
-
- -
-
-read()ΒΆ
-

Reads 20ms worth of audio.

-

If the audio is complete, then returning an empty bytes-like object to signal this is the way to do so.

-
- -
- -
-
-class royalnet.audio.YtdlDiscord(ytdl_file: royalnet.audio.ytdlfile.YtdlFile)ΒΆ
-
-
-convert_to_pcm() → NoneΒΆ
-
- -
-
-classmethod create_and_ready_from_url(url, **ytdl_args) → List[royalnet.audio.ytdldiscord.YtdlDiscord]ΒΆ
-
- -
-
-classmethod create_from_url(url, **ytdl_args) → List[royalnet.audio.ytdldiscord.YtdlDiscord]ΒΆ
-
- -
-
-delete() → NoneΒΆ
-
- -
-
-property infoΒΆ
-
- -
-
-pcm_available()ΒΆ
-
- -
-
-ready_up()ΒΆ
-
- -
-
-spawn_audiosource() → royalnet.audio.fileaudiosource.FileAudioSourceΒΆ
-
- -
- -
-
-class royalnet.audio.YtdlMp3(ytdl_file: royalnet.audio.ytdlfile.YtdlFile)ΒΆ
-
-
-convert_to_mp3() → NoneΒΆ
-
- -
-
-classmethod create_and_ready_from_url(url, **ytdl_args) → List[royalnet.audio.ytdlmp3.YtdlMp3]ΒΆ
-
- -
-
-classmethod create_from_url(url, **ytdl_args) → List[royalnet.audio.ytdlmp3.YtdlMp3]ΒΆ
-
- -
-
-delete() → NoneΒΆ
-
- -
-
-property infoΒΆ
-
- -
-
-pcm_available()ΒΆ
-
- -
-
-ready_up()ΒΆ
-
- -
- -
- - -
- -
- - -
-
- -
- -
- - - - - - - - - - - - \ No newline at end of file diff --git a/docs/html/bots.html b/docs/html/bots.html deleted file mode 100644 index a17fc225..00000000 --- a/docs/html/bots.html +++ /dev/null @@ -1,388 +0,0 @@ - - - - - - - - - - - royalnet.bots — Royalnet documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - -
- -
- - - - - - - - - - - - - - - - - -
- - - - -
-
-
-
- -
-

royalnet.botsΒΆ

-
-
-

Various bot interfaces, and a generic class to create new ones.

-
-
-class royalnet.bots.TelegramBot(*, telegram_config: royalnet.bots.telegram.TelegramConfig, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, commands: List[Type[royalnet.commands.command.Command]] = None)ΒΆ
-

A bot that connects to Telegram.

-
-
-_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
-
- -
-
-async _handle_update(update: telegram.update.Update)ΒΆ
-
- -
-
-_init_client()ΒΆ
-

Create the telegram.Bot, and set the starting offset.

-
- -
-
-_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
-
- -
-
-interface_name = 'telegram'ΒΆ
-
- -
-
-async run()ΒΆ
-

A blocking coroutine that should make the bot start listening to commands and requests.

-
- -
- -
-
-class royalnet.bots.TelegramConfig(token: str)ΒΆ
-

The specific configuration to be used for royalnet.database.TelegramBot.

-
- -
-
-class royalnet.bots.DiscordBot(*, discord_config: royalnet.bots.discord.DiscordConfig, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, commands: List[Type[royalnet.commands.command.Command]] = None)ΒΆ
-

A bot that connects to Discord.

-
-
-_bot_factory() → Type[discord.client.Client]ΒΆ
-

Create a custom DiscordClient class inheriting from discord.Client.

-
- -
-
-_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
-
- -
-
-_init_client()ΒΆ
-

Create an instance of the DiscordClient class created in royalnet.bots.DiscordBot._bot_factory().

-
- -
-
-_init_voice()ΒΆ
-

Initialize the variables needed for the connection to voice chat.

-
- -
-
-_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
-
- -
-
-async add_to_music_data(dfiles: List[royalnet.audio.ytdldiscord.YtdlDiscord], guild: discord.guild.Guild)ΒΆ
-

Add a list of royalnet.audio.YtdlDiscord to the corresponding music_data object.

-
- -
-
-async advance_music_data(guild: discord.guild.Guild)ΒΆ
-

Try to play the next song, while it exists. Otherwise, just return.

-
- -
-
-interface_name = 'discord'ΒΆ
-
- -
-
-async run()ΒΆ
-

Login to Discord, then run the bot.

-
- -
-
-async update_activity_with_source_title()ΒΆ
-

Change the bot’s presence (using discord.Client.change_presence()) to match the current listening status.

-

If multiple guilds are using the bot, the bot will always have an empty presence.

-
- -
- -
-
-class royalnet.bots.DiscordConfig(token: str)ΒΆ
-

The specific configuration to be used for royalnet.bots.DiscordBot.

-
- -
-
-class royalnet.bots.GenericBot(*, royalnet_config: Optional[royalnet.network.royalnetconfig.RoyalnetConfig] = None, database_config: Optional[royalnet.database.databaseconfig.DatabaseConfig] = None, commands: List[Type[royalnet.commands.command.Command]] = None, loop: asyncio.events.AbstractEventLoop = None)ΒΆ
-

A generic bot class, to be used as base for the other more specific classes, such as -royalnet.bots.TelegramBot and royalnet.bots.DiscordBot.

-
-
-_data_factory() → Type[royalnet.commands.commanddata.CommandData]ΒΆ
-
- -
-
-_init_commands(commands: List[Type[royalnet.commands.command.Command]]) → NoneΒΆ
-

Generate the commands dictionary required to handle incoming messages, and the network_handlers -dictionary required to handle incoming requests.

-
- -
-
-_init_database(commands: List[Type[royalnet.commands.command.Command]], database_config: royalnet.database.databaseconfig.DatabaseConfig)ΒΆ
-

Create an royalnet.database.Alchemy with the tables required by the commands. Then, -find the chain that links the master_table to the identity_table.

-
- -
-
-_init_royalnet(royalnet_config: royalnet.network.royalnetconfig.RoyalnetConfig)ΒΆ
-

Create a royalnet.network.RoyalnetLink, and run it as a asyncio.Task.

-
- -
-
-_interface_factory() → Type[royalnet.commands.commandinterface.CommandInterface]ΒΆ
-
- -
-
-async _network_handler(request_dict: dict) → dictΒΆ
-

Handle a single dict received from the royalnet.network.RoyalnetLink.

-
-
Returns
-

Another dict, formatted as a royalnet.network.Response.

-
-
-
- -
-
-interface_name = NotImplementedΒΆ
-
- -
-
-async run()ΒΆ
-

A blocking coroutine that should make the bot start listening to commands and requests.

-
- -
- -
- - -
- -
- - -
-
- -
- -
- - - - - - - - - - - - \ No newline at end of file diff --git a/docs/html/commands.html b/docs/html/commands.html deleted file mode 100644 index ec17e7a9..00000000 --- a/docs/html/commands.html +++ /dev/null @@ -1,288 +0,0 @@ - - - - - - - - - - - royalnet.commands — Royalnet documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - -
- -
- - - - - - - - - - - - - - - - - -
- - - - -
-
-
-
- -
-

royalnet.commandsΒΆ

-
-
-
-
-class royalnet.commands.CommandArgsΒΆ
-

An interface to access the arguments of a command with ease.

-
-
-__getitem__(item)ΒΆ
-

Arguments can be accessed with an array notation, such as args[0].

-
-
Raises
-

royalnet.error.InvalidInputError – if the requested argument does not exist.

-
-
-
- -
-
-__weakref__ΒΆ
-

list of weak references to the object (if defined)

-
- -
-
-joined(*, require_at_least=0) → strΒΆ
-

Get the arguments as a space-joined string.

-
-
Parameters
-

require_at_least – the minimum amount of arguments required, will raise royalnet.error.InvalidInputError if the requirement is not fullfilled.

-
-
Raises
-

royalnet.error.InvalidInputError – if there are less than require_at_least arguments.

-
-
Returns
-

The space-joined string.

-
-
-
- -
-
-match(pattern: Union[str, Pattern]) → Sequence[AnyStr]ΒΆ
-

Match the royalnet.utils.commandargs.joined() to a regex pattern.

-
-
Parameters
-

pattern – The regex pattern to be passed to re.match().

-
-
Raises
-

royalnet.error.InvalidInputError – if the pattern doesn’t match.

-
-
Returns
-

The matched groups, as returned by re.Match.groups().

-
-
-
- -
-
-optional(index: int, default=None)ΒΆ
-

Get the argument at a specific index, but don’t raise an error if nothing is found, instead returning the default value.

-
-
Parameters
-
    -
  • index – The index of the argument you want to retrieve.

  • -
  • default – The value returned if the argument is missing.

  • -
-
-
Returns
-

Either the argument or the default value, defaulting to None.

-
-
-
- -
- -
- - -
- -
- - -
-
- -
- -
- - - - - - - - - - - - \ No newline at end of file diff --git a/docs/html/creatingacommand.html b/docs/html/creatingacommand.html new file mode 100644 index 00000000..e8fbdd6c --- /dev/null +++ b/docs/html/creatingacommand.html @@ -0,0 +1,263 @@ + + + + + + + + + + + Royalnet Commands — Royalnet documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + + + +
+ + + + +
+
+
+
+ +
+

Royalnet CommandsΒΆ

+

A Royalnet Command is a small script that is run whenever a specific message is sent to a Royalnet interface.

+

A Command code looks like this:

+
from royalnet.commands import Command
+
+class PingCommand(Command):
+    name = "ping"
+
+    description = "Play ping-pong with the bot."
+
+    def __init__(self, interface):
+        # This code is run just once, while the bot is starting
+        super().__init__()
+
+    async def run(self, args, data):
+        # This code is run every time the command is called
+        await data.reply("Pong!")
+
+
+
+

Creating a new CommandΒΆ

+

First, think of a name for your command. +It’s the name your command will be called with: for example, the β€œspaghetti” command will be called by typing /spaghetti in chat. +Try to keep the name as short as possible, while staying specific enough so no other command will have the same name.

+

Next, create a new Python file with the name you have thought of. +The previously mentioned β€œspaghetti” command should have a file called spaghetti.py.

+

Then, in the first row of the file, import the Command class from royalnet, and create a new class inheriting from it:

+
from royalnet.commands import Command
+
+class SpaghettiCommand(Command):
+    ...
+
+
+

Inside the class, override the attributes name and description with respectively the name of the command and a small description of what the command will do:

+
from royalnet.commands import Command
+
+class SpaghettiCommand(Command):
+    name = "spaghetti"
+
+    description = "Send a spaghetti emoji in the chat."
+
+
+

Now override the Command.run() method, adding the code you want the bot to run when the command is called.

+

To send a message in the chat the command was called in, you can use the CommandData.reply() method:

+
from royalnet.commands import Command
+
+class SpaghettiCommand(Command):
+    name = "spaghetti"
+
+    description = "Send a spaghetti emoji in the chat."
+
+    async def run(self, args, data):
+        data.reply("🍝")
+
+
+

And it’s done! The command is now ready to be used in a bot!

+
+
+ + +
+ +
+ + +
+
+ +
+ +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/docs/html/database.html b/docs/html/database.html deleted file mode 100644 index 301eef29..00000000 --- a/docs/html/database.html +++ /dev/null @@ -1,738 +0,0 @@ - - - - - - - - - - - royalnet.database — Royalnet documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - -
- -
- - - - - - - - - - - - - - - - - -
- - - - -
-
-
-
- -
-

royalnet.databaseΒΆ

-
-
-

Relational database classes and methods.

-
-
-class royalnet.database.Alchemy(database_uri: str, tables: Set)ΒΆ
-

A wrapper around SQLAlchemy declarative that allows to use multiple databases at once while maintaining a single table-class for both of them.

-
-
-__init__(database_uri: str, tables: Set)ΒΆ
-

Create a new Alchemy object.

-
-
Parameters
-
-
-
-
- -
-
-_create_tables(tables: Set)ΒΆ
-
- -
-
-session_acm()ΒΆ
-

Use Alchemy as a asyncronous context manager (to be used in async with statements).

-
- -
-
-session_cm()ΒΆ
-

Use Alchemy as a context manager (to be used in with statements).

-
- -
- -
-
-royalnet.database.relationshiplinkchain(starting_class, ending_class) → Optional[tuple]ΒΆ
-

Find the path to follow to get from the starting table to the ending table.

-
- -
-
-class royalnet.database.DatabaseConfig(database_uri: str, master_table: Type, identity_table: Type, identity_column_name: str)ΒΆ
-

The configuration to be used for the royalnet.database.Alchemy component of royalnet.bots.GenericBot.

-
- -
-

TablesΒΆ

-
-
-class royalnet.database.tables.RoyalΒΆ
-
-
-avatar = Column(None, LargeBinary(), table=None)ΒΆ
-
- -
-
-password = Column(None, LargeBinary(), table=None)ΒΆ
-
- -
-
-role = Column(None, String(), table=None, nullable=False)ΒΆ
-
- -
-
-uid = Column(None, Integer(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-username = Column(None, String(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.TelegramΒΆ
-
-
-first_name = Column(None, String(), table=None)ΒΆ
-
- -
-
-last_name = Column(None, String(), table=None)ΒΆ
-
- -
-
-mention() → strΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b4108; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
-
-tg_id = Column(None, BigInteger(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-username = Column(None, String(), table=None)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.DiarioΒΆ
-
-
-context = Column(None, Text(), table=None)ΒΆ
-
- -
-
-creator = <RelationshipProperty at 0x77b4348; no key>ΒΆ
-
- -
-
-creator_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
-
-diario_id = Column(None, Integer(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-media_url = Column(None, String(), table=None)ΒΆ
-
- -
-
-quoted = Column(None, String(), table=None)ΒΆ
-
- -
-
-quoted_account = <RelationshipProperty at 0x77b45d0; no key>ΒΆ
-
- -
-
-quoted_account_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
-
-spoiler = Column(None, Boolean(), table=None, default=ColumnDefault(False))ΒΆ
-
- -
-
-text = Column(None, Text(), table=None)ΒΆ
-
- -
-
-timestamp = Column(None, DateTime(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.AliasΒΆ
-
-
-alias = Column(None, String(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b4300; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.ActiveKvGroupΒΆ
-
-
-group = <RelationshipProperty at 0x7733f18; no key>ΒΆ
-
- -
-
-group_name = Column(None, String(), ForeignKey('keygroups.group_name'), table=None, nullable=False)ΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b4300; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.KeyvalueΒΆ
-
-
-group = <RelationshipProperty at 0x77b4660; no key>ΒΆ
-
- -
-
-group_name = Column(None, String(), ForeignKey('keygroups.group_name'), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-key = Column(None, String(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-value = Column(None, String(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.KeygroupΒΆ
-
-
-group_name = Column(None, String(), ForeignKey('keygroups.group_name'), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.DiscordΒΆ
-
-
-avatar_hash = Column(None, String(), table=None)ΒΆ
-
- -
-
-discord_id = Column(None, BigInteger(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-discriminator = Column(None, String(), table=None)ΒΆ
-
- -
-
-full_username()ΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b45d0; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
-
-username = Column(None, String(), table=None)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.WikiPageΒΆ
-

Wiki page properties.

-
-

Warning

-

Requires PostgreSQL!

-
-
-
-contents = Column(None, Text(), table=None)ΒΆ
-
- -
-
-css = Column(None, String(), table=None)ΒΆ
-
- -
-
-format = Column(None, String(), table=None, nullable=False, default=ColumnDefault('markdown'))ΒΆ
-
- -
-
-page_id = Column(None, UUID(as_uuid=True), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-property page_short_idΒΆ
-
- -
-
-title = Column(None, String(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.WikiRevisionΒΆ
-

A wiki page revision.

-
-

Warning

-

Requires PostgreSQL!

-
-
-
-author = <RelationshipProperty at 0x77b4738; no key>ΒΆ
-
- -
-
-author_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None, nullable=False)ΒΆ
-
- -
-
-diff = Column(None, Text(), table=None)ΒΆ
-
- -
-
-page = <RelationshipProperty at 0x77b4150; no key>ΒΆ
-
- -
-
-page_id = Column(None, UUID(as_uuid=True), ForeignKey('wikipages.page_id'), table=None, nullable=False)ΒΆ
-
- -
-
-reason = Column(None, Text(), table=None)ΒΆ
-
- -
-
-revision_id = Column(None, UUID(as_uuid=True), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-timestamp = Column(None, DateTime(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.MedalΒΆ
-
-
-classes = Column(None, String(), table=None, nullable=False, default=ColumnDefault(''))ΒΆ
-
- -
-
-description = Column(None, String(), table=None)ΒΆ
-
- -
-
-icon = Column(None, String(), table=None)ΒΆ
-
- -
-
-mid = Column(None, Integer(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-name = Column(None, String(), table=None, nullable=False)ΒΆ
-
- -
-
-score = Column(None, Integer(), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.MedalAwardΒΆ
-
-
-award_id = Column(None, Integer(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
-
-date = Column(None, DateTime(), table=None)ΒΆ
-
- -
-
-medal = <RelationshipProperty at 0x77b4858; no key>ΒΆ
-
- -
-
-medal_id = Column(None, Integer(), ForeignKey('medals.mid'), table=None, nullable=False)ΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b43d8; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royal.uid'), table=None, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.BioΒΆ
-
-
-contents = Column(None, Text(), table=None, nullable=False, default=ColumnDefault(''))ΒΆ
-
- -
-
-royal = <RelationshipProperty at 0x77b4300; no key>ΒΆ
-
- -
-
-royal_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
- -
-
-class royalnet.database.tables.ReminderΒΆ
-
-
-creator = <RelationshipProperty at 0x77b4c00; no key>ΒΆ
-
- -
-
-creator_id = Column(None, Integer(), ForeignKey('royals.uid'), table=None)ΒΆ
-
- -
-
-datetime = Column(None, DateTime(), table=None)ΒΆ
-
- -
-
-interface_data = Column(None, LargeBinary(), table=None)ΒΆ
-
- -
-
-interface_name = Column(None, String(), table=None)ΒΆ
-
- -
-
-message = Column(None, String(), table=None)ΒΆ
-
- -
-
-reminder_id = Column(None, Integer(), table=None, primary_key=True, nullable=False)ΒΆ
-
- -
- -
-
- - -
- -
- - -
-
- -
- -
- - - - - - - - - - - - \ No newline at end of file diff --git a/docs/html/error.html b/docs/html/error.html deleted file mode 100644 index 3ba76e5d..00000000 --- a/docs/html/error.html +++ /dev/null @@ -1,281 +0,0 @@ - - - - - - - - - - - royalnet.error — Royalnet documentation - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- - - - - -
- -
- - - - - - - - - - - - - - - - - -
- - - - -
-
-
-
- -
-

royalnet.errorΒΆ

-
-
-
-
-exception royalnet.error.CurrentlyDisabledErrorΒΆ
-

This feature is temporarely disabled and is not available right now.

-
- -
-
-exception royalnet.error.ExternalErrorΒΆ
-

Something went wrong in a non-Royalnet component and the command execution cannot be completed.

-
- -
-
-exception royalnet.error.FileTooBigErrorΒΆ
-

The file to be downloaded would be too big to store; therefore, it has been skipped.

-
- -
-
-exception royalnet.error.InvalidConfigErrorΒΆ
-

The bot has not been configured correctly, therefore the command can not function.

-
- -
-
-exception royalnet.error.InvalidInputErrorΒΆ
-

The command has received invalid input and cannot complete.

-
- -
-
-exception royalnet.error.NoneFoundErrorΒΆ
-

The element that was being looked for was not found.

-
- -
-
-exception royalnet.error.RoyalnetRequestError(error: ResponseError)ΒΆ
-

An error was raised while handling the Royalnet request.

-

This exception contains the royalnet.network.ResponseError that was returned by the other Link.

-
- -
-
-exception royalnet.error.RoyalnetResponseErrorΒΆ
-

The royalnet.network.Response that was received is invalid.

-
- -
-
-exception royalnet.error.TooManyFoundErrorΒΆ
-

Multiple elements matching the request were found, and only one was expected.

-
- -
-
-exception royalnet.error.UnregisteredErrorΒΆ
-

The command required a registered user, and the user was not registered.

-
- -
-
-exception royalnet.error.UnsupportedErrorΒΆ
-

The command is not supported for the specified interface.

-
- -
- - -
- -
- - -
-
- -
- -
- - - - - - - - - - - - \ No newline at end of file diff --git a/docs/html/genindex.html b/docs/html/genindex.html index 3c095068..c5514b0c 100644 --- a/docs/html/genindex.html +++ b/docs/html/genindex.html @@ -81,14 +81,8 @@ @@ -166,82 +160,76 @@ | H | I | J - | K | L | M | N | O | P - | Q | R | S | T | U - | V - | W | Y

_

@@ -249,33 +237,19 @@

A

@@ -283,7 +257,7 @@

B

@@ -291,59 +265,41 @@

C

@@ -351,45 +307,29 @@

D

@@ -397,7 +337,7 @@

E

@@ -405,35 +345,29 @@

F

@@ -441,31 +375,19 @@

G

H

@@ -473,37 +395,31 @@

I

@@ -511,21 +427,7 @@

J

-
- -

K

- - -
@@ -533,11 +435,11 @@

L

@@ -545,27 +447,11 @@

M

@@ -573,21 +459,27 @@

N

@@ -595,11 +487,13 @@

O

@@ -607,43 +501,21 @@

P

-
- -

Q

- - -
@@ -651,124 +523,90 @@

R

@@ -777,27 +615,27 @@

S

@@ -805,43 +643,29 @@

T

@@ -849,45 +673,17 @@

U

-
- -

V

- - -
- -

W

- - -
@@ -895,17 +691,17 @@

Y

diff --git a/docs/html/index.html b/docs/html/index.html index 6628248e..d829177a 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -36,7 +36,7 @@ - + @@ -81,14 +81,8 @@ @@ -155,32 +149,22 @@

royalnetΒΆ

+

Welcome to the documentation of Royalnet!