This module implements the Discord bot functionality for the DeerTick project. For an overview of how it fits into the larger system, see the DeerTick Main Documentation.
Encodes data to JSON if it's not already a string.
Decodes JSON data to Python objects, returns original data if decoding fails.
Sends an error message to the Discord channel and logs it to the database.
Extends commands.Bot
to add custom functionality.
MyBot(*args, **kwargs)
db_manager
(DatabaseManager): Manages database operations.agents
(dict): Stores active agent instances.
Asynchronous setup method called when the bot is starting.
Event handler called when the bot has successfully connected to Discord.
Creates a new agent with the given name, model, and provider.
Sends a message to a specific agent and gets a response.
Sets a parameter for a specific agent.
Retrieves and displays information about a specific agent.
Lists all currently available agents.
Continues the conversation with the last agent that spoke in the channel.
Deletes an agent from the bot and the database.
Attaches an existing agent from the database to the bot.
Displays help information for all bot commands.
Creates a backup of the entire database to CSV files.
Renders a Mermaid diagram and sends it to the Discord channel.
Adds an agent to the current channel. Only admins can use this command.
Removes an agent from the current channel. Only admins can use this command.
df
(pandas.DataFrame): Stores model data loaded from 'model_data.csv'.model
(dict): Maps model names to their IDs.model_type
(dict): Maps model names to their types.preferred_providers
(dict): Maps model names to their preferred providers.providers
(dict): Maps model names to lists of supported providers.config
(configparser.ConfigParser): Stores configuration data from 'config.ini'.intents
(discord.Intents): Defines the bot's intents.bot
(MyBot): The main bot instance.director
(Agent): A special agent for managing other agents.
# Initialize the bot
bot = MyBot(command_prefix='!', intents=intents)
# Create a new agent
@bot.command()
async def create_new_agent(ctx, name):
await create_agent(ctx, name)
# Run the bot
bot.run(config.get('keys', 'DISCORD_BOT_TOKEN'))
- The bot uses a custom
DatabaseManager
for handling database operations. - Many commands interact with both the bot's local
agents
dictionary and the database. - Error handling is implemented using the
send_error_message
function. - The bot supports various operations like creating agents, managing their parameters, and facilitating conversations.