A Telegram bot for playing checkers with inline game invitations, real-time gameplay, and statistics tracking.
- ๐ฎ Inline game invitations
- โ๏ธ Full checkers gameplay with standard rules
- ๐ Piece promotion to kings
- ๐ Player statistics tracking
- ๐ฏ Interactive board using Telegram inline keyboards
- Python 3.13+
- aiogram 3.x - Telegram bot framework
- PostgreSQL - Database
- SQLAlchemy 2.x - ORM
- Docker & docker-compose
- Docker and docker-compose installed
- Task - Task runner (recommended)
- Telegram Bot Token (get from @BotFather)
Create your configuration file:
cp config/example.yaml config/local.yamlEdit config/local.yaml:
token: "YOUR_BOT_TOKEN_HERE"
updates_strategy: "polling" # or "webhook"
database_dns: "postgresql+asyncpg://admin:admin@postgres:5432/checkers"
host_url: null # Set this if using webhook modeBuild and start the services:
task botThe bot will automatically:
- Start the PostgreSQL database
- Run database migrations
- Start the bot in polling mode
task upgrade_db- In any chat, type
@your_bot_username - Select "Start Checkers Game"
- Send to the chat
- Wait for someone to accept the invitation
- Tap a piece to select it
- Green circles show valid moves
- Tap a destination to move
- Captures are mandatory!
- Reach the opposite end to promote to King
/start- Welcome message and instructions/stats- View your game statistics/help- Show game rules and help
- Standard 8x8 checkers board
- Pieces move diagonally on dark squares
- Regular pieces move forward only
- Kings can move in all diagonal directions
- Captures are mandatory when available
- Multiple captures in one turn (chain captures)
- Win by capturing all opponent pieces or blocking all moves
The project uses Task for common operations:
# Run the bot
task bot
# Code quality checks
task isort # Sort imports
task flake8 # Lint code
task mypy # Type checking
task pre_commit # Run all checks
# Database operations
task check_db # Check schema status
task upgrade_db # Apply migrations
task make_migrations -- "description" # Create new migration
task downgrade_db # Revert migration
# Utilities
task bot_exec # Open bash in container
task build # Build Docker image
task down # Clean up containers
task project_setup # Set up pre-commit hookscheckers/
โโโ bot/
โ โโโ bl/ # Business logic
โ โโโ controllers/ # Route handlers
โ โโโ db/ # Database models & session
โ โ โโโ models/ # SQLAlchemy models
โ โโโ middlewares/ # Bot middlewares
โ โโโ utils/ # Utility functions
โ โโโ main.py # Entry point
โโโ config/ # Configuration files
โโโ migrations/ # Alembic migrations
โโโ requirements/ # Python dependencies
โโโ Dockerfile
โโโ docker-compose.yaml
โโโ Taskfile.yaml # Task definitions
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements/prod.txt
pip install -r requirements/tools.txt-
Set up PostgreSQL and update
config/local.yaml -
Run migrations:
alembic upgrade head- Start the bot:
python -m bot.mainAll code must adhere to PEP8 and pass quality checks:
# Run all checks at once
task pre_commit
# Or run individually
task isort # Sort imports (line length: 80)
task flake8 # Lint code (PEP8 compliance)
task mypy # Type checking (strict mode)Configuration files:
.isort.cfg- Import sorting settings.flake8- Linting rulesmypy.ini- Type checking configuration
After modifying database models:
task make_migrations -- "Description of changes"
task upgrade_dbSet up git hooks to run quality checks before commits:
task project_setupThis creates a pre-commit hook that automatically runs task pre_commit before each commit.
CONFIG- Path to configuration file (default:./config/local.yaml)
- User information and statistics
- Total games, wins, losses
- Active and completed games
- Board state stored as JSON
- Current turn tracking
- Game status (pending, active, finished, cancelled)
- Move history for each game
- Captured pieces tracking
- Promotion tracking
- Check that the bot token is correct
- Verify the bot is running:
docker compose ps - Check logs:
docker compose logs -f bot
- Ensure PostgreSQL is running:
docker compose ps postgres - Check database DNS in config file
- Verify migrations are applied:
task check_db
- Enable inline mode in @BotFather settings
- Send
/setinlineto @BotFather - Set inline placeholder text
MIT
Built with aiogram 3.x and PostgreSQL.