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 thenetwork_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 themaster_table
to theidentity_table
.
-
_init_royalnet
(royalnet_config: royalnet.network.royalnetconfig.RoyalnetConfig)¶ Create a
royalnet.network.RoyalnetLink
, and run it as aasyncio.Task
.
-
_interface_factory
() → Type[royalnet.commands.commandinterface.CommandInterface]¶
-
async
_network_handler
(request_dict: dict) → dict¶ Handle a single
dict
received from theroyalnet.network.RoyalnetLink
.- Returns
Another
dict
, formatted as aroyalnet.network.Response
.
-
interface_name
= NotImplemented¶
-
async
run
()¶ A blocking coroutine that should make the bot start listening to commands and requests.
-