Co-authored-by: TheLovinator1 <4153203+TheLovinator1@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
3.4 KiB
3.4 KiB
Copilot Instructions for ANewDawn
Project Overview
ANewDawn is a Discord bot written in Python 3.13+ using the discord.py library and Pydantic AI for AI-powered chat capabilities. The bot includes features such as:
- AI-powered chat responses using OpenAI and Grok models
- Conversation memory with reset/undo functionality
- Image enhancement using OpenCV
- Web search integration via Ollama
- Slash commands and context menus
Development Environment
- Python: 3.13 or higher required
- Package Manager: Use
uvfor dependency management (seepyproject.toml) - Docker: The project uses Docker for deployment (see
Dockerfileanddocker-compose.yml) - Environment Variables: Copy
.env.exampleto.envand fill in required tokens
Code Style and Conventions
Linting and Formatting
This project uses Ruff for linting and formatting with strict settings:
- All rules enabled (
lint.select = ["ALL"]) - Preview features enabled
- Auto-fix enabled
- Line length: 160 characters
- Google-style docstrings required
Run linting:
ruff check --exit-non-zero-on-fix --verbose
Run formatting check:
ruff format --check --verbose
Python Conventions
- Use
from __future__ import annotationsat the top of all files (automatically added by Ruff) - Use type hints for all function parameters and return types
- Follow Google docstring convention
- Use
loggingmodule for logging, not print statements - Prefer explicit imports over wildcard imports
Testing
- Tests use pytest
- Test files should be named
*_test.pyortest_*.py - Run tests with:
pytest
Project Structure
main.py- Main bot application with all commands and event handlerspyproject.toml- Project configuration and dependenciesDockerfile/docker-compose.yml- Container configuration.github/workflows/- CI/CD workflows
Key Components
Bot Client
The main bot client is LoviBotClient which extends discord.Client. It handles:
- Message events (
on_message) - Slash commands (
/ask,/grok,/reset,/undo) - Context menus (image enhancement)
AI Integration
chatgpt_agent- Pydantic AI agent using OpenAIgrok_it()- Function for Grok model responses- Message history is stored in
recent_messagesdict per channel
Memory Management
add_message_to_memory()- Store messages for contextreset_memory()- Clear conversation historyundo_reset()- Restore previous state
CI/CD
The GitHub Actions workflow (.github/workflows/docker-publish.yml) runs:
- Ruff linting and format check
- Dockerfile validation
- Docker image build and push to GitHub Container Registry
Common Tasks
Adding a New Slash Command
- Add the command function with
@client.tree.command()decorator - Include
@app_commands.allowed_installs()and@app_commands.allowed_contexts()decorators - Use
await interaction.response.defer()for long-running operations - Check user authorization with
get_allowed_users()
Adding a New AI Instruction
- Create a function decorated with
@chatgpt_agent.instructions - The function should return a string with the instruction content
- Use
RunContext[BotDependencies]parameter to access dependencies
Modifying Image Enhancement
Image enhancement functions (enhance_image1, enhance_image2, enhance_image3) use OpenCV. Each returns WebP-encoded bytes.