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, command_prefix: str = '/', commands: List[Type[royalnet.utils.command.Command]] = None, missing_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>, error_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>)¶ A bot that connects to Telegram.
-
_call_factory
() → Type[royalnet.utils.call.Call]¶ Create the TelegramCall class, representing a command call. It should inherit from
royalnet.utils.Call
.- Returns
The created TelegramCall class.
-
_handle_update
(update: telegram.update.Update)¶
-
_init_client
()¶ Create the
telegram.Bot
, and set the starting offset.
-
botfather_command_string
¶ Generate a string to be pasted in the “Edit Commands” BotFather prompt.
-
interface_name
= 'telegram'¶
-
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, command_prefix: str = '!', commands: List[Type[royalnet.utils.command.Command]] = None, missing_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>, error_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>)¶ A bot that connects to Discord.
-
_bot_factory
() → Type[discord.client.Client]¶ Create a custom DiscordClient class inheriting from
discord.Client
.
-
_call_factory
() → Type[royalnet.utils.call.Call]¶ Create the TelegramCall class, representing a command call. It should inherit from
royalnet.utils.Call
.- Returns
The created TelegramCall class.
-
_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.
-
add_to_music_data
(audio_sources: List[royalnet.audio.royalpcmaudio.RoyalPCMAudio], guild: discord.guild.Guild)¶ Add a file to the corresponding music_data object.
-
advance_music_data
(guild: discord.guild.Guild)¶ Try to play the next song, while it exists. Otherwise, just return.
-
interface_name
= 'discord'¶
-
run
()¶ Login to Discord, then run the bot.
-
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, command_prefix: str, commands: List[Type[royalnet.utils.command.Command]] = None, missing_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>, error_command: Type[royalnet.utils.command.Command] = <class 'royalnet.commands.null.NullCommand'>)¶ A generic bot class, to be used as base for the other more specific classes, such as royalnet.bots.TelegramBot and royalnet.bots.DiscordBot.
-
_call_factory
() → Type[royalnet.utils.call.Call]¶ Create the TelegramCall class, representing a command call. It should inherit from
royalnet.utils.Call
.- Returns
The created TelegramCall class.
-
_init_commands
(command_prefix: str, commands: List[Type[royalnet.utils.command.Command]], missing_command: Type[royalnet.utils.command.Command], error_command: Type[royalnet.utils.command.Command]) → None¶ Generate the
commands
dictionary required to handle incoming messages, and thenetwork_handlers
dictionary required to handle incoming requests.
-
_init_database
(commands: List[Type[royalnet.utils.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 themaster_table
to theidentity_table
.
-
_init_royalnet
(royalnet_config: royalnet.network.royalnetconfig.RoyalnetConfig)¶ Create a
royalnet.network.RoyalnetLink
, and run it as aasyncio.Task
.
-
_network_handler
(request_dict: dict) → dict¶ Handle a single
dict
received from theroyalnet.network.RoyalnetLink
.- Returns
Another
dict
, formatted as aroyalnet.network.Response
.
-
call
(command_name: str, channel, parameters: List[str] = None, **kwargs)¶ Call the command with the specified name.
If it doesn’t exist, call
self.missing_command
.If an exception is raised during the execution of the command, call
self.error_command
.
-
interface_name
= NotImplemented¶
-
run
()¶ A blocking coroutine that should make the bot start listening to commands and requests.
-