Skip to content

MishaVyb/bart-bot

Repository files navigation

πŸˆβ€β¬› Bart Bot

Code style: black Test workflow Deploy workflow PTB Pyrogram Anyio SQLAlchemy

πŸ₯›πŸ₯πŸ₯ŸπŸšπŸ₯“πŸ™πŸ₯–β˜•οΈπŸ£ <--- πŸˆβ€β¬›

A delightful Telegram bot that behaves like your real pet! Send photos to build a collection, then feed your virtual pet with emoji food to receive random photos from your gallery.

✨ Features

🐾 Pet-like Behavior

  • Unique Responses: Every interaction gets a different pre-defined message, just like a real pet
  • Flexible Storage: Each participant has their own photo storage that can be shared with family members
  • Unpredictable: Randomly selects images to reply after feeding, keeping interactions exciting

πŸ—οΈ Technical Excellence

  • Asynchronous Architecture: Built with modern async/await patterns for optimal performance
  • Persistent Storage: All chat history and photos stored in PostgreSQL database
  • Custom Middleware System: Familiar middleware pattern similar to web frameworks
  • Comprehensive Testing: Automated E2E tests running in Telegram's test environment

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • PostgreSQL 13+
  • Telegram Bot Token

Installation

  1. Clone the repository

    git clone https://github.com/MishaVyb/bart-bot.git
    cd bart-bot
  2. Set up virtual environment

    make venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    make install
  4. Configure environment

    cp build.env.example build.env
    # Edit build.env with your configuration
  5. Set up database

    make database
  6. Run the bot

    python -m src.polling

Docker Deployment

For production deployment using Docker:

# Build and run with Docker Compose
make build_run

πŸ“– Usage

Basic Interaction

  1. Start the bot: Send /start to begin
  2. Upload photos: Send any photo to build your pet's photo collection
  3. Feed your pet: Use the emoji food buttons (πŸ₯›πŸ₯πŸ₯ŸπŸšπŸ₯“πŸ™πŸ₯–β˜•οΈπŸ£) to feed your virtual pet
  4. Get responses: Your pet will reply with random photos from your collection

Family Sharing

  • Forward messages from other users to share their photo storage
  • Request permission from storage owners to join their family
  • Collaborative feeding with family members

Admin Commands

  • /admin_loaddata - Load data from dump file (admin only)
  • /count - Check total media count in your storage

πŸ› οΈ Development

Project Structure

bart-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ application/          # Bot application logic
β”‚   β”‚   β”œβ”€β”€ handlers.py       # Message handlers
β”‚   β”‚   β”œβ”€β”€ middlewares.py    # Custom middleware
β”‚   β”‚   └── tasks.py          # Background tasks
β”‚   β”œβ”€β”€ database/             # Database models and engine
β”‚   β”œβ”€β”€ content.py            # Bot content and messages
β”‚   └── configurations.py     # Configuration management
β”œβ”€β”€ tests/                    # Test suite
β”œβ”€β”€ alembic/                  # Database migrations
└── data/                     # Data storage

Code Quality

The project uses several tools to maintain code quality:

# Run all code quality checks
make ci

# Format code
black .
isort .

# Type checking
mypy .

# Linting
flake8 .

Testing

# Run tests
pytest

# Run with coverage
pytest --cov=src

Database Management

# Reset database and migrations
make database

# Create new migration
alembic revision --autogenerate

# Apply migrations
alembic upgrade head

πŸ”§ Configuration

Key configuration options in build.env:

# Bot Configuration
BOT_TOKEN=your_telegram_bot_token
ADMIN_ID=your_telegram_user_id

# Database
DATABASE_URL=postgresql://user:password@localhost/bart_bot

# Content
CONTENT_FILEPATH=bart-bot.content.yaml

# Scheduling
SEND_FEED_ME_MESSAGE_CRONS=["0 9 * * *"]  # Daily at 9 AM

🐳 Docker

Production Deployment

# Build image
docker build -t vybornyy/bart-bot .

# Run with Docker Compose
docker-compose up -d

Services

  • polling: Main bot application
  • db: PostgreSQL database

πŸ“Š Monitoring

The bot includes comprehensive logging and monitoring:

  • Structured logging with configurable levels
  • Database query monitoring
  • Error tracking and reporting
  • Performance metrics

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow the existing code style (Black, isort, flake8)
  • Add tests for new features
  • Update documentation as needed
  • Use type hints throughout

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Made with ❀️ for pet lovers everywhere 🐾

About

bart photos bot version 2.0

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages