Anonymous peer-to-peer Telegram chat bot with matchmaking, gamification, subscriptions and a public Spotlight board.
- Overview
- Features
- Tech Stack
- Prerequisites
- Installation
- Configuration
- Database Setup
- Running the Bot
- Deploy as a System Service
- Commands Reference
- Subscription Tiers
- Project Structure
- Contributing
- License
MegaChat connects anonymous users on Telegram for one-on-one text and media chats based on shared interests. Users earn XP by chatting, level up to unlock titles, and can boost their visibility through the public Spotlight board.
The bot supports Italian and English, handles Telegram Stars payments for subscriptions and XP packs, and includes a full reporting and moderation foundation.
| Feature | Description |
|---|---|
| π Smart Matchmaking | Pairs users by language, gender preference, and shared interests (interest-score priority) |
| π¬ Anonymous Chat | Full message relay: text, photos, videos, voice, stickers, GIFs, video notes |
| π£ Flash Mode | Self-destructing photos/videos (spoiler + auto-delete after 15 s) |
| π’ Spotlight Board | Spend XP to post a public message in a channel; anyone can connect directly via deep link |
| π Gamification | Earn XP per message, level up through 5 tiers, unlock exclusive titles |
| π Rating System | Upvote/downvote partners after each chat; upvote recipient gets +50 XP and a notification |
| π¨ Report System | /report during an active chat; reports are stored with reason and counted per user |
| π₯ Leaderboard | Top 5 users by XP, visible to everyone |
| Product | Stars | Benefit |
|---|---|---|
| Premium subscription | 100 β/mo | 20 chats/day |
| Gold subscription | 250 β/mo | Unlimited chats |
| Ultra subscription | 500 β/mo | Unlimited + VIP |
| 500 XP pack | 50 β | Instant XP boost |
| 1 500 XP pack | 120 β | Instant XP boost |
| 5 000 XP pack | 350 β | Instant XP boost |
- Credentials loaded from environment variables (never hardcoded)
html.escape()on all user-supplied text embedded in HTML messages- Atomic matchmaking updates (
AND status='waiting') prevent race conditions - Per-user rate limiting on queue commands
- Input validation and length caps on all free-text fields
- Runtime β Python 3.10+
- Bot framework β python-telegram-bot 21.x (async, with JobQueue)
- Database β MySQL 8.0+ via
mysql-connector-python - Config β
python-dotenv - Deployment β systemd service (Linux)
- Python 3.10 or newer
- MySQL 8.0 or newer
- A Telegram bot token from @BotFather
- A Telegram channel for the Spotlight board (bot must be admin)
# 1. Clone the repository
git clone https://github.com/your-username/megachat.git
cd megachat
# 2. Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txtCopy .env.example to .env and fill in your values:
cp .env.example .env# .env
MEGACHAT_TOKEN=123456789:ABCdef... # Bot token from @BotFather
DB_HOST=localhost
DB_USER=megachat
DB_PASSWORD=your_password
DB_NAME=megachat
DB_POOL_SIZE=10
SPOTLIGHT_CHANNEL=@YourChannel
SPOTLIGHT_CHANNEL_ID=-100123456789 # Numeric ID of the channelNever commit
.envto version control. It is already listed in.gitignore.
mysql -u root -p < database.sqlIf you already have a running database, use the migration script instead:
# Always back up first
mysqldump -u megachat -p megachat > backup_$(date +%Y%m%d).sql
# Run the migration (idempotent β safe to re-run)
mysql -u megachat -p megachat < migrate.sqlThe migration script:
- Adds the new
report_countcolumn - Creates performance indexes (
status,tier,xp) - Creates the
reportstable - Fixes the old Italian default title (
Novellino β Beginner) - Cleans up inconsistent chat states
- Prints a verification report at the end
# Activate your virtual environment first
source venv/bin/activate
python main.pyYou should see:
MegaChat v2.1 is running...
The included setup_service.sh automates the full server setup:
sudo bash setup_service.shIt will:
- Create the virtual environment if missing
- Install all dependencies from
requirements.txt - Warn if
.envis absent - Write a systemd unit file (with
EnvironmentFilepointing to.env) - Enable and start the service
Useful commands after deployment:
# Live logs
sudo journalctl -u megachat -f
# Restart after a code change
sudo systemctl restart megachat
# Check current status
sudo systemctl status megachat| Command | Description |
|---|---|
/start |
Register or return to dashboard |
/search |
Enter the matchmaking queue |
/stop |
Leave queue or end current chat |
/next |
End current chat and immediately search for a new one |
/profile |
View your stats (level, XP, likes, tier, β¦) |
/report [reason] |
Report current chat partner |
/leaderboard |
Top 5 users by XP |
/shop |
Browse subscriptions and XP packs |
/settings |
Edit bio, switch language, delete account |
/menu |
Return to the main dashboard |
/help |
Usage guide |
/info |
About and privacy notice |
/cancel |
Cancel active registration or spotlight flow |
| Tier | Daily chats | Price |
|---|---|---|
| Free | 5 | β |
| Premium | 20 | 100 β / 30 days |
| Gold | Unlimited | 250 β / 30 days |
| Ultra | Unlimited + VIP | 500 β / 30 days |
Subscriptions are checked and downgraded automatically every 24 hours by a background job.
megachat/
βββ main.py # Bot handlers, matchmaking, relay, payments
βββ db.py # Database abstraction (queries, XP, leaderboard, reports)
βββ config.py # Settings loaded from environment variables
βββ texts.py # Bilingual (IT/EN) translation strings
βββ database.sql # Fresh-install schema
βββ migrate.sql # v2.0 β v2.1 migration (idempotent)
βββ broadcast.py # One-off mass-message utility (migration helper)
βββ setup_service.sh # Automated Linux service installer
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variable template
βββ .gitignore
Contributions are welcome! Please read CONTRIBUTING.md before opening a pull request.
This project is licensed under the MIT License β see LICENSE for details.